feat: Claude Code CLI fallback for Max/Pro plan users#6
Open
PlutoYork wants to merge 2 commits intodbreunig:mainfrom
Open
feat: Claude Code CLI fallback for Max/Pro plan users#6PlutoYork wants to merge 2 commits intodbreunig:mainfrom
PlutoYork wants to merge 2 commits intodbreunig:mainfrom
Conversation
Users on Claude Max or Pro plans authenticate via OAuth through Claude Code and don't have a separate ANTHROPIC_API_KEY. This adds a ClaudeCodeLM backend that routes DSPy inference through the `claude -p` CLI, enabling Plumb to work without an API key. Resolution order: 1. ANTHROPIC_API_KEY set → direct Anthropic API via LiteLLM (unchanged) 2. `claude` CLI on PATH → ClaudeCodeLM fallback (new) 3. Neither → PlumbAuthError with clear instructions The fallback is transparent — no configuration needed. If Claude Code is installed and authenticated, Plumb detects it automatically. Co-Authored-By: Bruce Boston <bruce@altpath.ai>
- Fix 2 failing tests that expected old ANTHROPIC_API_KEY-specific error messages (now generic "No LLM backend available") - Mock _claude_code_available() in auth tests to isolate the "neither backend available" path - Add new test: CLI fallback works when no API key but claude on PATH - Add TestClaudeCodeLM (8 tests): instantiation, JSON event parsing, plain text fallback, timeout, missing CLI, nonzero exit, message building, callable delegation - Add TestClaudeCodeAvailable (2 tests): PATH detection - Add TestGetLm (4 tests): API key precedence, CLI fallback, nothing available, API key wins when both present 56 passed, 0 failed. Co-Authored-By: Bruce Boston <bruce@altpath.ai>
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.
Problem
Plumb requires
ANTHROPIC_API_KEYfor all LLM-powered features (spec parsing, decision extraction, test generation). Users on Claude Max or Pro plans authenticate via OAuth through Claude Code and don't have a separate API key. This means they can't use any of Plumb's LLM features out of the box.As Claude Code adoption grows (especially Max plan users who are the most active AI-assisted developers), this is an increasing friction point for Plumb adoption.
Solution
Add a
ClaudeCodeLMbackend that routes DSPy inference through theclaude -pCLI, using the existing OAuth session for authentication.Resolution order (backward compatible):
ANTHROPIC_API_KEYset → direct Anthropic API via LiteLLM (unchanged, still the fast path)claudeCLI on PATH →ClaudeCodeLMfallback (new — zero config needed)PlumbAuthErrorwith clear instructions for both optionsThe fallback is transparent — no configuration flags, no
.envchanges. If Claude Code is installed and the user has an active session, Plumb detects it automatically viashutil.which("claude").Implementation
ClaudeCodeLM(dspy.LM)— custom LM class that callsclaude -p --model sonnet --output-format json --no-session-persistenceas a subprocess"result"eventget_lm()now auto-detects the best available backendvalidate_api_access()checks both paths and smoke-tests whichever is availableTrade-offs
claudeis on PATH. No new pip dependencies added.sonnet(the alias), which resolves to the latest Sonnet via Claude Code's model routing.Testing
Tested with Claude Code v2.1.76 on macOS with a Max plan subscription:
plumb parse-spec— successfully parsed 55 requirements from a spec fileplumb init→validate_api_access()→ smoke test passesANTHROPIC_API_KEYis unsetANTHROPIC_API_KEYis set (no behavior change)Scope
Single file changed:
plumb/programs/__init__.py(+138, -18 lines)