Feature Request: Configurable context compaction threshold (trigger at specific token count)

Resolved 💬 3 comments Opened Feb 6, 2026 by slotheather55 Closed Feb 10, 2026

Summary

With Claude Opus 4.6's expanded 1M token context window, users need the ability to configure when automatic compaction triggers — rather than waiting until the context window is nearly full.

Problem

Currently, Claude Code only supports two compaction modes:

  • Manual — running /compact
  • Automatic — triggers when the context window fills up

There is no way to set a custom token threshold (e.g., 256K or 500K) at which compaction should automatically trigger.

This matters for two reasons:

1. Context Accuracy Degrades at Higher Token Counts

Anthropic's own MRCR v2 benchmark (8-needle) shows a significant accuracy drop as context grows:

| Context Length | Accuracy |
|---|---|
| 256K tokens | 93% |
| 1M tokens | 76% |

That's a 17 percentage point drop in retrieval accuracy. For agentic coding workflows where Claude needs to accurately recall instructions, file contents, and prior decisions scattered throughout the conversation, this degradation directly impacts output quality.

2. Cost Management

Longer contexts mean more input tokens processed per API call. Users running Opus 4.6 on large codebases may want to compact earlier to keep per-request costs predictable, rather than letting context grow unbounded to 1M tokens.

Proposed Solution

Add a configurable compaction threshold setting, for example in .claude/settings.json or via a CLI flag:

{
  "compaction": {
    "autoThreshold": 256000
  }
}

Or as a hook trigger:

{
  "hooks": {
    "TokenThreshold": [
      {
        "matcher": "256000",
        "hooks": [
          { "type": "command", "command": "echo 'Triggering compaction at 256K threshold'" }
        ]
      }
    ]
  }
}

Either approach would let users choose their own tradeoff between context length and accuracy/cost.

Alternatives Considered

  • Manual /compact: Works but requires the user to monitor context usage and remember to run it — error-prone during deep coding sessions.
  • CLAUDE.md for persistent context: Helps with critical instructions surviving compaction, but doesn't prevent the accuracy degradation that occurs before compaction triggers.
  • Subagents: Useful for offloading work, but doesn't solve the core issue of the main conversation's context growing too large.

Environment

  • Claude Code CLI
  • Model: Claude Opus 4.6 (1M token context window)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗