Skip to content

[FEATURE] Per-model configurable autocompact threshold #34126

Description

@Theurgist

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

With the 1M context window now available for Opus, a single global CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is no longer sufficient. Different models benefit from different compaction strategies, and users need per-model control over when autocompact triggers.

Motivation

When using Opus (1M context) as the primary model that spawns Sonnet subagents, the optimal autocompact threshold differs significantly between them:

Use Case Example

  • Opus (1M): I may want to compact at ~30% (300K tokens) to keep costs manageable and responses fast, since the full 1M window is rarely needed
  • Sonnet subagents: I want them to use a larger portion of their context (e.g., 80-90%) since they handle focused, bounded tasks where more context is useful

Currently, CLAUDE_AUTOCOMPACT_PCT_OVERRIDE applies globally — forcing a single trade-off that can't serve both use cases.

Proposed Solution

Allow per-model autocompact thresholds in settings.json:

{
  "autoCompactThreshold": {
    "default": 80,
    "opus": 30,
    "sonnet": 90,
    "haiku": 95
  }
}

Or alternatively, extend the environment variable approach:

CLAUDE_AUTOCOMPACT_PCT_OPUS=30
CLAUDE_AUTOCOMPACT_PCT_SONNET=90
CLAUDE_AUTOCOMPACT_PCT_HAIKU=95
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=80  # fallback default

Why Not Use the Existing Global Override

Scenario Global at 30% Global at 90%
Opus (1M) primary session Good — keeps cost/latency down Bad — consumes up to 900K tokens before compacting
Sonnet subagents Bad — compacts too early, loses useful context for focused tasks Good — maximizes available context

There is no single value that works well for both.

Priority

High - Significant impact on productivity

Feature Category

Configuration and settings

Additional Context

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions