-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(hooks): use 1M context limit for Claude Opus 4.6 #1699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Both context-window-monitor and preemptive-compaction hooks now check the modelID for Opus 4.6 and use its actual 1M context limit. Previously all Anthropic models were treated as 200K unless ANTHROPIC_1M_CONTEXT env var was set, causing premature compaction on Opus 4.6 sessions. The env var fallback is preserved for non-Opus-4.6 Anthropic models.
|
All contributors have signed the CLA. Thank you! ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
1 similar comment
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Logic error in preemptive-compaction.ts: isOpus46 check overrides anthropic provider check entirely. If modelID is undefined for non-anthropic provider, it falls through to DEFAULT_ACTUAL_LIMITCorrect
|
🔥 🔥 🔥 |
|
gogogo |
|
It crashed when I told AI to apply the fix, it fixed it by doing this; ● Here are the code blocks for the fix:
export const OPUS_4_6_LIMIT = 1_000_000 export function isOpus46(modelID: string | undefined): boolean {
Remove the local declarations: function isOpus46(modelID: string | undefined): boolean { Add this import at the top with the other imports:
Remove the local declarations: function isOpus46(modelID: string | undefined): boolean { Add this import at the top with the other imports: |
…de Opus 4.6 # Conflicts: # src/hooks/context-window-monitor.ts # src/hooks/preemptive-compaction.ts
Summary
isOpus46()check tocontext-window-monitorandpreemptive-compactionhooks so Claude Opus 4.6 uses its actual 1M context limit instead of the hardcoded 200K defaultANTHROPIC_1M_CONTEXTenv var is preserved as a fallback for other Anthropic modelsProblem
Both hooks hardcode
200_000as the Anthropic context limit, gated behind theANTHROPIC_1M_CONTEXTenv var. This causes premature compaction at 200K for Opus 4.6 sessions, which actually support 1M context. The env var workaround applies a blanket 1M to all Anthropic models, which is incorrect for 200K models like Sonnet 4.5.Solution
Check the
modelIDfor Opus 4.6 patterns (opus-4-6,opus-4.6) and use 1M for that model specifically. All other Anthropic models continue using the existing 200K default (or env var override).Changes
src/hooks/context-window-monitor.ts— addedmodelIDto interface,isOpus46()checksrc/hooks/preemptive-compaction.ts— addedisOpus46()check before provider-based fallbacksrc/hooks/preemptive-compaction.test.ts— updated tests for Opus 4.6 vs non-Opus behaviorTesting
bun run typecheck✅bun test src/hooks/preemptive-compaction.test.ts— 5/5 pass ✅