fix(core): keep Claude Agent models from falling back to 200k context (#64107)

This commit is contained in:
Dan Smolsky
2026-11-15 13:01:08 -05:00
committed by GitHub
Unverified
parent e3ed63c7de
commit 6c5ef96af4
5 changed files with 17 additions and 11 deletions
@@ -197,7 +197,7 @@ export function registry() {
)
const process = opened.process
// A new process reports its version, login and models, which keeps the model list current without a separate check.
if (starting) yield* input.status.report({ type: "ready", probe: opened.probe })
if (starting) yield* input.status.report({ type: "ready", probe: opened.probe, fromChat: true })
// Apply controls before sending input or releasing parked tool results.
if (process.model !== request.model) {
yield* attempt(() => process.session.setModel(request.model))
@@ -9,7 +9,7 @@ export type State =
| { readonly type: "checking" }
| { readonly type: "missing" }
| { readonly type: "failed"; readonly message: string }
| { readonly type: "ready"; readonly probe: ClaudeProbe.Result }
| { readonly type: "ready"; readonly probe: ClaudeProbe.Result; readonly fromChat?: boolean }
export interface Interface {
readonly state: SubscriptionRef.SubscriptionRef<State>
@@ -63,6 +63,7 @@ export const register = Effect.fn("ClaudeProvider.register")(function* (
})
})
const checked = new Set<string>()
yield* SubscriptionRef.changes(status.state).pipe(
Stream.runForEach((state) =>
Effect.gen(function* () {
@@ -72,6 +73,11 @@ export const register = Effect.fn("ClaudeProvider.register")(function* (
priceSource: priceSource(state.probe.account, baseURL),
models: fromClaude(state.probe.models, current.catalog.models),
}
const unknown = next.models.filter((model) => model.contextWindow === undefined && !checked.has(model.id))
if (state.fromChat && unknown.length > 0) {
for (const model of unknown) checked.add(model.id)
yield* status.refresh().pipe(Effect.forkScoped)
}
if (JSON.stringify(next) === JSON.stringify(current.catalog)) return
current.catalog = next
yield* ctx.storage.set(CATALOG_KEY, current.catalog)
@@ -226,16 +226,15 @@ describe("ClaudeAgentPlugin models", () => {
}),
)
it.live("binds chats to plugin storage, and a chat's startup report keeps saved context sizes", () =>
it.live("binds chats to plugin storage, and checks context sizes for models a chat reports without one", () =>
Effect.gen(function* () {
const store = yield* storage
yield* store.set("models", { models: [{ id: "haiku", name: "Haiku", efforts: [], contextWindow: 123_456 }] })
yield* connect
const claude = FakeClaude.make([
FakeClaude.expectStartup(),
FakeClaude.expectTurn(),
FakeClaude.expectInterrupt(),
])
const claude = FakeClaude.make(
[FakeClaude.expectStartup(), FakeClaude.expectTurn(), FakeClaude.expectInterrupt()],
{ probes: true },
)
const registry = yield* addPlugin(FakeIO.make({ claude }))
const aisdk = yield* AISDK.Service
@@ -258,8 +257,9 @@ describe("ClaudeAgentPlugin models", () => {
expect(TestSessions.text(yield* Effect.promise(() => TestSessions.collect(result.stream)))).toBe("COPPER-OTTER")
expect(yield* store.get("sessions/session-a")).toMatchObject({ claudeSessionID: expect.any(String) })
const models = yield* eventually(claudeModels, (models) => models.length > 1)
expect(find(models, "haiku").limit.context).toBe(123_456)
yield* eventually(claudeModels, (models) =>
models.some((model) => model.id === "sonnet" && model.limit.context === 1_000_000),
)
yield* registry.close()
claude.check()
}),
+1 -1
View File
@@ -122,7 +122,7 @@ Users can configure the `claude-agent` provider and its models in opencode confi
- Why not Claude's own cost: it is a running total for the turn, so it cannot be split per response.
- Claude Code reports usage for one model response several times while it streams, and again as a total for the turn. Adding these up would count the same response several times and make opencode compact too early. We keep the highest count for each response, and use the last response's input as the context size.
- Each model's context size comes from Claude. Without it, opencode's 200k default applies.
- The model list is refreshed whenever Claude reports it: on `/connect`, when the login changes, and each time a new Claude process starts. It is saved, with where the login's prices come from, so opencode can show models and costs at startup without running `claude`.
- The model list is refreshed whenever Claude reports it: on `/connect`, when the login changes, and each time a new Claude process starts. A new process doesn't report context sizes, so a model it lists without a saved size triggers one full check. The list is saved, with where the login's prices come from, so opencode can show models and costs at startup without running `claude`.
### Titles, Summaries and Compaction