Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Correct Claude context windows in the utilization table

Claude07c1f8627738
diff --git a/cli/beacon/internal/tokens/contextwindow.go b/cli/beacon/internal/tokens/contextwindow.go
index 8392db89..787efa50 100644
--- a/cli/beacon/internal/tokens/contextwindow.go
+++ b/cli/beacon/internal/tokens/contextwindow.go
@@ -5,11 +5,38 @@ import "strings"
// contextWindows maps normalized model-name prefixes to context window sizes
// in tokens. Longest prefix wins. The table is a best-effort static snapshot;
// unknown models simply report raw input tokens without a utilization ratio.
+//
+// Unknown is deliberately preferred to guessed. A wrong window does not read as
+// missing data -- it reads as a confident ratio, and a model listed at a fifth
+// of its real window reports every ordinary call as running near the limit.
+// That is why entries are added only for models whose window is known from the
+// vendor rather than inferred from a family name, and why the generic "claude"
+// fallback below stays at the conservative 200000 rather than being raised to
+// match the current generation.
var contextWindows = []struct {
prefix string
tokens int64
}{
+ // Fallback for Claude models not named below -- the 3.x family, Sonnet 4.5,
+ // Opus 4.5 and anything older, all of which are 200K.
{"claude", 200000},
+ // The current generation is 1M, with Haiku 4.5 the exception at 200K. Before
+ // these entries existed every one of these models matched the generic
+ // "claude" prefix above and was reported against a 200K window, so a routine
+ // 150K-token call showed as 75% utilization and a 200K call tripped the
+ // near-limit counter -- on a model with 800K still to spare.
+ {"claude-opus-4-6", 1000000},
+ {"claude-opus-4-7", 1000000},
+ {"claude-opus-4-8", 1000000},
+ {"claude-opus-5", 1000000},
+ {"claude-sonnet-4-6", 1000000},
+ {"claude-sonnet-5", 1000000},
+ {"claude-fable-5", 1000000},
+ {"claude-mythos-5", 1000000},
+ // Explicit rather than left to the "claude" fallback: it lands on the same
+ // 200000, but naming it keeps a later edit to the fallback from silently
+ // moving Haiku with it.
+ {"claude-haiku-4-5", 200000},
{"gpt-5", 400000},
{"gpt-4.1", 1047576},
{"gpt-4o", 128000},
diff --git a/cli/beacon/internal/tokens/contextwindow_test.go b/cli/beacon/internal/tokens/contextwindow_test.go
index 5a6dba9b..fab3820b 100644
--- a/cli/beacon/internal/tokens/contextwindow_test.go
+++ b/cli/beacon/internal/tokens/contextwindow_test.go
@@ -10,6 +10,17 @@ func TestContextWindowMatchesModelVariants(t *testing.T) {
}{
{"claude-sonnet-4-5", 200000, true},
{"anthropic/claude-3-5-sonnet-20241022", 200000, true},
+ // The current generation is 1M. Longest prefix wins, so these must beat
+ // the generic "claude" fallback rather than inheriting its 200K.
+ {"claude-opus-5", 1000000, true},
+ {"claude-opus-4-8", 1000000, true},
+ {"claude-opus-4-6", 1000000, true},
+ {"claude-sonnet-5", 1000000, true},
+ {"claude-sonnet-4-6-20260101", 1000000, true},
+ {"claude-fable-5-1", 1000000, true},
+ {"anthropic/claude-opus-5", 1000000, true},
+ // Haiku 4.5 is the current-generation exception at 200K.
+ {"claude-haiku-4-5", 200000, true},
{"gpt-4o-2024-08-06", 128000, true},
{"gpt-4o-mini", 128000, true},
{"gpt-4.1-mini", 1047576, true},
@@ -32,3 +43,35 @@ func TestContextWindowMatchesModelVariants(t *testing.T) {
})
}
}
+
+// Sonnet 4.5 (200K) and Sonnet 5 (1M) differ by one character in a position that a
+// careless prefix rule gets wrong, and getting it wrong is invisible: the ratio still
+// renders, just against the wrong denominator.
+func TestContextWindowDoesNotConfuseAdjacentClaudeVersions(t *testing.T) {
+ for _, tc := range []struct {
+ model string
+ want int64
+ }{
+ {"claude-sonnet-4-5", 200000},
+ {"claude-sonnet-5", 1000000},
+ {"claude-opus-4-5", 200000},
+ {"claude-opus-4-6", 1000000},
+ {"claude-haiku-4-5", 200000},
+ } {
+ got, known := ContextWindow(tc.model)
+ if !known || got != tc.want {
+ t.Errorf("ContextWindow(%q) = %d/%v, want %d/true", tc.model, got, known, tc.want)
+ }
+ }
+}
+
+// An unknown model must stay unknown rather than being given a plausible-looking window.
+// A wrong window does not read as missing data; it reads as a confident ratio, and the
+// near-limit counter fires on it.
+func TestContextWindowLeavesUnknownModelsUnknown(t *testing.T) {
+ for _, model := range []string{"llama-4-405b", "some-vendor/frontier-x", "qwen3-coder-plus"} {
+ if got, known := ContextWindow(model); known {
+ t.Errorf("ContextWindow(%q) = %d/true, want unknown", model, got)
+ }
+ }
+}