fix(sdk-bridge/claude): route through cube identity via CLAUDE_CONFIG_DIR#209
Conversation
…_DIR Phase 3 dogfood operator question: "the claude sdk is using the agent cube creds yea not my one here?" — answer was NO. claude-sdk runs were billing the operator's interactive terminal session, not cube's. The legacy claude.py adapter sets CLAUDE_CONFIG_DIR to point at ~/.cube/claude-config/ so the spawned `claude` binary picks up cube's OAuth tokens. SDKBridgeAdapter just inherited parent env without that resolution, so the bundled claude binary (claude-agent-sdk wraps the same binary under the hood) loaded the operator's `~/.claude/` instead. This PR ports the resolver: 1. _resolve_cube_claude_config_dir() — same logic as claude.py: - $CUBE_CLAUDE_CONFIG_DIR override if set + dir exists - ~/.cube/claude-config/ default if it exists - else None (use whatever auth is in parent env) 2. SDKBridgeAdapter.run() sets env['CLAUDE_CONFIG_DIR'] when provider is 'claude' AND a cube identity is resolved. Codex and Cursor are untouched — they have their own auth (OPENAI_*, CURSOR_API_KEY). Tests: 3 new tests covering claude sets the var, $CUBE_CLAUDE_CONFIG_DIR override is honoured, codex/cursor do NOT touch CLAUDE_CONFIG_DIR. 16/16 sdk-bridge tests pass; 245/245 in tests/ pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe PR adds environment variable routing to set ChangesClaude Config Directory Environment Routing
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly Related PRs
Poem
Comment |
Summary
Closes the auth-routing gap surfaced in Phase 3 dogfood: claude-sdk runs were billing the operator's terminal Claude Code session, not cube's separate identity. Now resolves `CLAUDE_CONFIG_DIR` from the same convention (`~/.cube/claude-config/` or `$CUBE_CLAUDE_CONFIG_DIR` override) the legacy `claude.py` adapter uses.
Why
The bundled `claude` binary that `claude-agent-sdk` spawns reads `CLAUDE_CONFIG_DIR` for auth. Without it, the binary loads the operator's `~/.claude/` and bills their account.
Test plan
🤖 Generated with Claude Code
Summary
This PR fixes an authentication routing gap where Claude SDK runs were incorrectly billing the operator's terminal session instead of the cube's identity.
Key Changes:
_resolve_cube_claude_config_dir()function that checks$CUBE_CLAUDE_CONFIG_DIR(if set and exists) or falls back to~/.cube/claude-config/, mirroring the legacy claude.py adapter's conventionSDKBridgeAdapter.run()to explicitly setCLAUDE_CONFIG_DIRin the subprocess environment for theclaudeprovider only when a cube identity directory is resolvedTests: Added three test cases verifying that the claude provider injects the correct
CLAUDE_CONFIG_DIR, the$CUBE_CLAUDE_CONFIG_DIRoverride is honoured, and codex/cursor providers do not touch the variable. Full test suite passes (245/245).