fix: add BYOK/third-party API proxy support for SDK Agent #329
+151
−55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
SDK Agent fails with
"Your account does not have access to Claude Code. Please run /login."error for users using BYOK (Bring Your Own Key) with third-party API proxies (e.g.,ANTHROPIC_BASE_URL).Root Cause: The SDK Agent spawns a Claude subprocess that doesn't inherit the custom API settings from
~/.claude/settings.json, causing it to try default Anthropic authentication which fails.Additionally, when loading user settings with
settingSources: ["user"], the SDK subprocess also loads the claude-mem hooks configuration, causing SDK internal prompts to be incorrectly saved to theuser_promptstable.Solution
1. BYOK Support (Source-level fix)
loadClaudeCodeApiSettings()method toworker-service.tsthat reads BYOK config from~/.claude/settings.jsonand setsANTHROPIC_BASE_URLandANTHROPIC_AUTH_TOKENas environment variables at worker startupsettingSources: [](empty) in SDK Agent to prevent loading any user settings including hooks2. Defensive SDK Prompt Filter (Fallback)
SessionRoutes.tsto detect SDK internal sessionsprojectname equals home directory name (SDK runs withworkingDirectory: homedir())Changes
src/services/worker-service.ts: AddloadClaudeCodeApiSettings()method to load BYOK configsrc/services/worker/SDKAgent.ts: UsesettingSources: []to prevent loading hookssrc/hooks/new-hook.ts: Add SDK prompt filter at hook levelsrc/services/worker/http/routes/SessionRoutes.ts: Add SDK prompt filter at API level with home directory detectionWhy This Approach
Using
settingSources: []is cleaner than filtering because:Testing
settingSources: []skipped: false)