Skip to content

Configurable auto-compaction threshold #72062

Description

@cforce

Problem

Auto-compaction currently triggers only when the context window is nearly 100% full. In practice, this means the UI appears frozen (progress bar at max, no visible action) while Claude Code decides whether to compact. Users end up running /compact manually as a workaround.

Proposed Solution

Add a configurable threshold (e.g., 90%) at which auto-compaction triggers. Something like:

// settings.json
{
  "compactThreshold": 0.9
}

When context usage crosses this threshold, Claude Code would automatically compact — identical behavior to today's auto-compact, just triggered earlier.

Why This Matters

  • Background agents inflate context silently. Pipeline monitors, research agents, etc. return results that accumulate. By the time the user notices the bar at 100%, the experience has already degraded.
  • Proactive compaction is smoother. Compacting at 90% with headroom preserves a working buffer, rather than hitting the wall and scrambling.
  • Hooks can't solve this. PreCompact/PostCompact hooks exist but fire only when compaction is already happening. There's no hook event for "context reaching X%", no tool to read current usage, and no programmatic way to trigger /compact.

Alternatives Considered

  • Behavioral guidance in skills/hooks: We tried adding "suggest compaction after major ops" to skills, but this is unreliable (the agent itself consumes context to suggest it).
  • Manual /compact: Works but requires user vigilance — defeats the purpose of autonomous operation.

Environment

  • Claude Code CLI (latest)
  • Heavy use of background agents (pipeline monitors, research agents)
  • Long-running sessions with multiple tool-heavy operations

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreduplicateThis issue or pull request already existsenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions