diff --git a/tokens/tokens.go b/tokens/tokens.go index af64e78..6dd7904 100644 --- a/tokens/tokens.go +++ b/tokens/tokens.go @@ -110,8 +110,20 @@ func windowByModelFamily(modelID string) int { leaf = leaf[i+1:] } switch { + case strings.Contains(id, "claude-fable"), + strings.Contains(id, "claude-mythos"), + strings.Contains(id, "claude-opus-4-6"), + strings.Contains(id, "claude-opus-4-7"), + strings.Contains(id, "claude-opus-4-8"), + strings.Contains(id, "claude-opus-4-9"), + strings.Contains(id, "claude-sonnet-4-6"): + // The 1M-window Claude generation: Fable 5, Mythos 5, + // Opus 4.6+, Sonnet 4.6. Matching the 200k blanket rule below + // would make preventive compaction fire ~5x too early. + return 1000000 case strings.Contains(id, "claude"): - // All current Claude chat models share a 200k window. + // Older Claude chat models (3.x through the 4.5 era, Haiku 4.5) + // share a 200k window. return 200000 case strings.HasPrefix(leaf, "gpt-4o"), strings.HasPrefix(leaf, "gpt-4-turbo"): return 128000 diff --git a/tokens/tokens_test.go b/tokens/tokens_test.go index 548075e..41cb69a 100644 --- a/tokens/tokens_test.go +++ b/tokens/tokens_test.go @@ -84,7 +84,7 @@ func TestContextWindowProxyProviderDetectedByModelFamily(t *testing.T) { model string want int }{ - {"platformai/claude-sonnet-4-6-asia-southeast1", 200000}, + {"platformai/claude-sonnet-4-6-asia-southeast1", 1000000}, {"openrouter/anthropic/claude-3-opus", 200000}, {"bedrock/anthropic.claude-3-haiku", 200000}, {"vertex/gemini-1.5-pro-001", 2000000}, @@ -135,3 +135,32 @@ func TestCalibratorIgnoresZeroOrNegative(t *testing.T) { c.Update(-5, 100) assert.Equal(t, 100, c.Adjust(100), "bad samples must be ignored") } + +// TestContextWindow1MClaudeFamily pins the 1M-window Claude generation: +// Fable 5, Mythos 5, Opus 4.6+, and Sonnet 4.6 all ship a 1M context +// window. The old blanket claude→200k rule made compaction fire ~5x too +// early on these models. Older Claude (3.x, 4.0-4.5 era) stays 200k. +func TestContextWindow1MClaudeFamily(t *testing.T) { + tests := []struct { + model string + want int + }{ + {"anthropic/claude-fable-5", 1000000}, + {"platformai/claude-fable-5-global", 1000000}, + {"anthropic/claude-mythos-5", 1000000}, + {"anthropic/claude-opus-4-6", 1000000}, + {"anthropic/claude-opus-4-7", 1000000}, + {"anthropic/claude-opus-4-8", 1000000}, + {"platformai/claude-sonnet-4-6-asia-southeast1", 1000000}, + // Older generations keep 200k. + {"anthropic/claude-haiku-4-5-20251001", 200000}, + {"anthropic/claude-sonnet-4-5", 200000}, + {"anthropic/claude-3-5-sonnet-20241022", 200000}, + {"anthropic/claude-opus-4-0-20250514", 200000}, + } + for _, tc := range tests { + t.Run(tc.model, func(t *testing.T) { + assert.Equal(t, tc.want, ContextWindow(tc.model)) + }) + } +}