fix(provider): load Claude SDK only when needed - #8104
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — The change is narrowly scoped to deferring Claude SDK loading until Claude functionality is actually used, with focused tests for import isolation and cancellation. It does not alter APIs, schemas, workflows, or deployment behavior. You can add or adjust custom eligibility rules. Learn more. |
What Changed
Changed the Claude adapter and capability probe to import SDK runtime values only when they start Claude work. Type imports remain static, and the existing injected query path is unchanged.
Added a regression test that makes the Claude SDK throw if importing the adapter evaluates it. Focused adapter and capability-probe tests pass with 78 tests, the server typecheck passes, and the production server bundle contains only deferred Claude SDK imports.
Why
T3 currently evaluates
@anthropic-ai/claude-agent-sdkduring server startup even when the active provider is Codex, Cursor, Grok, or OpenCode. Provider-specific runtime code should load at the point where T3 starts a Claude query or SDK capability probe. This keeps unrelated provider startup isolated while preserving the existing Claude behavior.Checklist
Created with the Codex harness using gpt-5.6-sol.
Note
Medium Risk
Touches Claude session startup and capability probing, including abort-during-import cleanup. Behavior is otherwise unchanged, but SDK failures now appear later than module load.
Overview
Stops evaluating
@anthropic-ai/claude-agent-sdkwhen Claude adapter/provider modules load. Type imports stay static;queryis dynamic-imported only when starting a session or probing capabilities.Session start now uses
Effect.tryPromisewith abort handling so an interrupted lazy import does not callquery. InjectedcreateQueryis unchanged.Adds a module-load regression test and an interrupt test covering the abort path. SDK load failures now surface at first Claude use instead of import time.
Reviewed by Cursor Bugbot for commit 20ebbc4. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Defer loading
@anthropic-ai/claude-agent-sdkuntil session start inClaudeAdapterClaudeAdapterandClaudeProviderto import only types from the Claude SDK at module load, and dynamicallyimport()thequeryvalue insideEffect.tryPromisewhen a session starts or capabilities are probed.startSessionmid-import preventsqueryfrom being called.createQueryis no longer passed the statically importedqueryas a default; callers that relied on the old default in ClaudeAdapter.ts must supply it via options or rely on the new dynamic import path.Macroscope summarized 20ebbc4.