Repository navigation
fix(anthropic): Claude models fail with a missing API key after an earlier Claude CLI sign-in - #168074
Conversation
…ic/* runtime entry
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThe PR repairs eligible earlier Claude CLI configurations through Doctor and stops fresh sign-ins from automatically adding deprecated models. Example: A v2026.9.9 Claude CLI user selects anthropic/claude-haiku-4-5, which their earlier sign-in did not seed.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR supplies the still-needed migration for earlier Claude CLI sign-ins, with recorded product approval and published-release upgrade evidence; no actionable patch defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Anthropic plugin supplies a configuration repair to Doctor; Doctor reports and persists canonical routing through its existing backup writer, and agent execution consumes those saved routes. flowchart TD
A[Earlier CLI sign-in config] --> B[Doctor plugin registry]
B --> C[Anthropic eligibility check]
C --> D[Backed-up config writer]
D --> E[Canonical model routing]
E --> F[Runtime policy resolver]
F --> G[Claude Code or Anthropic API]
Technical reviewBest possible solution: Use the plugin-owned Doctor repair and existing backed-up configuration writer to bring eligible earlier sign-ins onto the canonical runtime route. Do we have a high-confidence way to reproduce the issue? Yes: earlier sign-ins lack the wildcard and native login supplies no OpenClaw auth profile, so unseeded IDs have no CLI route; this review inspected source and supplied observations without executing target code. Is this the best way to solve the issue? The repair uses the existing plugin Doctor contract, avoids runtime compatibility readers, and retains exact model policies, visible API credentials, and explicit wildcard choices. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1f307d61d0f7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +92, Tests +189, Docs +16. Total +297 across 7 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 9, 2026, 9:35 PM ET / October 10, 2026, 01:35 UTC. |
|
Landed in ac45dc4. Doctor (and the repair |
…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]>
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 asclaude-opus-4-8to fresh configs.User Impact
User impact: after
openclaw update(oropenclaw 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 asclaude-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 addsagents.defaults.models["anthropic/*"] = { agentRuntime: { id: "claude-cli" } }only when all of these hold:anthropic/...ref whose entry pinsclaude-cli(what sign-in writes);anthropic/*entry exists, whatever runtime it names;models.providers.anthropic.agentRuntime(the wildcard would outrank it);anthropicauth profile, a providerapiKeyother than the retiredanthropic:claude-climarker, orANTHROPIC_API_KEY/ANTHROPIC_OAUTH_TOKENin the environment or configenv.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 doctorlists it,--fixwrites 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 asdoctor --fixin the candidate rehearsal on a private state snapshot (candidate-doctor), then asdoctor --repair --non-interactivein 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.bakring plusopenclaw.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, runopenclaw 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 rowsfails at the parent (expected { …(12) } to not have property "anthropic/claude-opus-4-8"). Its second case shows an existingclaude-opus-4-8default and entry survive sign-in. Three existing seeding expectations dropclaude-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
bareimage, published[email protected]from npm, sign-in through the publishedopenclaw onboard --non-interactive --auth-choice anthropic-cliwith a stubclaudethat only answersclaude auth status. Thenopenclaw update --tag file:<candidate tgz> --no-restart --yes --jsonto a package built byscripts/package-openclaw-for-docker.mjsfrom this head:updateanthropic/*afterdoctor/config validateclaude-cli, defaultanthropic/claude-opus-5-5, no wildcardstatus: ok,2026.9.9 (bcfc888)→(587456f); result notesDoctor migration: agents.defaults.models["anthropic/*"]: added the claude-cli runtime …{ agentRuntime: { id: "claude-cli" } }anthropic/*differs);.bak,.bak.1and.pre-updatehave no wildcardConfig valid"anthropic/*": { agentRuntime: { id: "openclaw" } }status: okopenclawConfig validanthropic:defaultAPI-key auth profilestatus: okConfig validReplaying the candidate Doctor on a copy of cell A's pre-update config:
openclaw doctor --non-interactivelists theagents.defaults.models["anthropic/*"]change and leaves the file unchanged.openclaw doctor --fix --non-interactivewrites{ agentRuntime: { id: "claude-cli" } }and rotatesopenclaw.json.bak. The same replays leave cells B and C unchanged.pnpm exec oxlint --type-awareon the changed files: clean.node scripts/check-changed.mjspassed 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). WithOPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1it exits 0.Merge Danger
One-way door:
openclaw updateanddoctor --fixwriteanthropic/*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.