Repository navigation
feat(cli): add lite configure claude and lite unconfigure claude - #40319
Conversation
86a658d to
bde3c50
Compare
Greptile SummaryThis PR adds persistent Claude Code proxy configuration and receipt-based undo to the
Confidence Score: 4/5The PR is not yet safe to merge because the outstanding settings/receipt consistency defect can leave undo state inconsistent after a settings commit failure. The receipt is committed before the staged settings file, and failure of the second Files Needing Attention: litellm/proxy/client/cli/commands/claude_settings.py
|
| Filename | Overview |
|---|---|
| litellm/proxy/client/cli/commands/claude_settings.py | Centralizes credential-aware settings merging and receipt-based restoration, but the previously reported partial-commit failure remains possible. |
| litellm/proxy/client/cli/commands/configure.py | Implements interactive and explicit Claude configuration commands, credential resolution, model validation, and user-facing output. |
| litellm/proxy/client/cli/commands/auth.py | Routes login --config-claude through the shared, undoable configuration path. |
| litellm/proxy/client/cli/commands/autoroute/commands.py | Reuses the shared Claude settings merge while pinning the autorouter model and tiers. |
| litellm/proxy/client/cli/README.md | Documents configuration, undo behavior, credential handling, model discovery, and autoroute settings. |
| tests/test_litellm/proxy/client/cli/test_claude_settings.py | Adds restoration-shape and staging-failure coverage, though it does not exercise failure of the second commit. |
Reviews (2): Last reviewed commit: "feat(cli): add lite configure claude and..." | Re-trigger Greptile
| merged: Final = merge_claude_settings_static_token( | ||
| original_settings, base_url, master_key, AUTOROUTER_MODEL_NAME | ||
| ) |
There was a problem hiding this comment.
Autoroute Documentation Is Incomplete
The shared merge now writes the top-level model, gateway discovery, and Fable override, but the autoroute documentation omits these settings changes.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed in be34b15: the autoroute README paragraph now lists the discovery default and the Fable tier key it shares with the merge.
PR overviewThis pull request adds Two issues have been addressed, with one credential-handling concern still open. Existing Claude credentials can be copied into a persistent state file, allowing another local process or backup system with access to the user's LiteLLM configuration directory to recover them even after removal from Claude settings. Exploitation depends on pre-existing local or backup access, so the remaining risk is minor but should be resolved by avoiding plaintext credential snapshots. Open issues (1)
Fixed/addressed: 2 · PR risk: 4/10 |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
CI is green except osv-scan, which also fails on staging's own last three runs; this branch does not touch the lockfile. @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 5/5. The implementation is well-scoped and the changed behavior is covered by meaningful tests: key/model validation, settings preservation, receipt-based repeat configure/unconfigure, user edits surviving unconfigure, symlink-safe writes, permissions, and conflicts with temporary The only failing check is |
bde3c50 to
be34b15
Compare
|
Round 2 pushed as be34b15: every thread above is fixed and answered, CI green except the inherited osv-scan. @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 5/5. Round 2 addresses all previously identified issues: receipt/settings staging preserves the earlier undo state on failed reconfiguration; receipts now preserve null/missing CI is green for the changed code. The remaining |
be34b15 to
66696b3
Compare
|
Round 3 pushed as 66696b3: the pinned-model finding is fixed and answered. CI green except the inherited osv-scan; the proxy-infra migration timing test flaked once and passed on rerun. @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 5/5. Round 3 fixes the remaining pinned-model issue: repeating The changed-code CI is green. The remaining |
66696b3 to
4a6f825
Compare
|
Round 4 pushed as 4a6f825: lite autoroute up now pins autorouter as the starting model too, answered on the thread. osv-scan is the inherited red. @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 5/5. Round 4 addresses the remaining autoroute behavior: The prior findings remain addressed: transactional settings/receipt handling, exact restoration of missing/null shapes, selective undo that preserves user edits, credential cleanup, symlink-safe writes, ownership conflict checks, mocked model-list validation, and coverage for repeat configuration and permissions. The changed-code CI is green. |
|
@greptile review |
4a6f825 to
99be9a0
Compare
a13cb42 to
9eab2a5
Compare
|
Round 8 pushed as 9eab2a5: the withheld report now names only credentials unconfigure actually left removed, answered on the thread. CI green except the inherited osv-scan. @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 5/5. Round 8 closes the final review gap: The broader implementation also has coverage for receipt/settings write failures, exact file and |
9eab2a5 to
438d360
Compare
|
@greptileai can you reply here with score & why |
|
bugbot run |
|
Confidence score: 4/5. The implementation is substantial and well-covered: it centralizes Claude settings merging, validates credentials and models through I’m not giving 5/5 because this changes several credential and filesystem-state paths with intentionally non-atomic settings/receipt commits and meaningful edge-case complexity, so continued integration coverage is warranted. I found no remaining blocking correctness issue in the latest revision. |
438d360 to
4bf19b5
Compare
|
Round 9 pushed as 4bf19b53ce. Beyond the one Bugbot finding (repeat configure reclaiming user edits), an adversarial pass on the receipt and the command layer found eight more confirmed issues, fixed as four mechanisms rather than patches:
673 CLI tests pass, four delta gates and the recursion detector pass, codecov/patch 93.42%. @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 5/5. Round 9 resolves the remaining correctness gaps I identified. Receipt ownership is now per-key and write-driven, repeat configure/re-login snapshots and fingerprints user changes correctly, credential restoration is bound to the captured The command layer checks ownership before authentication or model-listing requests, uses typed listing failures for actionable hints, and keeps model pinning scoped to Claude Code’s starting model. The focused regression coverage exercises repeat configuration, credential and endpoint changes, deletion, symlink handling, failure cleanup, and command preconditions. The reported 673 CLI tests, CI status, and coverage are passing, and I found no remaining blocking correctness issues in |
Persistently route Claude Code through a LiteLLM proxy with a long-lived virtual key or the stored lite login, turn on gateway model discovery so /model lists the proxy's models, optionally pick the model Claude Code starts on, and record what changed so unconfigure restores only the keys the user has not touched since. lite login --config-claude writes through the same receipt and is undoable too. The two settings merges (lite up / --config-claude and lite autoroute) collapse into one credential-aware merge
4bf19b5 to
f1d655f
Compare
| file_existed=file_exists if earlier is None else earlier.file_existed, | ||
| env_present=ENV_KEY in current if earlier is None else earlier.env_present, | ||
| env_was_object=isinstance(current.get(ENV_KEY), dict) if earlier is None else earlier.env_was_object, | ||
| previous=MappingProxyType({path: claim.previous for path, claim in claims.items()}), |
There was a problem hiding this comment.
Low: Prior credentials persist in the receipt
claim.previous includes the full values of env.ANTHROPIC_API_KEY and env.ANTHROPIC_AUTH_TOKEN, so configuring copies any existing credential into ~/.litellm/claude_configure_state.json. A local process or backup policy with access to that directory can recover the key even after it has been removed from settings.json, and the copy can remain indefinitely when unconfigure retains a receipt for withheld credentials. Store credential snapshots in the OS credential vault behind an opaque receipt reference, rather than serializing them into this JSON file.
There was a problem hiding this comment.
Answered without a code change here, and filed as LIT-7437 to be done once for every snapshot the CLI keeps, because this receipt is already the narrowest copy in that chain:
- The receipt is staged with
tempfile.mkstemp(0600) inside~/.litellm, whichensure_private_dirkeeps at 0700. The value it snapshots comes from~/.claude/settings.json, which Claude Code writes at 0644, so the copy is less readable than the original the user already keeps. - It holds a previous credential only for the window in which that credential is out of settings.json and unconfigure needs it to put it back. A normal unconfigure removes the receipt; the withheld case names the file and how to drop it.
- What this configure writes is never in the receipt:
writtenholds sha256 fingerprints, not values. The two older snapshots in the same directory,lite up'sclaude_settings_backup.jsonandlite autoroute up's copy, hold the whole settings file including any credential, and Ramp Router'sramp-router-state.jsonstores both the priorANTHROPIC_API_KEYand the writtenANTHROPIC_AUTH_TOKENas plaintext under~/.claude. - The CLI's keychain helper (
cli_keyring.SecretVault) is a single-slot vault for the login token. Snapshots keyed by settings path and credential slot need a keyed variant, the same fallbackscli_token_utilshas for an unreachable keychain, and an erase onlite down/autoroute down/unconfigureplus an answer for a receipt deleted by hand (a keychain entry would outlive it, which the current message says drops the credential). That is one change across all three files, so it lives in LIT-7437 rather than in this receipt alone.
There was a problem hiding this comment.
Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.
|
Round 10 pushed as f1d655f. Beyond answering Bugbot's two findings on 4bf19b53ce in-thread (an @greptileai can you reply here with a score and why that score? |
|
bugbot run |
|
Confidence score: 5/5. Round 10 preserves the previously validated behavior while simplifying the implementation: the dotted-path receipt removes duplicated undo logic, The current commit has no merge-blocking findings. CI for the changed code is green; |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit f1d655f. Configure here.
…yhelper_conflict Resolves the conflicts with the lite configure claude work from #40319: every persistent writer and reader of Claude Code's settings file now resolves it through CLAUDE_CONFIG_DIR, the lite up backup check only guards the default file, and each settings file keeps its own undo receipt (the default file keeps ~/.litellm/claude_configure_state.json, any other file gets ~/.litellm/claude_configure_state/<sha256 of its resolved path>.json).
TLDR
Problem this solves:
~/.claude/settings.jsonlite login --config-claudeonly works with an SSO login, and nothing undoes itHow it solves it:
lite configure claude --api-key KEYpatches settings.json in place, turns on gateway model discovery, and records what it changed--api-keyit uses yourlite loginthrough apiKeyHelper, the same pathlite login --config-claudetakeslite unconfigure clauderestores exactly those keys, leaving anything the user changed since; it undoes--config-claudetooenv.ANTHROPIC_BASE_URL,apiKeyHelper,model, ...): the value each path held before configure took it over, a fingerprint for each path a merge changed, and for a credential theANTHROPIC_BASE_URLit was captured beside. Ownership moves only by a write: a repeat configure or re-login refreshes a fingerprint only for a path its merge changed and snapshots afresh a path the user changed in between, so whatever a repeat displaces is what comes back and an edit made between two configures is never adopted as oursANTHROPIC_BASE_URLit was captured with; otherwise it stays removed, the output names that server, and the receipt is kept owning only those slots, so pointing the URL back and running unconfigure again finishes the jobOSErrorinto aClaudeSettingsErrornaming the path, and discard the sibling staged file, so no temp file holding a token is left behind andlite login --config-claudenever relabels it "Authentication failed"lite up/lite autoroute upownership check, then the credential, thenGET /v1/models, all before any login prompt; unconfigure reports only keys whose value it changed, says when the file itself is gone, and the /v1/models hint matches how the listing failed--model(or the interactivelite configure) only picks the model Claude Code starts on;/modelkeeps listing the gateway's modelslite up,--config-claude,lite autoroute upandconfigurelitellm/User Flow
Before: a developer with a LiteLLM virtual key cannot make a bare
claudeuse the proxy without editing JSON by handlite claude configure --api-key sk-..., which forwardsconfigureto theclaudebinary and fails witherror: unknown option '--api-key'lite claude -p "hi"instead, which routes that one invocation, but~/.claude/settings.jsonis untouched, so the next plainclaudesaysNot logged in · Please run /loginclaude-opus-5, and a proxy without that model group answers400 Invalid model name passed in model=claude-opus-5; nothing tells them which models the proxy does serveAfter: one command wires Claude Code to the proxy, and one command puts it back
lite --base-url https://proxy.example.com configure claude --api-key sk-...(or plainlite configure, which asks which agents to wire and which model to start on); the command checks the key againstGET /v1/modelsand prints what it wrote and how to undo itclaudefrom any terminal;/modellists the proxy's Claude-named models next to the built-in rows, and every turn lands onPOST /v1/messageswith whichever model they pickedlite unconfigure claude; settings.json is back to what it held before, and the next plainclaudeis on their previous setup againRelevant issues
lite configure [claude]andlite unconfigure claude(persistent wiring with a virtual key or the stored login, receipt-based undo, interactive picker)lite up/--config-claudeandlite autoroute) with one credential-awaremerge_claude_settings;lite login --config-claudenow writes through the receipt so it is undoableLinear ticket
Resolves LIT-7355
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Shared setup: a proxy from this worktree on
http://127.0.0.1:4735(no database), master keysk-rig-lit7355, servingclaude-haiku-4-5,claude-sonnet-4-6,claude-opus-4-7,gpt-5.6-luna(all upstream to a real gateway, real spend) andclaude-auto, a complexity auto-router over the three Claude groups. Everyclauderun below uses a freshHOMEseeded with{"theme": "dark", "model": "claude-opus-5"}in.claude/settings.json, Claude Code v2.1.265, and the worktree'sliteBefore (4b9c289)
configure does not exist
lite --base-url http://127.0.0.1:4735 --api-key sk-rig-lit7355 claude configure --api-key sk-rig-lit7355the launcher routes one run and leaves settings.json alone
lite --base-url http://127.0.0.1:4735 --api-key sk-rig-lit7355 claude -p "Reply with exactly: routed ok"ls -la $HOME/.claude/settings.jsonbare claude
claude -p "Reply with exactly: routed ok"Not logged in · Please run /loginunconfigure (re-run on f1d655f)
Same seed (
{"theme": "dark", "env": {"ANTHROPIC_API_KEY": "sk-ant-mine"}}), a freshHOME, and a stub answeringGET /v1/modelsonhttp://127.0.0.1:4739with the rig's six idslite --base-url http://127.0.0.1:4739 configure claude --api-key sk-rig-lit7355prints the same five lines as above and writes the same fourenvkeyslite unconfigure claudeapiKeyHelperandmodelwere never written, so they are not named):cat $HOME/.claude/settings.json{ "theme": "dark", "env": { "ANTHROPIC_API_KEY": "sk-ant-mine" } }ls $HOME/.litellm/is empty: the receipt is gone with nothing withheldType
🆕 New Feature
Caveats (if any)
Medium
lite configure codexneeds a TOML writer, which the CLI extra does not shiplite autoroute upis the mode that pins every tier to one groupunrecognized_model, assumes a 200k window, and sends no thinking params for it. Name the group like a model id, or append[1m], to change that; noted in the READMElite autoroute upalready uses; the command says so when the file is a symlink into a dotfiles repoLow
lite upandlite login --config-claudenow also drop a strayenv.ANTHROPIC_AUTH_TOKEN, since Claude Code prefers it over apiKeyHelperlite login --config-claudenow writes through the configure receipt, solite unconfigure claudeundoes it; it keeps a model pinned bylite configure claude --model, never adopts a key the user edited since the first configure, and refuses before logging in whilelite upholds the filePiSyncErrornow carries akinddecided where the /v1/models response is classified;lite pi's "nothing to run" wording moved to its callerlite autoroute upnow also sets the discovery env default and the Fable tier key, since it shares the mergeCLAUDE_CONFIG_DIRis not honored, matchinglite upandlite login --config-claude~/.litellm, less readable than the 0644 settings.json it came from), the same shape as thelite upandlite autoroute upbackups and Ramp Router's state file; it never holds the key configure writes, only its fingerprint. Keychain-backed snapshots for all three files are LIT-7437 (Veria, Low)Final Attestation
Note
Medium Risk
Changes persist API keys and proxy URLs in user home config with receipt logic; mistakes could leave Claude Code misrouted, though unconfigure and ownership checks limit blast radius.
Overview
Adds
lite configure claudeandlite unconfigure claudeso Claude Code can stay routed through the LiteLLM proxy without hand-editing~/.claude/settings.json. Configure accepts a long-lived--api-key(written asenv.ANTHROPIC_AUTH_TOKEN) or falls back tolite loginviaapiKeyHelper, validates the key withGET /v1/models, optionally pins a starting model with--model, and records an undo receipt at~/.litellm/claude_configure_state.json. Unconfigure restores only keys that still match what configure wrote, leaves user edits alone, and withholds credentials when the base URL no longer matches where they were captured.lite login --config-claudenow uses the same configure path (receipt-based undo) and refuses to run whilelite uporlite autoroute uphold a settings backup.merge_claude_settingsis unified forlite up, configure, and autoroute (static token vs helper, optional tier overrides); wiring also clears strayANTHROPIC_AUTH_TOKENso it cannot beatapiKeyHelper.lite autoroute upsets the top-levelmodelandANTHROPIC_DEFAULT_FABLE_MODELtoautoroutervia that shared merge.PiSyncErrorgains aListingFailurekind for clearer configure/pi listing errors.Reviewed by Cursor Bugbot for commit f1d655f. Bugbot is set up for automated code reviews on this repo. Configure here.