feat: add Claude Code AI proxy credential fallback#862
Merged
simple-agent-manager[bot] merged 8 commits intomainfrom May 1, 2026
Merged
feat: add Claude Code AI proxy credential fallback#862simple-agent-manager[bot] merged 8 commits intomainfrom
simple-agent-manager[bot] merged 8 commits intomainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Extend the AI proxy credential fallback to support Claude Code alongside OpenCode. When no user Anthropic API key exists and the AI proxy is enabled, the control plane returns inferenceConfig with provider "anthropic-proxy" pointing to the native Anthropic Messages API proxy endpoint. The VM agent injects ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN env vars for Claude Code proxy sessions, using the workspace callback token for auth. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The task credential source tracking test had incorrect query count expectations. With projectId=null, getDecryptedAgentKey makes 2 queries (user-scoped + platform), not 4. Fixed the mock to match. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…sort - Add AI_PROXY_DEFAULT_ANTHROPIC_MODEL to Env interface for type safety - Fix export sort order in shared constants/index.ts - Remove unnecessary Record<string, string> cast in runtime.ts Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
0a35fa9 to
e49cd0b
Compare
claude-code now has its own AI proxy fallback, so it can't be used to test "non-opencode agents get 404". Use google-gemini instead. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
26 tasks
simple-agent-manager Bot
added a commit
that referenced
this pull request
May 1, 2026
* task: move codex credential injection fallback to active Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: add Codex AI proxy credential fallback When no user-provided OpenAI API key exists for openai-codex agent type, inject SAM's AI proxy as the credential source. Mirrors the Claude Code fallback (WP2, PR #862) for the OpenAI agent type. - Add DEFAULT_AI_PROXY_OPENAI_MODEL constant (gpt-4.1) - Extend runtime.ts proxy fallback to include openai-codex - Add openai-proxy provider branch in session_host.go - Inject OPENAI_BASE_URL and OPENAI_API_KEY env vars for Codex Co-Authored-By: Claude Opus 4.6 <[email protected]> * test: add Codex AI proxy credential fallback tests Mirrors the Claude Code proxy fallback test suite for openai-codex: - Returns openai-proxy inferenceConfig when no credential exists - User credential takes priority over proxy fallback - 404 when AI proxy is disabled - Custom model via AI_PROXY_DEFAULT_OPENAI_MODEL env var - Task credential source tracking - No regression on opencode or claude-code fallback Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: sort exports in shared constants index Co-Authored-By: Claude Opus 4.6 <[email protected]> * docs: add AI_PROXY_DEFAULT_OPENAI_MODEL to .env.example Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor: move proxy-eligible agents Set to module scope Address review findings: move PROXY_ELIGIBLE_AGENTS to module scope for isolate reuse, add comment documenting KV model-picker gap for Codex (intentional, matches Claude Code pattern). Co-Authored-By: Claude Opus 4.6 <[email protected]> * task: add backlog task for AI proxy credential hardening Captures defense-in-depth findings from WP3 security audit: - Short-lived proxy-scoped tokens - __platform_proxy__ sentinel cleanup - BaseURL origin validation - Go-side proxy injection tests Co-Authored-By: Claude Opus 4.6 <[email protected]> * task: archive codex credential injection fallback task Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Raphaël Titsworth-Morin <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Summary
claude-codeagent, fall back to SAM's platform AI proxy so Claude Code runs with zero-key onboarding.claude-codewith provideranthropic-proxy, baseURL pointing to the native Anthropic proxy endpoint (/ai/anthropic), andapiKeySource: callback-token.ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN, andANTHROPIC_MODELenv vars when the proxy fallback is active for Claude Code.AI_PROXY_DEFAULT_ANTHROPIC_MODELenv var (default:claude-sonnet-4-6) controls the default model for Claude Code proxy sessions.Validation
pnpm lintpnpm typecheckpnpm test(4212 API tests pass, all Go tests pass)pnpm buildStaging Verification (REQUIRED for all code changes — merge-blocking)
sam/wp2-claude-code-credential-01kqgbapp.sammy.partyusing smoke test token, verified app loadsStaging Verification Evidence
https://api.sammy.party/healthreturns{"status":"healthy"}https://app.sammy.party/dashboard— authenticated as serverspresentation2025/ai/v1/chat/completions) responds correctly (401 for invalid token)/ai/anthropic/v1/messages) returns 404 — this is a pre-existing deployment issue from PR feat: add native Anthropic Messages API proxy endpoint #859, not related to this PRUI Compliance Checklist (Required for UI changes)
N/A: no UI changes
End-to-End Verification (Required for multi-component changes)
Data Flow Trace
VM agent requests credential →
POST /api/workspaces/:id/agent-keywith{ agentType: "claude-code" }→
apps/api/src/routes/workspaces/runtime.ts:POST /:id/agent-keyCredential resolution:
getDecryptedAgentKey(db, userId, 'claude-code', key, projectId)→
apps/api/src/routes/credentials.ts:getDecryptedAgentKey()— checks user-scoped, then platformNo credential found + AI proxy enabled → returns
inferenceConfig: { provider: 'anthropic-proxy', baseURL: 'https://api.{BASE_DOMAIN}/ai/anthropic', model, apiKeySource: 'callback-token' }→
runtime.tslines ~75-115VM agent receives response →
packages/vm-agent/internal/acp/gateway.go:fetchAgentCredential()Session host injects env vars →
packages/vm-agent/internal/acp/session_host.go:startAgent()→ Sets
ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN,ANTHROPIC_MODELin agent env fileClaude Code uses proxy → SDK reads
ANTHROPIC_BASE_URLand appends/v1/messages→ hitshttps://api.{BASE_DOMAIN}/ai/anthropic/v1/messagesUntested Gaps
startAgent()function requires a live container (ContainerResolver), making unit testing impractical. This is a pre-existing gap — the OpenCode proxy path has the same gap. The env var injection logic is tested via theTestIsSecretEnvVartest for the sensitive var filtering.Post-Mortem (Required for bug fix PRs)
N/A: not a bug fix — new feature (credential fallback for Claude Code)
Specialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to human — N/A, all completed/v1/messages)Exceptions (If any)
Agent Preflight (Required)
Classification
External References
N/A: No external API changes. Claude Code SDK env var behavior (
ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN,ANTHROPIC_MODEL) verified from existing OpenCode proxy pattern in the codebase.Codebase Impact Analysis
apps/api/src/routes/workspaces/runtime.ts— Extended AI proxy fallback to handleclaude-codeagent typeapps/api/src/env.ts— AddedAI_PROXY_DEFAULT_ANTHROPIC_MODELto Env typepackages/shared/src/constants/ai-services.ts— AddedDEFAULT_AI_PROXY_ANTHROPIC_MODELconstantpackages/vm-agent/internal/acp/session_host.go— Added Claude Code proxy env var injectionpackages/vm-agent/internal/acp/process.go— AddedANTHROPIC_AUTH_TOKENto secret env namesDocumentation & Specs
apps/api/.env.example— AddedAI_PROXY_DEFAULT_ANTHROPIC_MODELdocumentationConstitution & Risk Check
AI_PROXY_DEFAULT_ANTHROPIC_MODELenv var withDEFAULT_AI_PROXY_ANTHROPIC_MODELconstant fallback. BaseURL derived fromBASE_DOMAIN.ANTHROPIC_AUTH_TOKENadded tosecretEnvNamesto preventpsexposure. Callback token used as auth (same pattern as OpenCode).