Skip to content

feat(auto-router): show the routed model and session savings in Claude Code and Codex - #40330

Merged
tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit7356_autorouter_statusline
Sep 11, 2026
Merged

tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_lit7356_autorouter_statusline

Conversation

@tin-berri

@tin-berri tin-berri commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Claude Code's status line can only show the alias the auto-router was asked for
  • Nothing tells a developer what a session actually cost versus the router's baseline
  • Codex shows no routing feedback at all

How it solves it:

  • GET /auto_router/session returns one session's routed model, spend and baseline spend, scoped to the caller's own key
  • A stdlib status line script, installed by every lite Claude Code wiring, renders Routed to plus the savings bars
  • lite codex registers the same script as a Stop hook, printing the block as a system message
  • The baseline is the router's own savings baseline (priciest model in the hardest tier), never a hardcoded model, and it is recorded per turn on the rollup row so the label stays true to the money after a reconfiguration
  • lite configure claude now requires a long-lived key (--api-key, lite --api-key or LITELLM_PROXY_API_KEY) and writes it as a static ANTHROPIC_AUTH_TOKEN. The lite login fallback that wrote apiKeyHelper: lite auth print-token is gone: Claude Code re-ran that helper on every credential refresh, each run was a full lite start that probes the keychain, and the status line would have spawned it every 300ms. lite login --config-claude stays, and lite up keeps working, but both now write the login's key statically (re-run login --config-claude when it expires); the status line reads the key from the env only
  • --model also pins env.ANTHROPIC_MODEL: a resumed session (claude -c, --resume) otherwise re-sends the tier model its transcript recorded and a key scoped to the router gets a 403
  • The lite autoroute wizard turns on return_raw_model_name, so the transcript names the tier model
  • lite autoroute up also pins the top-level model to autorouter, so a leftover model from lite configure claude cannot 400 the first turn

User Flow

Before: a developer running Claude Code through an auto-router sees the alias they requested and no cost feedback

  1. They run lite configure claude --api-key sk-... --model claude-sonnet-5 against a proxy whose claude-sonnet-5 group is an auto-router
  2. They send a message; the status line shows Claude Code's own model label, claude-sonnet-5, even though the proxy routed the turn to claude-haiku-4-5
  3. They call GET http://localhost:4000/auto_router/session?session_id= with their key and get 404, since the route does not exist
  4. In Codex, each turn ends with no routing or cost information at all

After: the same developer sees the served model and the session's savings in both tools

  1. They run the same lite configure claude --api-key sk-... --model claude-sonnet-5; the command also installs ~/.litellm/statusline.py and registers it as statusLine
  2. They send a message; the status line reads claude-sonnet-5 · Routed to: claude-haiku-4-5 -80% vs Claude Opus 5 with a LiteLLM $0.03 bar under a Claude Opus 5 $0.17 bar
  3. They call GET http://localhost:4000/auto_router/session?session_id= with their key and get 200 with last_model, spend, baseline_spend, baseline_model and baseline_models; the same call with any other key gets 404
  4. claude -c resumes on the router alias, since ANTHROPIC_MODEL outranks the model the transcript recorded
  5. In Codex launched through lite codex, Codex asks once to trust the hook, and every later turn ends with the same block as a system message
  6. lite unconfigure claude removes the statusLine entry only while it still points at that script

Relevant issues

Builds on #40319 (lite configure claude, merged), which owns the settings merge this PR hooks into; the status line is one more key that merge writes and the configure receipt owns.

Linear ticket

Resolves LIT-7356

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Screenshots / Proof of Fix

Setup shared by both runs: a worktree proxy with real Postgres and real Anthropic models through the sandbox gateway. The claude-sonnet-5 group is a heuristic complexity router (SIMPLE haiku, MEDIUM/COMPLEX sonnet, REASONING opus, so the savings baseline resolves to opus). A virtual key sk-toN... scoped to that group is what Claude Code and Codex use; a second key sk-other is the negative case.

  - model_name: claude-sonnet-5
    litellm_params:
      model: auto_router/complexity_router
      complexity_router_config:
        classifier_type: heuristic
        tiers: {SIMPLE: haiku-direct, MEDIUM: sonnet-direct, COMPLEX: sonnet-direct, REASONING: opus-direct}
        default_model: haiku-direct
        return_raw_model_name: true

Before (11ec6f7)

Claude Code transcript names the alias, not the served model

  1. claude -p "Reply with exactly: hello there" then claude -p --resume <session> "<a harder prompt>" with ANTHROPIC_BASE_URL at the proxy and ANTHROPIC_MODEL=claude-sonnet-5, then reading every assistant line of the transcript
  2. Four assistant lines, every one model='claude-sonnet-5', while the proxy's x-litellm-model-name on the same turns was anthropic/claude-haiku-4-5 and anthropic/claude-sonnet-5

Session endpoint

  1. curl "$PROXY/auto_router/session?session_id=cf712ab8-4c7c-4d48-ba91-eed54bc2956b" -H "Authorization: Bearer $KEY"
  2. 404 (route does not exist), while the rollup row for that session already sat in LiteLLM_AutoRouterSession

Codex

  1. codex exec "Reply with exactly: hello from codex" through the proxy
  2. Turn completes, nothing about routing or cost is shown

After (e485f6d)

Claude Code transcript and status line

  1. lite --base-url http://127.0.0.1:47358 configure claude --api-key $KEY --model claude-sonnet-5 from a fresh HOME
  2. Output ends with Start claudefrom any terminal. Undo withlite unconfigure claude.; ~/.claude/settings.json now carries "statusLine": {"type": "command", "command": "/…/.venv/bin/python /…/.litellm/statusline.py"} beside the env block; the script itself is -rw------- inside the owner-only ~/.litellm
  3. claude (interactive, driven through a pty), two prompts; the status line under the input box reads, in order:
Routed to: claude-haiku-4-5
claude-sonnet-5 · Routed to: claude-haiku-4-5  -80% vs Claude Opus 5
LiteLLM       █████░░░░░░░░░░░░░░░░░░░ $0.03
Claude Opus 5 ████████████████████████ $0.17
  1. Every assistant line of the transcript now says model='claude-haiku-4-5'
  2. lite unconfigure claude prints No settings file remains at …/settings.json; it held nothing but lite configure claude's own keys., since configure had created the file and statusLine is one of the keys its receipt owns

Session endpoint

  1. Owning key: curl "$PROXY/auto_router/session?session_id=cf712ab8-…" -H "Authorization: Bearer $KEY"
{"session_id":"cdf2ff00-d966-44d9-a23f-101b563da88a","router_name":"claude-sonnet-5","router_type":"complexity","turns":3,"last_model":"anthropic/claude-haiku-4-5","spend":0.03897375,"saved_spend":0.155895,"baseline_spend":0.19486875,"baseline_model":"anthropic/claude-opus-5","baseline_models":{"anthropic/claude-opus-5":3}}
  1. A second virtual key, same session id: 404 {"detail":"No auto-routed turns recorded for session 'cf712ab8-…' under this key"}
  2. The master key, same session id: 404 (its own earlier session, 463d0957-…, returns 200 with turns: 1)
  3. The virtual key on /auto_router/benchmarks: still 401, the admin gate is untouched
  4. Reconfiguration test: the proxy was restarted with the router's REASONING tier moved from opus-direct to sonnet-direct, so its live savings baseline became anthropic/claude-sonnet-5 (the log shows savings_baseline_model: anthropic/claude-sonnet-5 on the next decision). A fourth turn on the same session, then the same curl:
{"session_id":"cdf2ff00-d966-44d9-a23f-101b563da88a","router_name":"claude-sonnet-5","router_type":"complexity","turns":4,"last_model":"anthropic/claude-haiku-4-5","spend":0.04037975,"saved_spend":0.157301,"baseline_spend":0.19768075,"baseline_model":"anthropic/claude-opus-5","baseline_models":{"anthropic/claude-opus-5":3,"anthropic/claude-sonnet-5":1}}

The label stays claude-opus-5, which is what three of the four turns' saved_spend was priced against, and baseline_models shows the split instead of relabelling the old money with the new baseline

Resuming a session

Before this round (settings carried model: claude-sonnet-5 but no ANTHROPIC_MODEL), driven the same way through a pty on the same proxy:

  1. claude, one prompt: answered by claude-haiku-4-5 (the transcript records that id, since the router sets return_raw_model_name: true)
  2. claude -c, one prompt: Claude Code re-sends the transcript's model, the proxy log shows POST /v1/messages?beta=true HTTP/1.1" 403 Forbidden, and the TUI prints Please run /login · API Error: 403 key not allowed to access model.

After: lite configure claude --api-key $KEY --model claude-sonnet-5 writes "model": "claude-sonnet-5[1m]" and "env": {"ANTHROPIC_MODEL": "claude-sonnet-5[1m]", ...}. Same two runs: every request the proxy saw named model: claude-sonnet-5 (56 of 56, zero 403s), the transcript still records claude-haiku-4-5 per turn, and the resumed session's status line reads claude-sonnet-5 · Routed to: claude-haiku-4-5 -80% vs Claude Opus 5 with the cost bars under it. lite unconfigure claude restores env.ANTHROPIC_MODEL with the other keys

Configure without a key

lite configure claude --model claude-sonnet-5 with no key anywhere: Error: lite configure claudeneeds a long-lived virtual key: pass --api-key,lite --api-key, or set LITELLM_PROXY_API_KEY. Your lite login credential expires within a day, so it is not written into Claude Code's settings. No settings file, no receipt, no request, no login prompt

Codex Stop hook

  1. lite --base-url http://127.0.0.1:47358 codex --skip-verify exec "Reply with exactly: hello from codex" from a fresh HOME, with the hook already trusted the way the Codex TUI records it ([hooks.state."/<session-flags>/config.toml:stop:0:0"] trusted_hash = "sha256:16acd9a2…", enabled = true in ~/.codex/config.toml)
  2. lite prints litellm: routing Codex through proxy at http://127.0.0.1:47358 and launches Codex with -c hooks.Stop=[{hooks=[{type="command",command="…/python …/.litellm/statusline.py"}]}]
  3. Second turn on the same thread: … codex --skip-verify exec resume 01a08c71-86b2-7121-ab90-0f82e2e309a7 "Reply with exactly: second turn"; Codex's own output ends with
codex
second turn
hook: Stop
hook: Stop Completed
  1. The proxy access log shows the hook's call for that thread once per turn: GET /auto_router/session?session_id=01a08c71-86b2-7121-ab90-0f82e2e309a7 HTTP/1.1" 200 OK (on an earlier run the first turn's call was a 404 Not Found because the spend flush had not landed yet, and the second turn still found the row since the hook never caches)
  2. codex exec runs hooks but does not print their systemMessage (the TUI does), so the same script was invoked by hand with the Stop payload Codex sends for that thread, under the same env, to show the text:
claude-sonnet-5 · Routed to: claude-haiku-4-5  -80% vs Claude Opus 5
LiteLLM       █████░░░░░░░░░░░░░░░░░░░ $0.02
Claude Opus 5 ████████████████████████ $0.08
  1. The trust prompt itself is a Codex TUI dialog (Hooks need review with Trust all and continue), which I could not drive through a pty reliably; what Codex writes after that choice is the hooks.state block above, and an untrusted hook is skipped silently

Type

🆕 New Feature

Caveats (if any)

Medium

  • A virtual key whose allowed_routes confines it to llm_api_routes cannot call /auto_router/session (the route joins self_managed_routes, which waives the role gate, not a key's own route ceiling); its status line shows only the Routed to line, and the 403 is cached for the TTL so it does not retry every refresh. Add /auto_router/session to that key's allowed_routes to opt it in
  • The routed model only names the tier model when the auto-router deployment sets return_raw_model_name: true; otherwise the line shows the requested alias. The wizard sets it; hand-written configs must add it
  • Codex runs the hook only after the user picks Trust all and continue once in the TUI; codex exec skips untrusted hooks silently
  • A Codex config that already declares hooks keeps them: lite codex then skips its own Stop hook with a notice, since a session flag would replace the whole hooks.Stop list
  • The rollup is written by the async spend flush, so the cost lines lag a turn by a second or two; the Codex message reflects the session as of the previous turn
  • lite login --config-claude now writes the login's key as a static token that expires with it (24h by default), so it is the per-login re-wire step rather than a one-time setup. It configures Claude Code from the key in hand even when the CLI's own token file or keychain refused to keep the credential, and says so, since the key is usable either way; lite configure claude refuses to run on a lite login credential. A machine configured by an older version keeps working (its apiKeyHelper still resolves) until the next --config-claude or configure claude --api-key, which strips the helper; lite unconfigure claude restores whatever the receipt recorded for it
  • lite up now copies the resolved key into env.ANTHROPIC_AUTH_TOKEN for the life of the session; a key that expires while up is running is not refreshed until up is restarted. Every settings.json write (configure, up, autoroute up, and both restores) now goes through one owner-only, atomic, symlink-aware writer (write_claude_settings), so a file that now carries the key is never created under the umask or truncated in place; verified live with lite up over a 0644 file (patched file 0600, restored file 0600, no temp files left)
  • Model names reaching the status line come from the transcript, the proxy and Claude Code's model cache, none of which the script controls; control characters (ESC, BEL, C1) are stripped from every such label before it reaches the terminal, so a provider-chosen name cannot redraw the screen or set the clipboard through OSC-52
  • The Keychain prompt on plain lite commands (credential-preflight) comes from the token store's migrate-on-read in fix(anthropic): carry the adaptive effort tier to every bridged Claude target #38533, not from this PR; this PR removes the two places that invoked lite from Claude Code

Low

  • proxy-infra / Run tests went red once on test_check_migration.py::test_migrate_diff_stops_at_its_budget_and_takes_its_process_tree_with_it, a process-tree timing test this PR does not touch (green on the base PR head, on staging, and locally on this tree)
  • osv-scan is red on this head and on the base PR's head from the same hour (new advisories on next, sharp, js-yaml, vitest and diskcache in lockfiles this PR does not touch); it needs its own osv-scanner.toml PR, not this one
  • baseline_model is recorded per turn on the rollup row (baseline_models, a map of baseline to turns), so it names the counterfactual the money was actually priced against even after the router is reconfigured or removed; a session that straddles a baseline change reports the majority label and the full map. Rows written before this column existed, and adaptive or quality routers (which derive no savings baseline), report baseline_model: null
  • A session that touched two auto-router groups reports the group with the latest turn
  • The baseline_models column ships as one ADD COLUMN IF NOT EXISTS ... JSONB NOT NULL DEFAULT '{}' migration on LiteLLM_AutoRouterSession (schema-only, applied at boot); the prisma migrate deploy on the rig database and the real-Postgres rollup tests in tests/proxy_behavior/spend ran against it
  • gofmt, vet, build, test (the terraform provider workflow) is red on this head; it is path-filtered to terraform/provider/**, which this PR does not touch, and it is green on the staging tip
  • Docs for the new endpoint and the status line: docs(auto-router): per-session savings endpoint and the Claude Code status line litellm-docs#1382

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

Medium Risk
Touches proxy auth routing, spend rollup SQL, and CLI credential handling in user settings; session reads are key-scoped but keys with restricted allowed_routes may not reach the new endpoint without configuration.

Overview
Adds per-session auto-router visibility for coding agents: a new GET /auto_router/session (key-scoped) returns the last routed model, spend, savings baseline, and a baseline_models breakdown; the spend rollup now records savings_baseline_model per turn and persists baseline_models on LiteLLM_AutoRouterSession (migration + Prisma).

The lite CLI stops writing apiKeyHelper and instead copies a static ANTHROPIC_AUTH_TOKEN into Claude settings (lite up, login --config-claude, configure claude now requires a long-lived virtual key). --model also sets env.ANTHROPIC_MODEL so resumed sessions stay on the router alias. lite autoroute enables return_raw_model_name: true so transcripts show tier models.

A bundled statusline.py is installed atomically (write_private_bytes) and wired as Claude Code statusLine and a Codex Stop hook, showing routed model and savings bars from the new endpoint (5s cache, stdlib-only).

Reviewed by Cursor Bugbot for commit e485f6d. Bugbot is set up for automated code reviews on this repo. Configure here.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5

This is a strong, well-scoped implementation:

  • The session endpoint scopes the SQL lookup to the caller’s key and session ID, returns 404 for inaccessible/unflushed sessions, and derives the savings baseline from the live router configuration rather than hardcoding a model.
  • The Claude Code and Codex integrations share a self-contained stdlib-only script, preserve user-owned status-line settings, and make unconfiguration conditional on the installed command still being present.
  • The script handles transcript model detection, proxy failures, asynchronous rollup lag, caching, credential fallback, non-color output, and Codex systemMessage output.
  • The tests cover key isolation, missing routers, cache behavior, credential resolution, transcript filtering, rendering, standalone execution, settings preservation, and Codex hook wiring.

I’m not giving 5/5 yet because the required CI status is still pending, the PR is stacked on #40319, and the documented operational caveats (rollup lag, Codex trust flow, and outstanding litellm-docs documentation) still need to be validated or completed. I found no blocking correctness issue in the implementation reviewed.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@greptile-apps

greptile-apps Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds key-scoped auto-router session reporting and surfaces routed-model and session-savings information in Claude Code and Codex. It also persists per-turn baseline labels, installs the shared status-line script atomically, pins resumed Claude sessions to the router model, and restores lite login --config-claude using a static token.

  • Adds the /auto_router/session endpoint through a repository abstraction.
  • Records baseline-model counts in the auto-router session rollup.
  • Integrates routed-model and savings output with Claude Code and Codex.
  • Consolidates private, atomic Claude settings and script writes.
  • Restores the opt-in login configuration flow, though one persistence-failure path skips it silently.

Confidence Score: 4/5

The PR is not yet safe to merge because login --config-claude can silently omit its requested configuration when credential persistence fails.

The previous baseline-label, repository-access, docstring, credential-scoped cache, and atomic-script findings are fixed in the current code. The earlier compatibility finding is also fixed because lite login --config-claude has been restored. One remaining blocking path returns after a successful login but before configuring Claude Code when the credential cannot be saved or recorded.

Files Needing Attention: litellm/proxy/client/cli/commands/auth.py

Important Files Changed

Filename Overview
litellm/proxy/client/cli/commands/auth.py Restores login --config-claude with static-token configuration, but returns before configuring when credential persistence fails.
litellm/proxy/management_endpoints/auto_router_endpoints.py Adds a key-scoped auto-router session endpoint using the repository layer and persisted baseline metadata.
litellm/repositories/autorouter_session_repository.py Encapsulates lookup of the latest session rollup for the caller’s exact key and session.
litellm/proxy/client/cli/commands/statusline_script.py Implements sanitized routed-model and savings rendering with credential-scoped caching.
litellm/proxy/client/cli/commands/claude_settings.py Installs the status-line script and performs owner-only atomic settings updates while preserving configuration ownership.
litellm/proxy/db/autorouter_session_rollup.py Persists per-turn baseline-model counts so historical savings retain the correct comparison label.

Comments Outside Diff (1)

  1. litellm/proxy/client/cli/commands/auth.py, line 817-821 (link)

    P1 Claude configuration silently skipped

    If credential persistence returns CredentialNotSaved or CredentialNotRecorded, _finish_login returns before honoring --config-claude. The login can therefore mint a usable key but silently leave Claude Code unconfigured, even though the requested setup had enough information to proceed. Configure Claude before this persistence-dependent return, or clearly report that the configuration was skipped.

Reviews (4): Last reviewed commit: "feat(auto-router): show routed model and..." | Re-trigger Greptile

Comment on lines +762 to +763
rows: Final = _SESSION_ROWS.validate_python(
await _query_raw(prisma_client, AUTOROUTER_SESSION_SQL, user_api_key_dict.api_key, session_id) or ()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Direct database query

This handler calls _query_raw directly, violating the repository requirement that request paths use the approved key, team, or user helpers

Rule Used: What: In critical path of request, there should be... (source)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6d0b48c: the endpoint now goes through AutoRouterSessionRepository.find_latest_for_key, so no raw SQL sits in the request path.

Comment on lines +60 to +61
class Session(NamedTuple):
"""The proxy's record of one auto-routed session, as GET /auto_router/session returns it."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Routine docstrings violate policy

These explanatory docstrings violate the repository requirement limiting source comments to complex logic, tool inputs, or TODO and FIXME notes

Context Used: CLAUDE.md (source)

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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6d0b48c: the routine docstrings are gone from the script, claude_settings and agents; only non-obvious invariants keep one.

Comment on lines +218 to +220
try:
script_path.parent.mkdir(parents=True, exist_ok=True)
script_path.write_bytes(Path(statusline_script.__file__).read_bytes())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Script replacement is non-atomic

Concurrent Claude or Codex sessions can execute the shared script while write_bytes truncates it, causing missing or malformed status output

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6d0b48c: the script is staged beside the target and renamed into place via write_private_bytes, so no truncate-then-write remains.

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

@tin-berri
tin-berri force-pushed the litellm_lit7356_autorouter_statusline branch from 6a8b56c to a8c29b2 Compare September 9, 2026 00:25
@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri
tin-berri force-pushed the litellm_lit7355_claude_configure branch from be34b15 to 66696b3 Compare September 9, 2026 00:26
@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5

The feature is implemented end-to-end: the self-scoped session endpoint, bounded session IDs, Claude status-line installation/unconfiguration, Codex Stop-hook wiring, raw routed-model names, schema updates, and focused tests are all covered. The key-scoping and route-gating behavior is also exercised, and the PR includes real Claude/Codex/Postgres validation plus a passing e2e status check.

I’m not giving it 5/5 because two edge cases remain: baseline_model is resolved from the live router configuration, so historical savings can be labeled incorrectly after a router reconfiguration; and the local status-line cache is keyed only by session_id, not proxy/key scope, so reusing a session ID across credentials or proxies can display stale data. The non-atomic cache-file write and direct raw SQL query are additional maintainability concerns, but they do not undermine the primary feature flow.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@veria-ai

veria-ai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 5 · PR risk: 0/10

@tin-berri
tin-berri force-pushed the litellm_lit7356_autorouter_statusline branch from a8c29b2 to b9e9b0f Compare September 9, 2026 00:40
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score? Since your last look: the cache is now keyed by proxy, key and session (b9e9b0f); the live-config baseline label is a documented caveat.

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5 (unchanged).

The two concerns from my previous review are addressed: the status-line cache is now scoped by proxy, key, and session, and the live-config baseline behavior is clearly documented as an operational caveat rather than being presented as historical attribution.

The implementation otherwise looks strong end-to-end: key-scoped session reads, bounded session IDs, Claude/Codex credential separation, receipt compatibility, and focused tests are covered. The latest e2e status is also passing.

I’m holding at 4/5 because install_statusline_script() still creates or overwrites ~/.litellm/statusline.py using ambient directory/file permissions and a non-atomic write (claude_settings.py:220). In a collaborative filesystem setup, another user could modify the hook that Claude Code or Codex executes with the proxy credential in its environment. Tighten the parent directory and destination to owner-only permissions and install the script atomically. The direct raw SQL call in auto_router_endpoints.py remains a repository-rule/maintainability concern, but not a feature-flow blocker.

Once the hook installation permissions are hardened and the remaining CI checks are green, I would consider this a 5/5.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tin-berri
tin-berri force-pushed the litellm_lit7355_claude_configure branch from 66696b3 to 4a6f825 Compare September 9, 2026 00:55
@tin-berri
tin-berri force-pushed the litellm_lit7356_autorouter_statusline branch from b9e9b0f to 1b73e52 Compare September 9, 2026 00:59
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score? 1b73e52 installs the script owner-only (0600 file, 0700 dir) and runs the apiKeyHelper only on a cache miss.

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 5/5.

The two remaining implementation concerns are addressed in 1b73e52bb5:

  • install_statusline_script() now creates the containing directory with owner-only permissions and opens the script with 0600, preventing another local user from replacing the executable hook.
  • load_session() checks the session cache before resolving credentials, so apiKeyHelper runs only on a cache miss (at most once per cache TTL), rather than on every status refresh. The helper identity is hashed for cache scoping; its returned token is not written to the cache.

Together with the earlier proxy/key/session cache scoping and the documented live-baseline attribution caveat, I found no remaining feature-flow correctness blocker. CI is still pending, and the direct raw SQL call remains a repository maintainability concern, but neither changes the implementation confidence score.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tin-berri
tin-berri force-pushed the litellm_lit7356_autorouter_statusline branch from 1b73e52 to 96d6090 Compare September 9, 2026 01:13
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Score: 4/5.

The implementation is well-scoped and the validation is unusually thorough: it covers key-scoped session access, baseline persistence across router reconfiguration, resumed Claude sessions, static credential handling, Claude status-line output, Codex Stop hooks, and the no-key configuration failure path. The per-turn baseline recording and baseline_models aggregation preserve the correctness of historical savings instead of relabeling old spend after reconfiguration.

I’m not giving it 5/5 because this is a broad cross-cutting change spanning the API, migration, async spend rollups, Claude/Codex integrations, and local config mutation. The CI status is still pending, and the documented rollup timing, hook trust behavior, legacy configuration compatibility, and route-permission caveats leave some integration risk that should be confirmed by the remaining checks.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tin-berri
tin-berri force-pushed the litellm_lit7356_autorouter_statusline branch from 7327498 to 41fd991 Compare September 11, 2026 00:32
@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Score: 4/5 (high confidence).

The implementation is broad but cohesive and addresses the requested flow end to end:

  • Adds the key-scoped /auto_router/session endpoint with 404 isolation for other keys, bounded session IDs, and repository-backed reads.
  • Records the savings baseline per turn, preserving correct attribution when router configuration changes mid-session.
  • Wires the stdlib status-line script into Claude Code and Codex, including caching, async-flush lag handling, quiet fallbacks, and control-character sanitization.
  • Handles Claude settings ownership, static credentials, resume-model pinning, atomic/private writes, symlinks, restore behavior, and existing user hooks carefully.
  • Adds meaningful unit, repository, auth, real-Postgres rollup, and CLI tests; the current E2E status is passing.

I’m not giving 5/5 because this is a relatively large cross-cutting change touching proxy routes, persistence, schema/migration, CLI behavior, and agent integrations, so it carries more integration risk than a small isolated feature. I did not find a correctness issue that should block merge based on the reviewed head.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment on lines 805 to 827
@@ -865,22 +820,16 @@ def _pkce_login(base_url: str, config_claude: bool, vault: SecretVault) -> None:
),
)
@click.pass_context
def login(ctx: click.Context, config_claude: bool, pkce: bool) -> None:
def login(ctx: click.Context, pkce: bool) -> None:
"""Login to LiteLLM proxy using SSO authentication"""
from litellm.constants import LITELLM_CLI_SOURCE_IDENTIFIER

ctx_obj: Final[CliContextObj] = ctx.obj

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 CLI compatibility removed

Removing login --config-claude breaks existing automation without an opt-in flag, violating the repository requirement against uncontrolled backwards-incompatible changes

Rule Used: What: avoid backwards-incompatible changes without user-controlled flags Why: This breaks current behaviour for users using existing functionality Example of BAD: this PR (#22164) introduced run_post_custom... (source)

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!

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tin-berri
tin-berri force-pushed the litellm_lit7356_autorouter_statusline branch from 41fd991 to e67939c Compare September 11, 2026 01:41
@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5

This is a strong end-to-end implementation. The latest changes address the earlier concerns: the status-line cache is scoped by proxy, key, and session; long session IDs use the same bounded representation as the rollup; baseline identities are recorded per turn; the endpoint uses the repository layer; and older Claude settings receipts have regression coverage. The feature is also backed by focused tests and a passing e2e status check.

I’m not giving 5/5 because the change has a broad CLI/integration surface with documented operational caveats (async rollup lag, Codex hook trust, credential expiry, and externally tracked documentation), and the current status view does not establish that every required CI check is green. I found no blocking correctness issue in the current implementation.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@tin-berri
tin-berri enabled auto-merge (squash) September 11, 2026 02:46
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai review

@tin-berri
tin-berri force-pushed the litellm_lit7356_autorouter_statusline branch from e67939c to e485f6d Compare September 11, 2026 17:18
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai fixed in e485f6d: --config-claude now configures Claude Code before the persistence-dependent return and reports when the CLI could not keep the key. Can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 5/5

The remaining issue is fixed in e485f6d0c1: _finish_login() now calls _configure_claude_code(base_url, api_key) before returning for CredentialNotSaved or CredentialNotRecorded. This correctly uses the freshly minted key that is still in hand, so --config-claude is honored even when the CLI cannot persist its own credential. The added message makes that outcome explicit, and the focused tests cover both persistence-failure cases and verify that Claude Code receives the static token. I found no remaining correctness blocker in the reviewed implementation.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 e485f6d. Configure here.

@tin-berri
tin-berri merged commit f22f9bc into litellm_internal_staging Sep 11, 2026
95 of 96 checks passed
@tin-berri
tin-berri deleted the litellm_lit7356_autorouter_statusline branch September 11, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants