Skip to content

fix(anthropic): Claude models fail with a missing API key after Claude CLI sign-in unless sign-in seeded them - #167963

Merged
obviyus merged 4 commits into
mainfrom
fix/claude-cli-runtime-routing
Oct 9, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/claude-cli-runtime-routing

Conversation

@obviyus

@obviyus obviyus commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: after Claude CLI sign-in (openclaw models auth login --provider anthropic --method cli), any anthropic/<id> that sign-in did not seed fails with No API key found for provider "anthropic" … missing-provider-auth. This affects Claude models published after sign-in and IDs typed with --model, /model or models set, such as anthropic/claude-haiku-4-5.

User Impact

User impact: Claude-CLI-only users can type or pick any Claude model and it runs through Claude Code. The model picker still lists only models the Claude CLI catalog serves, so claude-mythos-5 (direct API only) stays hidden. Users with an Anthropic API key and no Claude CLI sign-in keep the API route. Exact model entries that name another runtime still win. A session pinned to an Anthropic API-key account keeps that account's models, including claude-mythos-5, in its picker.

Existing installs that signed in on an affected build get the new routing only after they rerun openclaw models auth login --provider anthropic --method cli. This PR adds no Doctor migration.

User-authored provider/* wildcards for other CLI backends behave exactly as on main. For example, google/* → google-gemini-cli keeps the same picker rows, and its typed IDs run as before. The picker gate is keyed on the anthropic/* → claude-cli entry that sign-in writes.

Why This Change Was Made

Since #129052, Claude CLI sign-in persists no OpenClaw auth profile. At run time, resolveCliRuntimeExecutionProvider (src/agents/model-runtime-aliases.ts) found no runtime policy for unseeded IDs and no claude-cli profile it could alias. The turn then fell to the embedded Anthropic API path. An instrumented isolated Gateway on 58ba7ed showed policy=undefined … viaAuthProfile=undefined and then useCliExecution=false.

  • Sign-in (extensions/anthropic/cli-migration.ts) now also writes the existing, documented provider wildcard agents.defaults.models["anthropic/*"] = { agentRuntime: { id: "claude-cli" } }. It does not overwrite a wildcard that already names another runtime.
  • Catalog decisions (src/agents/model-catalog-cli-wildcard.ts, used by model-catalog-decisions.ts) mark a row unavailable, with no "sign in" reason, when all of these hold: native Claude CLI credentials supplied the availability (evidence: "runtime"), the row reaches claude-cli only through that sign-in wildcard, the Claude CLI catalog does not list it (bundled manifest plus published catalog), and it is not a configured row. Availability from a selected or pinned API account is never narrowed. Run-time routing is unchanged, so typed IDs still run.

Production change: 3 lines in cli-migration.ts, 15 net lines in model-catalog-decisions.ts and a new 58-line module (about 45 code lines). No config keys, schema or SDK surface change.

Provenance (f8b06fb, #166037): prepared catalog decisions keep saved account, model and runtime choices and their provenance. createCliRuntimeModelAuthEvaluator returns a pinned non-native account's own provider-auth result, and evaluateNative keeps host results for selected accounts. The wildcard gate now only narrows availability that came from native Claude CLI credentials, so a saved account choice keeps the models that account can use.

Evidence

Real proofs used the machine's existing native claude login, OpenClaw's real sign-in flow, isolated profiles and a loopback Gateway:

  • Before, on main 58ba7ed: models set anthropic/claude-haiku-4-5 plus one turn failed with missing-provider-auth, and the instrumentation showed no CLI route.

  • After, on b35cc8e: the picker lists available rows that exactly match the 11 Claude CLI catalog IDs. claude-mythos-5 and claude-haiku-4-5 are not listed.

  • After: a turn typed with --model anthropic/claude-haiku-4-5 returned OK with runner=cli and winnerProvider=claude-cli.

  • After: models set anthropic/claude-haiku-4-5 plus a turn returned OK through claude-cli.

  • API-key control: on a profile with paste-api-key (key piped on stdin) and no Claude CLI sign-in, an anthropic/claude-haiku-4-5 turn returned OK with runner=embedded and winnerProvider=anthropic. Mythos stays listed for API users, as on main.

  • Regressions:

    • extensions/anthropic/cli-migration.test.ts, including the registered non-interactive sign-in entry: 4 failures without the fix, 40/40 pass with it.
    • src/agents/model-catalog-decisions.test.ts: the Claude CLI wildcard test fails without the gate (expected true to be false). With the gate, it covers a listed row, an API-only row (unavailable, no reason), an exact pinned row, a configured typed row, an exact override to openclaw, and an unchanged google/* → google-gemini-cli row even when that backend lists its own rows.
    • Same test, selected-account case (added on 41f26e5): with the wildcard and a session pinned to an Anthropic API-key profile, claude-mythos-5 is available with selectedProfileId: "anthropic:work" in both evaluateEntry and evaluateNative. With only native Claude CLI credentials it stays unavailable. On 651801e this fails (expected { availability: false … } to match object { availability: true … }). With the fix, 24/24 pass in the file, and model-auth-availability.test.ts plus cli-migration.test.ts pass.
  • New-model simulation on 651801e, in a throwaway worktree with claude-fable-5 removed from local knowledge: both bundled manifest rows (anthropic, claude-cli), the fable-5 alias, the model-catalog-core alias and the Claude CLI context alias. models.catalogRefresh.url pointed at a loopback copy of catalog.openclaw.ai/models/v2/catalog.json, served at first without anthropic/claude-fable-5 and claude-cli/claude-fable-5.

    • Before: models.list {view:"configured", refresh:true} (the Control UI view) returned 10 Claude rows and no Fable 5 row.
    • I added both rows back only in the served copy, with a newer generatedAt, then ran openclaw models refresh and models.list {refresh:true}. The Gateway PID did not change. The first response was unchanged because adoption starts after that response. The next read listed claude-cli/claude-fable-5 as available, but not anthropic/claude-fable-5. A Gateway restart gave the same rows, so the refresh lifecycle is not the cause.
    • Turns: --model anthropic/claude-fable-5 returned OK on the same Gateway PID with runner=cli, winnerProvider=claude-cli and winnerModel=claude-fable-5. --model claude-cli/claude-fable-5, the row the picker shows, also returned OK through claude-cli.
  • Gates on 41f26e5: node scripts/check-changed.mjs exited 0. It ran the tsgo lanes, oxlint on core and the changed extension files, the full dead-export scan, format checks, ratchets and the import-cycle check. pnpm exec oxlint --type-aware on the changed files exited 0.

Upgrade cell (published v2026.9.9 → this PR, disposable Docker container from the scripts/e2e/Dockerfile bare stage, candidate packed with scripts/package-openclaw-for-docker.mjs from 41f26e5, build 2026.9.9-41f26e5206fc). api.anthropic.com resolved to loopback in the container, so the fake key never left it. npm latest is still 2026.9.9.

  • Existing state was written by the published CLI. It had a Claude CLI-style agents.defaults.models with three anthropic/* IDs on claude-cli and no wildcard, primary anthropic/claude-opus-5-5, and an anthropic:work API-key profile from paste-api-key with a fake key. Through the v2026.9.9 Gateway, sessions.create and then sessions.patch {model:"anthropic/claude-sonnet-5@anthropic:work"} saved this session selection: providerOverride=anthropic, modelOverride=claude-sonnet-5, authProfileOverride=anthropic:work (user), agentRuntimeOverride=claude-cli.
  • openclaw update --tag file:<tgz> --no-restart --yes --json exited 0 with status: ok and all steps at 0. The CLI now reports OpenClaw 2026.9.9 (41f26e5). The updater's doctor, openclaw doctor --non-interactive and config validate passed (valid: true, no warnings). Doctor warnings matched the baseline: a plaintext gateway token in the fixture, loopback bind and no service manager. The saved session selection and agents.defaults.models read back identical to the pre-update values.
  • Claude CLI sign-in again, with the real openclaw models auth login --provider anthropic --method cli --set-default under a pty. It needs a TTY. Without a claude binary it stops with Claude CLI is not authenticated on this host. With a stub claude on PATH that only answers auth status --json with {"loggedIn":true,"authMethod":"claude.ai"} and --version, and never runs a model, it exited 0. That was the only stubbed part; the sign-in, config write and Gateway are the shipped code. After the first sign-in, "anthropic/*": {agentRuntime:{id:"claude-cli"}} was present once. A second sign-in left it present once. The three existing entries and the primary were unchanged, the session selection was identical after each sign-in, and config validate and doctor passed.
  • Candidate Gateway with the wildcard present: models.list {sessionKey, view:"all", provider:"anthropic"} for the session pinned to anthropic:work listed claude-mythos-5 as available: true. models.list {agentId:"main"}, with no selected account, listed it as available: false, which is the accepted Claude CLI-first behavior.
  • Not covered: no real Claude Code turn ran in the cell. Real turns are in the evidence above. The update's package swap took 23 min on a loaded host; an earlier v2026.9.9 cell on the same host took 7–11 min for the whole update. No Telegram Test Server run.

Gap: a Claude model that the published catalog adds later appears in the picker without a restart, but only as claude-cli/<id>, not anthropic/<id>. anthropic is a refreshable catalog provider, so its published rows appear only when live /v1/models discovery returns them, and that discovery needs an API key. The src/agents/model-catalog.ts guard says "Only live registry or refreshed rows may publish those provider models". claude-cli is static, so its published row appears. The sign-in wildcard gate only marks existing anthropic rows unavailable and never adds rows, so the claude-cli row has no anthropic twin to fold into. Both refs run through Claude Code. Showing anthropic/<id> would need a separate change to the refreshable-provider guard in model-catalog.ts or to the CLI twin collapse in model-runtime-aliases.ts.

Merge danger

Medium-low. The run-time change is config written only by Claude CLI sign-in. The picker change sits in shared catalog decisions, but it applies only when an agent's anthropic/* entry names claude-cli and the row is neither configured nor listed by the Claude CLI catalog.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: anthropic size: S labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Claude CLI sign-in adds a provider-wide routing rule so unseeded Claude models run through Claude Code, while model pickers preserve explicit API-account choices.

Example: After Claude CLI sign-in, a user selects anthropic/claude-haiku-4-5.

  • Before: The turn falls through to the Anthropic API and fails with missing-provider-auth.
  • After: The recorded turn returns OK with runner=cli and winnerProvider=claude-cli.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, correct routing repair with real Gateway behavior and published-release upgrade evidence; the prior blockers are resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded real sign-in and isolated Gateway turns exercise the changed routing owner: unseeded Haiku and newly published Fable return OK through Claude CLI, while the API-only control retains Anthropic execution. The reviewed-head upgrade cell preserves published v2026.9.9 settings and session selections through update and repeated sign-in; only native auth-status detection is stubbed in that cell.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users signed in through Claude CLI receive a missing API-key error when selecting a Claude model that sign-in did not seed.
Reason: The repair restores the documented Claude CLI execution path using an existing routing contract. The routing tradeoff and separate existing-sign-in migration have recorded acceptance from an account with verified repository maintain permission.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary on current main. The previous selected-account finding and upgrade-compatibility blocker are resolved, and no actionable code defect remains.

Priority: P2
Reviewed head: 41f26e5206fc13b8aaafc6f3641fd56c93d6ee3c

Before merge

None.

Findings

None.

Agent review details

How this fits together

OpenClaw uses saved model routing rules and account credentials to choose between provider APIs and local command-line applications. Prepared authentication decisions also determine model availability in UI and channel pickers.

flowchart TD
  A[Claude CLI sign-in] --> B[Saved model routing rules]
  B --> C[Model and selected account]
  C --> D[Prepared authentication decision]
  D --> E[Claude CLI catalog filter]
  E --> F[UI and channel model pickers]
  C --> G[Provider API or Claude Code turn]
Loading

Technical review

Best possible solution:

Keep native Claude authentication authoritative and use the existing routing contract without weakening explicit account or runtime choices.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main sign-in leaves unseeded Anthropic IDs without a CLI runtime policy or native-auth profile alias, matching the contributor's recorded missing-provider-auth Gateway failure. This read-only review did not execute target code.

Is this the best way to solve the issue?

Yes: adding the existing wildcard at sign-in fixes routing at its producer, and the catalog restriction now preserves availability supplied by explicit API accounts. No new configuration key or parallel execution path is introduced.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 427f926e7c2d.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main necessity: Fetched main still seeds known and selected Claude model references without the anthropic/* routing rule. Its newer account-listing logic does not repair sign-in routing for unseeded IDs. (extensions/anthropic/cli-migration.ts:130, 427f926e7c2d)
  • Previous finding resolved: The latest commit limits picker suppression to availability supplied by native runtime credentials. The regression preserves claude-mythos-5 availability and anthropic:work selection through both host and native evaluations. (src/agents/model-catalog-decisions.ts:367, 41f26e5206fc)
  • Real routing evidence: The supplied complete body records real native Claude login, OpenClaw sign-in, and isolated Gateway turns: unseeded Haiku returns OK through claude-cli, while an API-key-only control returns OK through anthropic. A published-model simulation also executes Fable without restarting the Gateway. Captured sourceRevision: 54ed225ce3be4eb728a4a0da73374eb46ef74365a52848e754c2e76964ca8637. These contributor observations were inspected; target code was not executed during this review. (b35cc8eae0e0)
  • Published-release upgrade compatibility: The new body evidence records published v2026.9.9 updating to the reviewed head with existing models, primary selection, API profile, and saved session selection preserved. Repeated shipped CLI sign-in adds the wildcard once; Doctor and config validation pass. Native auth-status detection alone was stubbed in this upgrade cell, while real Claude turns are documented separately. Candidate Gateway reads preserve the pinned API account's Mythos availability. (41f26e5206fc)
  • Accepted routing tradeoff: The written decision at fix(anthropic): Claude models fail with a missing API key after Claude CLI sign-in unless sign-in seeded them #167963 (comment) accepts routing unseeded Anthropic models through Claude Code even when API credentials exist, preserves exact runtime overrides, and assigns existing-sign-in migration to follow-up work. The permission endpoint independently verifies the author's maintain role.
  • Routing and account provenance: History identifies model-scoped sign-in routing in Fix Claude CLI runtime migration for gateway turns #82546 and prepared account-selection preservation in perf(gateway): restore fast saved-session model picking #166037. Their stated contracts retain explicit runtime and account choices; this patch respects both. (src/agents/model-catalog-decisions.ts:355, f8b06fbb69b6)

Likely related people:

  • Peter Steinberger: Raw commit f8b06fb adds src/agents/model-catalog-decisions.ts:283 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f8b06fbb69b6; files: src/agents/model-catalog-decisions.ts)
  • Alex Knight: Raw commit c438dad adds extensions/anthropic/cli-migration.ts:134 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c438dadc5c65; files: extensions/anthropic/cli-migration.ts)

PR surface

Source +76, Tests +94, Docs 0. Total +170 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 77 1 +76
Tests 2 94 0 +94
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 172 2 +170

Review metrics

Metric Value Why it matters
Persisted routing rule 1 provider-wide rule added during Claude CLI sign-in The existing configuration contract now covers model IDs outside the sign-in seed list.
Production versus tests Production +77/-1 lines; tests +94/-0 lines Production growth supports the routing repair and its scoped catalog restriction, with regression coverage for preserved choices.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: The defect affects Claude CLI users selecting unseeded models and has a bounded provider-specific repair.
  • merge-risk: 🚨 compatibility: Sign-in changes persisted provider-wide routing; the published-release upgrade evidence verifies preservation, and migration of prior sign-ins is explicitly accepted as follow-up work.
  • merge-risk: 🚨 auth-provider: The accepted routing change selects Claude CLI for unseeded Anthropic models even when API credentials exist, while retaining exact overrides.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The shared availability filter changes Claude model choices visible in Telegram model pickers and commands.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-09T21:01:23.192Z sha 651801e :: blocked before merge. :: [P2] Preserve availability supplied by an explicitly selected API account
  • reviewed 2026-10-09T21:31:17.677Z sha 651801e :: blocked before merge. :: [P2] Preserve availability supplied by an explicitly selected API account
  • reviewed 2026-10-09T22:13:33.771Z sha 41f26e5 :: blocked before merge. :: none

Reviewed October 9, 2026, 7:13 PM ET / 23:13 UTC (Revision 4).

@obviyus
obviyus marked this pull request as ready for review October 9, 2026 21:25
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer decision: accepted. Users with both a Claude CLI sign-in and an Anthropic API key now run anthropic/* models that were not known at sign-in through Claude Code, matching how sign-in-seeded models already route; an exact agents.defaults.models entry can still pin a model to the API. A follow-up PR adds a Doctor migration for existing Claude CLI sign-ins and stops seeding deprecated catalog rows.

@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 9, 2026
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

The requested data-model compatibility proof is in the PR body under Evidence → "Upgrade cell": published v2026.9.9 state (Claude CLI-style agents.defaults.models, an Anthropic API-key profile, and a session pinned to that account and runtime) updated to 41f26e5; update ok, doctor and config validate clean, saved models and session selection identical after update and after two Claude CLI sign-ins (wildcard present exactly once).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 9, 2026
@obviyus
obviyus merged commit 9c241fe into main Oct 9, 2026
131 checks passed
@obviyus
obviyus deleted the fix/claude-cli-runtime-routing branch October 9, 2026 23:58
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 9c241fe. After Claude CLI sign-in, any anthropic/ Claude model runs through Claude Code (sign-in writes the documented anthropic/* → claude-cli rule), and the picker only shows models the Claude CLI catalog lists unless a selected API account supplies them. Proof: real Claude Max sign-in (typed and catalog-added models run via Claude Code, API-only models stay out), API-key control, and a published 2026.9.9 upgrade with saved selections intact.

obviyus added a commit that referenced this pull request Oct 10, 2026
…rlier Claude CLI sign-in (#168074)

Related: #167963

## What Problem This Solves

Fixes: Claude models that Claude CLI sign-in did not add fail with "No API key found for provider anthropic" for anyone who signed in to Claude CLI on a release since native Claude CLI login (#129052), because those configs predate the `anthropic/*` runtime entry that #167963 now writes at sign-in. Sign-in also still added deprecated catalog models such as `claude-opus-4-8` to fresh configs.

## User Impact

User impact: after `openclaw update` (or `openclaw doctor --fix`), an earlier Claude CLI sign-in routes every Claude model through Claude Code, the same as a fresh sign-in. Fresh sign-ins no longer add deprecated catalog models; an existing entry for one, such as `claude-opus-4-8`, is kept.

Configs with an Anthropic credential, an API default model with a Claude CLI fallback, a provider-level Anthropic runtime, or an existing `anthropic/*` entry are left unchanged.

## Why This Change Was Made

The Anthropic plugin now owns a Doctor config repair (`doctorContract.configRepair`). It adds `agents.defaults.models["anthropic/*"] = { agentRuntime: { id: "claude-cli" } }` only when all of these hold:

- the default model is an `anthropic/...` ref whose entry pins `claude-cli` (what sign-in writes);
- no `anthropic/*` entry exists, whatever runtime it names;
- no `models.providers.anthropic.agentRuntime` (the wildcard would outrank it);
- no Anthropic credential is visible to config repair: an `anthropic` auth profile, a provider `apiKey` other than the retired `anthropic:claude-cli` marker, or `ANTHROPIC_API_KEY`/`ANTHROPIC_OAUTH_TOKEN` in the environment or config `env`.

Specific model entries keep winning over the wildcard, so entries that name a runtime are unaffected. Runtime reads only the canonical entry; there is no new compatibility reader. The change is reported as a Doctor change (`openclaw doctor` lists it, `--fix` writes it).

Sign-in seeding filters catalog rows with `status: "deprecated"`. Route probing and the setup picker still see every row.

## Update Behavior

The installed updater cannot be patched, so the repair keys only on config that shipped Claude CLI sign-ins already wrote. During `openclaw update`, the candidate's own Doctor runs twice: once as `doctor --fix` in the candidate rehearsal on a private state snapshot (`candidate-doctor`), then as `doctor --repair --non-interactive` in a fresh process after the package swap (`openclaw doctor`). The second run writes the repair through Doctor's normal backed-up config write (`openclaw.json.bak` ring plus `openclaw.json.pre-update`), so update rollback restores the earlier config. The update result lists the change under the Doctor migration notes. Gateway startup does not apply it to a valid config. After a manual package replacement, run `openclaw doctor --fix`.

## Evidence

- Regression tests fail at the parent commit and pass here:
  - `extensions/anthropic/cli-migration.test.ts`: `registered cli sign-in seeds no deprecated Claude CLI catalog rows` fails at the parent (`expected { …(12) } to not have property "anthropic/claude-opus-4-8"`). Its second case shows an existing `claude-opus-4-8` default and entry survive sign-in. Three existing seeding expectations drop `claude-opus-4-8`.
  - `extensions/anthropic/doctor-contract-api.test.ts`: covers the repair, idempotency, both kinds of existing wildcard, an API default with a Claude CLI fallback, a non-Anthropic default, auth profile, provider API key, config env key, process env key, provider-level runtime, and the retired provider marker. At the parent the module does not exist.
- Published-driver × candidate cells: Docker `bare` image, published `[email protected]` from npm, sign-in through the published `openclaw onboard --non-interactive --auth-choice anthropic-cli` with a stub `claude` that only answers `claude auth status`. Then `openclaw update --tag file:<candidate tgz> --no-restart --yes --json` to a package built by `scripts/package-openclaw-for-docker.mjs` from this head:

  | Cell | Config before update | `update` | `anthropic/*` after | Other model entries | Post-update `doctor` / `config validate` |
  | --- | --- | --- | --- | --- | --- |
  | A | 2026.9.9 sign-in: 11 seeded rows pinned `claude-cli`, default `anthropic/claude-opus-5-5`, no wildcard | `status: ok`, `2026.9.9 (bcfc888)` → `(587456f)`; result notes `Doctor migration: agents.defaults.models["anthropic/*"]: added the claude-cli runtime …` | `{ agentRuntime: { id: "claude-cli" } }` | unchanged (only `anthropic/*` differs); `.bak`, `.bak.1` and `.pre-update` have no wildcard | exit 0, no further Anthropic finding / `Config valid` |
  | B | A plus `"anthropic/*": { agentRuntime: { id: "openclaw" } }` | `status: ok` | still `openclaw` | unchanged | exit 0 / `Config valid` |
  | C | A plus an `anthropic:default` API-key auth profile | `status: ok` | absent | unchanged | exit 0 / `Config valid` |

  Replaying the candidate Doctor on a copy of cell A's pre-update config: `openclaw doctor --non-interactive` lists the `agents.defaults.models["anthropic/*"]` change and leaves the file unchanged. `openclaw doctor --fix --non-interactive` writes `{ agentRuntime: { id: "claude-cli" } }` and rotates `openclaw.json.bak`. The same replays leave cells B and C unchanged.
- `pnpm exec oxlint --type-aware` on the changed files: clean. `node scripts/check-changed.mjs` passed every lane, including the doctor contract declaration and closure guard tests and the extension typechecks, except the dead-export scan. That scan flags only untouched files (`extensions/telegram/src/sequential-key.ts`, `src/auto-reply/reply/model-selection.ts`). With `OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1` it exits 0.

## Merge Danger

One-way door: `openclaw update` and `doctor --fix` write `anthropic/*` into existing configs. A revert stops new writes but does not remove entries already written; the pre-update backup still has the earlier config. Blast radius: Claude CLI users with no Anthropic credential visible to config repair. Claude IDs without a specific runtime-pinned entry move from a failing API route to Claude Code. A user whose only Anthropic API key lives in the auth store, with no config auth profile or env var, and who sets a Claude CLI-pinned default model, would also see unpinned Claude IDs move to Claude Code. That is the routing a fresh Claude CLI sign-in now produces.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…e CLI sign-in unless sign-in seeded them (openclaw#167963)

## What Problem This Solves

Fixes: after Claude CLI sign-in (`openclaw models auth login --provider anthropic --method cli`), any `anthropic/<id>` that sign-in did not seed fails with `No API key found for provider "anthropic" … missing-provider-auth`. This affects Claude models published after sign-in and IDs typed with `--model`, `/model` or `models set`, such as `anthropic/claude-haiku-4-5`.

## User Impact

User impact: Claude-CLI-only users can type or pick any Claude model and it runs through Claude Code. The model picker still lists only models the Claude CLI catalog serves, so `claude-mythos-5` (direct API only) stays hidden. Users with an Anthropic API key and no Claude CLI sign-in keep the API route. Exact model entries that name another runtime still win. A session pinned to an Anthropic API-key account keeps that account's models, including `claude-mythos-5`, in its picker.

Existing installs that signed in on an affected build get the new routing only after they rerun `openclaw models auth login --provider anthropic --method cli`. This PR adds no Doctor migration.

User-authored `provider/*` wildcards for other CLI backends behave exactly as on `main`. For example, `google/*` → `google-gemini-cli` keeps the same picker rows, and its typed IDs run as before. The picker gate is keyed on the `anthropic/*` → `claude-cli` entry that sign-in writes.

## Why This Change Was Made

Since openclaw#129052, Claude CLI sign-in persists no OpenClaw auth profile. At run time, `resolveCliRuntimeExecutionProvider` (src/agents/model-runtime-aliases.ts) found no runtime policy for unseeded IDs and no `claude-cli` profile it could alias. The turn then fell to the embedded Anthropic API path. An instrumented isolated Gateway on 35a9f60 showed `policy=undefined … viaAuthProfile=undefined` and then `useCliExecution=false`.

- Sign-in (`extensions/anthropic/cli-migration.ts`) now also writes the existing, documented provider wildcard `agents.defaults.models["anthropic/*"] = { agentRuntime: { id: "claude-cli" } }`. It does not overwrite a wildcard that already names another runtime.
- Catalog decisions (`src/agents/model-catalog-cli-wildcard.ts`, used by `model-catalog-decisions.ts`) mark a row unavailable, with no "sign in" reason, when all of these hold: native Claude CLI credentials supplied the availability (`evidence: "runtime"`), the row reaches `claude-cli` only through that sign-in wildcard, the Claude CLI catalog does not list it (bundled manifest plus published catalog), and it is not a configured row. Availability from a selected or pinned API account is never narrowed. Run-time routing is unchanged, so typed IDs still run.

Production change: 3 lines in cli-migration.ts, 15 net lines in model-catalog-decisions.ts and a new 58-line module (about 45 code lines). No config keys, schema or SDK surface change.

Provenance (f81245d, openclaw#166037): prepared catalog decisions keep saved account, model and runtime choices and their provenance. `createCliRuntimeModelAuthEvaluator` returns a pinned non-native account's own provider-auth result, and `evaluateNative` keeps host results for selected accounts. The wildcard gate now only narrows availability that came from native Claude CLI credentials, so a saved account choice keeps the models that account can use.

## Evidence

Real proofs used the machine's existing native `claude` login, OpenClaw's real sign-in flow, isolated profiles and a loopback Gateway:

- Before, on `main` 35a9f60: `models set anthropic/claude-haiku-4-5` plus one turn failed with `missing-provider-auth`, and the instrumentation showed no CLI route.
- After, on b35cc8e: the picker lists `available` rows that exactly match the 11 Claude CLI catalog IDs. `claude-mythos-5` and `claude-haiku-4-5` are not listed.
- After: a turn typed with `--model anthropic/claude-haiku-4-5` returned `OK` with `runner=cli` and `winnerProvider=claude-cli`.
- After: `models set anthropic/claude-haiku-4-5` plus a turn returned `OK` through `claude-cli`.
- API-key control: on a profile with `paste-api-key` (key piped on stdin) and no Claude CLI sign-in, an `anthropic/claude-haiku-4-5` turn returned `OK` with `runner=embedded` and `winnerProvider=anthropic`. Mythos stays listed for API users, as on `main`.
- Regressions:
  - `extensions/anthropic/cli-migration.test.ts`, including the registered non-interactive sign-in entry: 4 failures without the fix, 40/40 pass with it.
  - `src/agents/model-catalog-decisions.test.ts`: the Claude CLI wildcard test fails without the gate (`expected true to be false`). With the gate, it covers a listed row, an API-only row (unavailable, no reason), an exact pinned row, a configured typed row, an exact override to `openclaw`, and an unchanged `google/*` → `google-gemini-cli` row even when that backend lists its own rows.
  - Same test, selected-account case (added on 41f26e5): with the wildcard and a session pinned to an Anthropic API-key profile, `claude-mythos-5` is available with `selectedProfileId: "anthropic:work"` in both `evaluateEntry` and `evaluateNative`. With only native Claude CLI credentials it stays unavailable. On 651801e this fails (`expected { availability: false … } to match object { availability: true … }`). With the fix, 24/24 pass in the file, and `model-auth-availability.test.ts` plus `cli-migration.test.ts` pass.

- New-model simulation on 651801e, in a throwaway worktree with `claude-fable-5` removed from local knowledge: both bundled manifest rows (`anthropic`, `claude-cli`), the `fable-5` alias, the model-catalog-core alias and the Claude CLI context alias. `models.catalogRefresh.url` pointed at a loopback copy of `catalog.openclaw.ai/models/v2/catalog.json`, served at first without `anthropic/claude-fable-5` and `claude-cli/claude-fable-5`.
  - Before: `models.list {view:"configured", refresh:true}` (the Control UI view) returned 10 Claude rows and no Fable 5 row.
  - I added both rows back only in the served copy, with a newer `generatedAt`, then ran `openclaw models refresh` and `models.list {refresh:true}`. The Gateway PID did not change. The first response was unchanged because adoption starts after that response. The next read listed `claude-cli/claude-fable-5` as available, but not `anthropic/claude-fable-5`. A Gateway restart gave the same rows, so the refresh lifecycle is not the cause.
  - Turns: `--model anthropic/claude-fable-5` returned `OK` on the same Gateway PID with `runner=cli`, `winnerProvider=claude-cli` and `winnerModel=claude-fable-5`. `--model claude-cli/claude-fable-5`, the row the picker shows, also returned `OK` through `claude-cli`.
- Gates on 41f26e5: `node scripts/check-changed.mjs` exited 0. It ran the tsgo lanes, oxlint on core and the changed extension files, the full dead-export scan, format checks, ratchets and the import-cycle check. `pnpm exec oxlint --type-aware` on the changed files exited 0.

Upgrade cell (published v2026.9.9 → this PR, disposable Docker container from the `scripts/e2e/Dockerfile` `bare` stage, candidate packed with `scripts/package-openclaw-for-docker.mjs` from 41f26e5, build `2026.9.9-41f26e5206fc`). `api.anthropic.com` resolved to loopback in the container, so the fake key never left it. npm `latest` is still 2026.9.9.
- Existing state was written by the published CLI. It had a Claude CLI-style `agents.defaults.models` with three `anthropic/*` IDs on `claude-cli` and no wildcard, primary `anthropic/claude-opus-5-5`, and an `anthropic:work` API-key profile from `paste-api-key` with a fake key. Through the v2026.9.9 Gateway, `sessions.create` and then `sessions.patch {model:"anthropic/claude-sonnet-5@anthropic:work"}` saved this session selection: `providerOverride=anthropic, modelOverride=claude-sonnet-5, authProfileOverride=anthropic:work (user), agentRuntimeOverride=claude-cli`.
- `openclaw update --tag file:<tgz> --no-restart --yes --json` exited 0 with `status: ok` and all steps at 0. The CLI now reports `OpenClaw 2026.9.9 (41f26e5)`. The updater's doctor, `openclaw doctor --non-interactive` and `config validate` passed (`valid: true`, no warnings). Doctor warnings matched the baseline: a plaintext gateway token in the fixture, loopback bind and no service manager. The saved session selection and `agents.defaults.models` read back identical to the pre-update values.
- Claude CLI sign-in again, with the real `openclaw models auth login --provider anthropic --method cli --set-default` under a pty. It needs a TTY. Without a `claude` binary it stops with `Claude CLI is not authenticated on this host`. With a stub `claude` on `PATH` that only answers `auth status --json` with `{"loggedIn":true,"authMethod":"claude.ai"}` and `--version`, and never runs a model, it exited 0. That was the only stubbed part; the sign-in, config write and Gateway are the shipped code. After the first sign-in, `"anthropic/*": {agentRuntime:{id:"claude-cli"}}` was present once. A second sign-in left it present once. The three existing entries and the primary were unchanged, the session selection was identical after each sign-in, and `config validate` and doctor passed.
- Candidate Gateway with the wildcard present: `models.list {sessionKey, view:"all", provider:"anthropic"}` for the session pinned to `anthropic:work` listed `claude-mythos-5` as `available: true`. `models.list {agentId:"main"}`, with no selected account, listed it as `available: false`, which is the accepted Claude CLI-first behavior.
- Not covered: no real Claude Code turn ran in the cell. Real turns are in the evidence above. The update's package swap took 23 min on a loaded host; an earlier v2026.9.9 cell on the same host took 7–11 min for the whole update. No Telegram Test Server run.

Gap: a Claude model that the published catalog adds later appears in the picker without a restart, but only as `claude-cli/<id>`, not `anthropic/<id>`. `anthropic` is a `refreshable` catalog provider, so its published rows appear only when live `/v1/models` discovery returns them, and that discovery needs an API key. The `src/agents/model-catalog.ts` guard says "Only live registry or refreshed rows may publish those provider models". `claude-cli` is `static`, so its published row appears. The sign-in wildcard gate only marks existing `anthropic` rows unavailable and never adds rows, so the `claude-cli` row has no `anthropic` twin to fold into. Both refs run through Claude Code. Showing `anthropic/<id>` would need a separate change to the refreshable-provider guard in `model-catalog.ts` or to the CLI twin collapse in `model-runtime-aliases.ts`.

## Merge danger

Medium-low. The run-time change is config written only by Claude CLI sign-in. The picker change sits in shared catalog decisions, but it applies only when an agent's `anthropic/*` entry names `claude-cli` and the row is neither configured nor listed by the Claude CLI catalog.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…rlier Claude CLI sign-in (openclaw#168074)

Related: openclaw#167963

## What Problem This Solves

Fixes: Claude models that Claude CLI sign-in did not add fail with "No API key found for provider anthropic" for anyone who signed in to Claude CLI on a release since native Claude CLI login (openclaw#129052), because those configs predate the `anthropic/*` runtime entry that openclaw#167963 now writes at sign-in. Sign-in also still added deprecated catalog models such as `claude-opus-4-8` to fresh configs.

## User Impact

User impact: after `openclaw update` (or `openclaw doctor --fix`), an earlier Claude CLI sign-in routes every Claude model through Claude Code, the same as a fresh sign-in. Fresh sign-ins no longer add deprecated catalog models; an existing entry for one, such as `claude-opus-4-8`, is kept.

Configs with an Anthropic credential, an API default model with a Claude CLI fallback, a provider-level Anthropic runtime, or an existing `anthropic/*` entry are left unchanged.

## Why This Change Was Made

The Anthropic plugin now owns a Doctor config repair (`doctorContract.configRepair`). It adds `agents.defaults.models["anthropic/*"] = { agentRuntime: { id: "claude-cli" } }` only when all of these hold:

- the default model is an `anthropic/...` ref whose entry pins `claude-cli` (what sign-in writes);
- no `anthropic/*` entry exists, whatever runtime it names;
- no `models.providers.anthropic.agentRuntime` (the wildcard would outrank it);
- no Anthropic credential is visible to config repair: an `anthropic` auth profile, a provider `apiKey` other than the retired `anthropic:claude-cli` marker, or `ANTHROPIC_API_KEY`/`ANTHROPIC_OAUTH_TOKEN` in the environment or config `env`.

Specific model entries keep winning over the wildcard, so entries that name a runtime are unaffected. Runtime reads only the canonical entry; there is no new compatibility reader. The change is reported as a Doctor change (`openclaw doctor` lists it, `--fix` writes it).

Sign-in seeding filters catalog rows with `status: "deprecated"`. Route probing and the setup picker still see every row.

## Update Behavior

The installed updater cannot be patched, so the repair keys only on config that shipped Claude CLI sign-ins already wrote. During `openclaw update`, the candidate's own Doctor runs twice: once as `doctor --fix` in the candidate rehearsal on a private state snapshot (`candidate-doctor`), then as `doctor --repair --non-interactive` in a fresh process after the package swap (`openclaw doctor`). The second run writes the repair through Doctor's normal backed-up config write (`openclaw.json.bak` ring plus `openclaw.json.pre-update`), so update rollback restores the earlier config. The update result lists the change under the Doctor migration notes. Gateway startup does not apply it to a valid config. After a manual package replacement, run `openclaw doctor --fix`.

## Evidence

- Regression tests fail at the parent commit and pass here:
  - `extensions/anthropic/cli-migration.test.ts`: `registered cli sign-in seeds no deprecated Claude CLI catalog rows` fails at the parent (`expected { …(12) } to not have property "anthropic/claude-opus-4-8"`). Its second case shows an existing `claude-opus-4-8` default and entry survive sign-in. Three existing seeding expectations drop `claude-opus-4-8`.
  - `extensions/anthropic/doctor-contract-api.test.ts`: covers the repair, idempotency, both kinds of existing wildcard, an API default with a Claude CLI fallback, a non-Anthropic default, auth profile, provider API key, config env key, process env key, provider-level runtime, and the retired provider marker. At the parent the module does not exist.
- Published-driver × candidate cells: Docker `bare` image, published `[email protected]` from npm, sign-in through the published `openclaw onboard --non-interactive --auth-choice anthropic-cli` with a stub `claude` that only answers `claude auth status`. Then `openclaw update --tag file:<candidate tgz> --no-restart --yes --json` to a package built by `scripts/package-openclaw-for-docker.mjs` from this head:

  | Cell | Config before update | `update` | `anthropic/*` after | Other model entries | Post-update `doctor` / `config validate` |
  | --- | --- | --- | --- | --- | --- |
  | A | 2026.9.9 sign-in: 11 seeded rows pinned `claude-cli`, default `anthropic/claude-opus-5-5`, no wildcard | `status: ok`, `2026.9.9 (bcfc888)` → `(587456f)`; result notes `Doctor migration: agents.defaults.models["anthropic/*"]: added the claude-cli runtime …` | `{ agentRuntime: { id: "claude-cli" } }` | unchanged (only `anthropic/*` differs); `.bak`, `.bak.1` and `.pre-update` have no wildcard | exit 0, no further Anthropic finding / `Config valid` |
  | B | A plus `"anthropic/*": { agentRuntime: { id: "openclaw" } }` | `status: ok` | still `openclaw` | unchanged | exit 0 / `Config valid` |
  | C | A plus an `anthropic:default` API-key auth profile | `status: ok` | absent | unchanged | exit 0 / `Config valid` |

  Replaying the candidate Doctor on a copy of cell A's pre-update config: `openclaw doctor --non-interactive` lists the `agents.defaults.models["anthropic/*"]` change and leaves the file unchanged. `openclaw doctor --fix --non-interactive` writes `{ agentRuntime: { id: "claude-cli" } }` and rotates `openclaw.json.bak`. The same replays leave cells B and C unchanged.
- `pnpm exec oxlint --type-aware` on the changed files: clean. `node scripts/check-changed.mjs` passed every lane, including the doctor contract declaration and closure guard tests and the extension typechecks, except the dead-export scan. That scan flags only untouched files (`extensions/telegram/src/sequential-key.ts`, `src/auto-reply/reply/model-selection.ts`). With `OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1` it exits 0.

## Merge Danger

One-way door: `openclaw update` and `doctor --fix` write `anthropic/*` into existing configs. A revert stops new writes but does not remove entries already written; the pre-update backup still has the earlier config. Blast radius: Claude CLI users with no Anthropic credential visible to config repair. Claude IDs without a specific runtime-pinned entry move from a failing API route to Claude Code. A user whose only Anthropic API key lives in the auth store, with no config auth profile or env var, and who sets a Claude CLI-pinned default model, would also see unpinned Claude IDs move to Claude Code. That is the routing a fresh Claude CLI sign-in now produces.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: anthropic gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant