Skip to content

Build the Claude Code model picker from Claude Code's own model list - #4084

Merged
SawyerHood merged 1 commit into
mainfrom
bb/yo-what-up-right-now-i-don-t-know-what-s-happeni-thr_yvuhy6ap7b
Sep 22, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/yo-what-up-right-now-i-don-t-know-what-s-happeni-thr_yvuhy6ap7b

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The Claude Code model picker was a hardcoded catalog (model-catalog-data.ts) with Claude Code's reported models appended after it. When Claude Code 2.1.280 made claude-opus-5-5[1m] its default, BB did pick it up, but it landed sixth in the list under Claude Code's alias label, "Opus (1M context)". The stale hardcoded "Opus 5 (1M)" stayed at the top. Every model release needed a manual catalog edit to look right (#2833 was the last one, for Fable 5.1).

What changed

  • plugins/provider-claude-code/src/model-list.ts: the picker is built only from Claude Code's initializationResult().models, in Claude Code's order, one entry per resolved model id.
    • Names: display names are derived from the model id (claude-opus-5-5[1m] → "Opus 5.5 (1M)", claude-haiku-4-5-20251001 → "Haiku 4.5"). Ids that don't match the claude-<family>-<major>[-<minor>] pattern keep Claude Code's own label.
    • Aliases: Claude Code's aliases (opus[1m], sonnet, …) become selected-only entries, labeled " alias".
    • Default: Claude Code's reported default model, falling back to the first entry.
    • Reasoning efforts: taken from supportedEffortLevels, with xhigh also offering ultracode, as before.
  • Deleted model-catalog-data.ts, model-catalog.ts and model-catalog.test.ts, along with the legacy selected-only catalog.
  • plugins/provider-claude-code/server.ts: dropped models.fallback. BB already stores the last good catalog per host and serves it when a later probe fails, so the static list only showed up when a host's very first probe failed.
  • plugins/provider-claude-code/src/bridge/model-list.ts: an empty model report now throws, so it counts as a failed probe instead of overwriting the stored catalog with nothing.
  • Server tests that pinned the Claude fallback catalog now check the generic models.fallback path with a test provider, and expect no fallback models for Claude Code.

No wire change: the model-list shape is unchanged, so HOST_DAEMON_PROTOCOL_VERSION stays put. No CLI, guide or plugin API change.

Behavior changes to be aware of:

  • Older models leave the picker. Claude Code only reports its current models, so Opus 5, 4.8 and 4.7 and old aliases like opus, best and fable are no longer listed. Threads and project defaults on those models recover to the default in the composer, and the next UI send switches them.
  • Updates to those models are rejected. bb thread update --model <dropped id> returns 400, and workflow literal selections naming a dropped model fail validation. bb thread spawn --model <id> still works because spawn doesn't check the catalog.
  • Default effort is now "high". It used to be "medium" for Opus 4.7 and Sonnet 5, and it only applies when no effort preference is saved.
  • First probe failure leaves the picker empty. If a host's very first probe fails, the picker shows the load error instead of a static list.
  • Context-window hints stay hardcoded. LARGE_CLAUDE_CONTEXT_MODELS in sdk-extraction.ts is untouched, because Claude Code's model report carries no context window.

How you verified

  • pnpm exec turbo run test typecheck --filter=bb-plugin-provider-claude-code: 363 tests pass. New model-list.test.ts cases cover Claude Code's order, derived names, aliases as selected-only entries, effort mapping, and following a changed default. bridge.test.ts covers the empty report being treated as a failure.
  • pnpm exec turbo run test typecheck --filter=@bb/server: all passing except test/public/machine-environment.test.ts, which hit its 5 s timeout under full-suite load and passes when run alone.
  • Fed the real Claude Code 2.1.280 probe through the bridge. On a dev app, GET /api/v1/system/execution-options?providerId=claude-code returns exactly Opus 5.5 (1M) (default), Fable 5.1, Sonnet 5 and Haiku 4.5, with the four aliases as selected-only entries. The model picker in the dev app UI shows the same list.

AGENT GENERATED

🤖 Generated with Claude Code

The picker was a hardcoded catalog with discovered models appended below
it, so a new Claude Code default (Opus 5.5) appeared sixth under a generic
alias label while the stale hardcoded Opus 5 stayed on top. The list now
comes only from Claude Code's initialization report, in its order, with
display names derived from the resolved model id and aliases offered as
selected-only entries. The curated catalog, the selected-only legacy
catalog, and the server-side fallback list are removed; an empty report
counts as a discovery failure so the last stored catalog keeps serving.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@SawyerHood
SawyerHood merged commit db77f2c into main Sep 22, 2026
16 checks passed
@SawyerHood
SawyerHood deleted the bb/yo-what-up-right-now-i-don-t-know-what-s-happeni-thr_yvuhy6ap7b branch September 22, 2026 18:42
andrewkchan added a commit that referenced this pull request Sep 22, 2026
Every automated check of bb's Claude Code model catalog replaces the Agent
SDK's `query()` with a mock returning a fixture the repo authored itself, so
an upstream CLI release that breaks the probe passes CI silently. The picker
shipped broken for a week that way: `models.fallback` served a stale catalog
until #4084 removed it, at which point the failure surfaced to users as
"Could not load models for Claude Code."

A test that catches this already exists — `integration.provider-basic.test.ts`
"lists models" — but `test:integration` is referenced nowhere in `.github/`,
so it only ever runs when someone remembers to run it locally against an
authenticated CLI.

Add a CI job that installs the latest Claude Code CLI, authenticates it from
a repository secret, and runs that probe on pushes and same-repo pull
requests. The CLI reads CLAUDE_CODE_OAUTH_TOKEN, which `claude setup-token`
mints as a long-lived credential; the credentials file written by `/login`
holds an ~8-hour access token and would start rotting immediately in an
ephemeral runner.

Two layers stripped that variable before the CLI could see it:

- The bridge environment is an allowlist, and provider-claude-code declared
  only BB_CLAUDE_CODE_EXECUTABLE. This also meant a bb user authenticating
  Claude Code by token could not drive the provider at all, on any machine.
- Turbo strips undeclared variables, so the live-CLI tasks dropped it before
  vitest started. BB_CLAUDE_CODE_EXECUTABLE was silently inert there too.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
andrewkchan added a commit that referenced this pull request Sep 22, 2026
Every automated check of bb's Claude Code model catalog replaces the Agent
SDK's `query()` with a mock returning a fixture the repo authored itself, so
an upstream CLI release that breaks the probe passes CI silently. The picker
shipped broken for a week that way: `models.fallback` served a stale catalog
until #4084 removed it, at which point the failure surfaced to users as
"Could not load models for Claude Code."

A test that catches this already exists — `integration.provider-basic.test.ts`
"lists models" — but `test:integration` is referenced nowhere in `.github/`,
so it only ever runs when someone remembers to run it locally against an
authenticated CLI.

Add a CI job that installs the Claude Code CLI, authenticates it from a
repository secret, and runs that probe on pushes and same-repo pull requests.

The job installs the native build through claude.ai/install.sh rather than the
npm package. bb resolves `claude` from PATH and then `~/.local/bin`, so the
native build is what most users run, and the two are not interchangeable
despite sharing a version number: 2.1.280 native exits silently on
`--setting-sources=` where 2.1.280 from npm answers normally. An npm-only job
reports green through that regression, which is how this job first passed.

The CLI reads CLAUDE_CODE_OAUTH_TOKEN, which `claude setup-token` mints as a
long-lived credential; the credentials file written by `/login` holds an
~8-hour access token and would start rotting immediately in an ephemeral
runner. Two layers stripped that variable before the CLI could see it:

- The bridge environment is an allowlist, and provider-claude-code declared
  only BB_CLAUDE_CODE_EXECUTABLE. This also meant a bb user authenticating
  Claude Code by token could not drive the provider at all, on any machine.
- Turbo strips undeclared variables, so the live-CLI tasks dropped it before
  vitest started. BB_CLAUDE_CODE_EXECUTABLE was silently inert there too.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
andrewkchan added a commit that referenced this pull request Sep 23, 2026
Every automated check of bb's Claude Code model catalog replaces the Agent
SDK's `query()` with a mock returning a fixture the repo authored itself, so
an upstream CLI release that breaks the probe passes CI silently. The picker
shipped broken for a week that way: `models.fallback` served a stale catalog
until #4084 removed it, at which point the failure surfaced to users as
"Could not load models for Claude Code."

A test that catches a broken probe already exists —
`integration.provider-basic.test.ts` "lists models" — but `test:integration`
is referenced nowhere in `.github/`, so it only ever runs when someone
remembers to run it locally against an authenticated CLI.

Add a CI job that installs the Claude Code CLI, authenticates it from a
repository secret, and runs that probe on pushes and same-repo pull requests.
It installs the native build through claude.ai/install.sh rather than the npm
package, because bb resolves `claude` from PATH and then `~/.local/bin`, so
the native build is the binary most users run.

The job is expected to pass, including on this commit. It is general coverage
for the probe, not a reproduction of the defect that motivated it: that one is
specific to the macOS native build, which exits when the settings set it loads
is empty. Linux does not exhibit it, so reproducing it needs a macOS leg.

The CLI reads CLAUDE_CODE_OAUTH_TOKEN, which `claude setup-token` mints as a
long-lived credential; the credentials file written by `/login` holds an
~8-hour access token and would start rotting immediately in an ephemeral
runner. Two layers stripped that variable before the CLI could see it:

- The bridge environment is an allowlist, and provider-claude-code declared
  only BB_CLAUDE_CODE_EXECUTABLE. This also meant a bb user authenticating
  Claude Code by token could not drive the provider at all, on any machine.
- Turbo strips undeclared variables, so the live-CLI tasks dropped it before
  vitest started. BB_CLAUDE_CODE_EXECUTABLE was silently inert there too.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
andrewkchan added a commit that referenced this pull request Sep 23, 2026
Every automated check of bb's Claude Code model catalog mocks the Agent SDK's
`query()`, so nothing in CI ever spawned a real `claude`. The test that would
catch a broken probe already exists — `integration.provider-basic.test.ts`
"lists models" — but `test:integration` is referenced nowhere in `.github/`.

The picker broke exactly that way: the probe's `settingSources: []` made the
CLI exit with code 0 and no output, reported as "Query closed before response
received". `models.fallback` hid it until #4084 removed it.

- Add a `provider-model-listing` CI job running the probe against a real,
  unpinned CLI. It passes today, and would have passed on the unfixed probe:
  the defect is specific to the macOS native build, which exits when the
  settings set it loads is empty, so a Linux runner cannot reproduce it.
- Match the probe's setting sources to what `sdk-session.ts` already passes
  for real sessions, which fixes the picker.
- Let CLAUDE_CODE_OAUTH_TOKEN reach the CLI. The bridge env allowlist declared
  only BB_CLAUDE_CODE_EXECUTABLE, and Turbo strips undeclared variables, so
  token auth never worked for any bb user and the documented executable
  override was inert under `test:integration`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
andrewkchan added a commit that referenced this pull request Sep 23, 2026
## Human comments

I am running into a bug on the Claude Code model picker where the models
are not listing properly. It looks like we have some automated tests
that download claude code and then run the bb probe against it to get
the list of models to display in the picker, but they simply do not run
in CI.

This wires them up in CI. Note some changes are needed for secrets:
1. Passing the env var for `CLAUDE_CODE_OAUTH_TOKEN` through to the
bridge process
2. Adding `CLAUDE_CODE_OAUTH_TOKEN` to the github repo secrets

## What was wrong

Every automated check of bb's Claude Code model catalog mocks the Agent
SDK's `query()`, so nothing in CI has ever spawned a real `claude`. A
test that would catch a broken probe already exists —
`integration.provider-basic.test.ts` "lists models" — but
`test:integration` is referenced nowhere under `.github/`, so it only
runs when someone remembers to run it locally.

That gap surfaced when the picker started showing "Could not load models
for Claude Code": the probe's `settingSources: []` made the CLI exit
with code 0 and no output, which the SDK reports as `Query closed before
response received`. It had been failing since at least Sep 16, hidden by
`models.fallback` until #4084 removed it.

## What changed

- `.github/workflows/ci.yml`: new `provider-model-listing` job on pushes
and same-repo PRs. Installs the Claude Code CLI, authenticates from a
`CLAUDE_CODE_OAUTH_TOKEN` secret, runs the model-listing probe against a
real binary.
- `plugins/provider-claude-code/src/bridge/model-list.ts`: the probe now
uses `settingSources: ["user", "project", "local"]`, matching what
`sdk-session.ts` already passes for real sessions.
- `plugins/provider-claude-code/server.ts`, `turbo.json`: let
`CLAUDE_CODE_OAUTH_TOKEN` reach the CLI. Two layers stripped it — the
bridge env allowlist declared only `BB_CLAUDE_CODE_EXECUTABLE`, and
Turbo strips undeclared variables. So token auth never worked for any bb
user, not just CI, and the documented `BB_CLAUDE_CODE_EXECUTABLE`
override was inert under `test:integration`.
- `docs/configuration.md`, `claude-code-provider` skill: document both
variables.

Scope is the model-listing tests only, to keep the job fast and free of
real model turns. The CLI version is unpinned (pinning would hide the
breakage this job watches for), and it installs the native build, which
is what bb resolves from `PATH` and `~/.local/bin`.

## Expected state of this job: green

**This job passes, and would have passed on the unfixed probe too.** It
is general regression coverage, not a reproduction of the defect that
motivated it.

That defect is specific to the macOS native build, which exits when the
settings set it loads is empty. On CLI 2.1.280:

```
macOS, native, settingSources: []  -> FAIL  Query closed before response received
macOS, npm build, same config, []  -> OK
Linux CI, native, authenticated,[] -> OK
```

So a Linux runner cannot reproduce it; a macOS leg could, and is the
natural follow-up. A CLI that exits 0 with empty stdout and stderr also
leaves bb nothing to report, which is worth filing upstream separately.

## How you verified

- Probe fix confirmed against the real native CLI: `[]` fails,
`["user","project","local"]` returns 5 models. Verified end to end in a
dev build.
- The CI job runs and passes on Linux with exactly one test selected: `✓
lists models`, `Tests 1 passed | 64 skipped (65)` — the filter is not
silently matching zero tests.
- Env plumbing proved with a shim: both variables reach the spawned
process, while an undeclared control variable is still stripped.
- `turbo run test typecheck --filter=bb-plugin-provider-claude-code`:
passing. `turbo run test --filter=@bb/server`: 295 files passing, with
one unrelated pre-existing failure (`bb-official-generator.test.ts`, a
local git `%cI` format difference) that reproduces with these changes
stashed.

Fixes #

> AGENT GENERATED

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant