Skip to content

fix(provider): load Claude SDK only when needed - #8104

Open
onmax wants to merge 2 commits into
pingdotgg:mainfrom
vite-hub:fix/lazy-claude-sdk-import-upstream
Open

fix(provider): load Claude SDK only when needed#8104
onmax wants to merge 2 commits into
pingdotgg:mainfrom
vite-hub:fix/lazy-claude-sdk-import-upstream

Conversation

@onmax

@onmax onmax commented Aug 24, 2026

Copy link
Copy Markdown

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-sdk during 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

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

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-sdk when Claude adapter/provider modules load. Type imports stay static; query is dynamic-imported only when starting a session or probing capabilities.

Session start now uses Effect.tryPromise with abort handling so an interrupted lazy import does not call query. Injected createQuery is 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-sdk until session start in ClaudeAdapter

  • Changes ClaudeAdapter and ClaudeProvider to import only types from the Claude SDK at module load, and dynamically import() the query value inside Effect.tryPromise when a session starts or capabilities are probed.
  • Starting a Claude session now checks the abort signal before and after the dynamic import, and closes the runtime exactly once if interrupted during loading.
  • Adds tests asserting the adapter module imports without touching the SDK, and that interrupting startSession mid-import prevents query from being called.
  • Risk: createQuery is no longer passed the statically imported query as 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.

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 56e718d0-128d-4665-b59f-6761405d3cb3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Aug 24, 2026
Comment thread apps/server/src/provider/Layers/ClaudeAdapter.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 20ebbc4

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant