Skip to content

fix(anthropic): Claude models fail with a missing API key after an earlier Claude CLI sign-in - #168074

Merged
obviyus merged 1 commit into
mainfrom
fix/claude-cli-wildcard-doctor
Oct 10, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/claude-cli-wildcard-doctor

Conversation

@obviyus

@obviyus obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

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.

@clawsweeper

clawsweeper Bot commented Oct 10, 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 extensions: anthropic size: M labels Oct 10, 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. 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. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The 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.

  • Before: Without a wildcard runtime entry or Anthropic credential, the selection falls through to the API and fails with missing-provider-auth.
  • After: Update or Doctor adds anthropic/* → claude-cli, allowing the existing runtime resolver to select Claude Code.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused migration with shipped-entry-point upgrade evidence, meaningful preservation coverage, and no identified correctness blocker.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded shipped update and Doctor invocations exercise the Anthropic repair on published v2026.9.9 configurations: the eligible cell gains the canonical wildcard, explicit-route and API-profile controls remain unchanged, reporting does not write, and fixing rotates backups; these observations prove the migration rather than a live Claude completion.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Earlier Claude CLI users encounter a missing Anthropic API-key error when selecting models their sign-in did not seed.
Reason: The earlier merged repair explicitly delegates this migration and deprecated-model cleanup, and the implementation uses established routing and Doctor contracts.

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
Reviewed head: 587456f24c9c47908a416994254c97a90c6fc8c7

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Native Claude authentication and earlier sign-in routing keeps the original intent (750a64e: Claude CLI owns login and token refresh; OpenClaw must not copy its native credentials.)
  • Deprecated sign-in seeds changes intended behavior with a stated reason (0a9b08c: The plugin manifest became the authoritative model catalog; this PR explains why deprecated rows remain discoverable but should no longer be automatically seeded.)
  • Older-model route probing keeps the original intent (866012f: Probe configured older models so changing the default does not remove session creation or substitute an unrouted model.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main migration remains absent: Fetched main declares an empty Anthropic doctorContract; the merged sign-in fix writes the wildcard only during sign-in and explicitly leaves migration of existing configurations to follow-up work. (extensions/anthropic/openclaw.plugin.json:4, 1f307d61d0f7)
  • Introduced repair and preservation rules: The pinned introduction diff adds the existing Doctor contract and a narrowly eligible wildcard repair, preserving existing wildcard entries, provider-level runtimes, visible credentials, model entries, and other configuration. (extensions/anthropic/doctor-contract-api.ts:35, 587456f24c9c)
  • Recorded direction and verified ownership: 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 Claude CLI-first wildcard routing and explicitly assigns the Doctor migration and deprecated-model cleanup to follow-up work. The permission endpoint verifies obviyus has the maintain role, despite REST author_association reporting CONTRIBUTOR.
  • Published-release upgrade and Doctor evidence: The complete inspected body records published v2026.9.9 updating to head 587456f: the eligible configuration gains only the wildcard, existing API wildcard and API-profile controls remain unchanged, backups retain the earlier configuration, and Doctor/config validation pass. Separate shipped Doctor invocations distinguish reporting from persistence. Only native auth-status detection is stubbed; no Claude model turn is claimed for these cells. Captured sourceRevision: 47c036fec26d67776e6bb308d03369cdd20a8afef269415bfedc61772d21bf7d. (587456f24c9c)
  • Existing routing precedence: Runtime policy resolution checks exact agent/model policies before the provider wildcard, and checks provider-level runtime afterward; the repair therefore preserves exact runtime choices and declines configurations whose provider policy would otherwise be displaced. (src/agents/model-runtime-policy.ts:249, 587456f24c9c)
  • Historical route-detection contract retained: fix(anthropic): detect Claude CLI routes pinned to non-default models #113424 introduced probing older configured models so default-model changes do not remove session creation. This patch filters only sign-in seeds and keeps every catalog row in route probes and setup choices. (extensions/anthropic/cli-constants.ts:85, 866012f5be19)

Likely related people:

  • Peter Steinberger: Raw commit 0a9b08c adds extensions/anthropic/cli-constants.ts:97 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0a9b08c13ac0; files: extensions/anthropic/cli-constants.ts)
  • Jason (Json): Raw commit 866012f adds extensions/anthropic/cli-constants.ts:31 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 866012f5be19; files: extensions/anthropic/cli-constants.ts)

PR surface

Source +92, Tests +189, Docs +16. Total +297 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 99 7 +92
Tests 2 195 6 +189
Docs 2 16 0 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 310 13 +297

Review metrics

Metric Value Why it matters
Persisted routing repair One existing provider-wide routing entry added conditionally Doctor changes persisted execution routing without introducing a new setting or schema.
Production versus tests Production +99/-7; tests +195/-6 lines Growth supplies the plugin-owned repair and preservation coverage; route probing continues using the existing catalog owner.

Labels

Label changes:

  • add P2: The failure affects earlier Claude CLI configurations selecting unseeded models and has a bounded provider-specific migration.
  • add merge-risk: 🚨 compatibility: The repair persists a new wildcard in existing configurations; published-release upgrade evidence verifies preservation and backups.
  • add merge-risk: 🚨 auth-provider: Unpinned Anthropic IDs move to native Claude execution, including the disclosed auth-store-only credential case; the recorded direction accepts CLI-first routing while exact policies remain authoritative.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • 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.

Label justifications:

  • P2: The failure affects earlier Claude CLI configurations selecting unseeded models and has a bounded provider-specific migration.
  • merge-risk: 🚨 compatibility: The repair persists a new wildcard in existing configurations; published-release upgrade evidence verifies preservation and backups.
  • merge-risk: 🚨 auth-provider: Unpinned Anthropic IDs move to native Claude execution, including the disclosed auth-store-only credential case; the recorded direction accepts CLI-first routing while exact policies remain authoritative.
  • 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.

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.

Reviewed October 9, 2026, 9:35 PM ET / October 10, 2026, 01:35 UTC.

@obviyus
obviyus merged commit ac45dc4 into main Oct 10, 2026
115 of 117 checks passed
@obviyus
obviyus deleted the fix/claude-cli-wildcard-doctor branch October 10, 2026 01:40
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in ac45dc4. Doctor (and the repair openclaw update runs) now adds the anthropic/* → claude-cli rule for existing Claude CLI sign-ins that lack it, so Claude models not seeded at sign-in stop failing with a missing API key; existing anthropic/* rules and API-key setups are left alone, and new sign-ins no longer seed deprecated Claude CLI models. Proof: regressions that failed on main and three published 2026.9.9 → candidate upgrade cells.

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

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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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