Skip to content

Conversation

@morphaxl
Copy link

@morphaxl morphaxl commented Feb 9, 2026

Summary

  • Add isOpus46() check to context-window-monitor and preemptive-compaction hooks so Claude Opus 4.6 uses its actual 1M context limit instead of the hardcoded 200K default
  • The ANTHROPIC_1M_CONTEXT env var is preserved as a fallback for other Anthropic models

Problem

Both hooks hardcode 200_000 as the Anthropic context limit, gated behind the ANTHROPIC_1M_CONTEXT env 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 modelID for 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 — added modelID to interface, isOpus46() check
  • src/hooks/preemptive-compaction.ts — added isOpus46() check before provider-based fallback
  • src/hooks/preemptive-compaction.test.ts — updated tests for Opus 4.6 vs non-Opus behavior

Testing

  • bun run typecheck
  • bun test src/hooks/preemptive-compaction.test.ts — 5/5 pass ✅

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.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@morphaxl
Copy link
Author

morphaxl commented Feb 9, 2026

I have read the CLA Document and I hereby sign the CLA

1 similar comment
@morphaxl
Copy link
Author

morphaxl commented Feb 9, 2026

I have read the CLA Document and I hereby sign the CLA

Copy link

@cubic-dev-ai cubic-dev-ai bot left a 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

@andrerfneves
Copy link

🔥 🔥 🔥

@cryptobetEU
Copy link

gogogo

@cryptobetEU
Copy link

It crashed when I told AI to apply the fix, it fixed it by doing this;

● Here are the code blocks for the fix:


  1. Create new file: src/hooks/model-utils.ts

export const OPUS_4_6_LIMIT = 1_000_000

export function isOpus46(modelID: string | undefined): boolean {
if (!modelID) return false
return modelID.includes("opus-4-6") || modelID.includes("opus-4.6")
}


  1. Update src/hooks/context-window-monitor.ts

Remove the local declarations:
// DELETE THESE LINES:
const OPUS_4_6_LIMIT = 1_000_000

function isOpus46(modelID: string | undefined): boolean {
if (!modelID) return false
return modelID.includes("opus-4-6") || modelID.includes("opus-4.6")
}

Add this import at the top with the other imports:
import { isOpus46, OPUS_4_6_LIMIT } from "./model-utils"


  1. Update src/hooks/preemptive-compaction.ts

Remove the local declarations:
// DELETE THESE LINES:
const OPUS_4_6_LIMIT = 1_000_000

function isOpus46(modelID: string | undefined): boolean {
if (!modelID) return false
return modelID.includes("opus-4-6") || modelID.includes("opus-4.6")
}

Add this import at the top with the other imports:
import { isOpus46, OPUS_4_6_LIMIT } from "./model-utils"

marlon-costa-dc pushed a commit to marlon-costa-dc/oh-my-opencode that referenced this pull request Feb 10, 2026
…de Opus 4.6

# Conflicts:
#	src/hooks/context-window-monitor.ts
#	src/hooks/preemptive-compaction.ts
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.

3 participants