Skip to content

Feature: configurable context compaction threshold (e.g. compact_at_percent: 66) #41818

Description

@m4cd4r4

Summary

Add a configurable threshold that triggers /compact automatically when context usage reaches a specified percentage of the context window, rather than waiting until near 100%.

Use Case

Currently, automatic compaction only fires when the context window is nearly full. By that point, context quality has already degraded. Many users want to proactively compact at a lower threshold (e.g. 66%) to keep response quality consistently high throughout a session.

There is no way to implement this today - there is no hook event that exposes current context usage, and no settings.json option to configure a threshold.

Proposed API

In settings.json:

```json
{
"compactAtPercent": 66
}
```

Or per-project in .claude/settings.json:

```json
{
"compactAtPercent": 80
}
```

When context usage reaches the threshold, Claude Code would automatically trigger the same compaction behaviour as /compact.

Alternatives Considered

  • Rule-based soft enforcement (telling Claude to suggest /compact at 70%) - works but relies on Claude noticing, not a hard system-level trigger
  • Hooks - no context usage variable is available to hook scripts, so this can't be implemented via hooks today

Impact

  • More consistent response quality across long sessions
  • User control over the quality/continuity tradeoff
  • Enables workflows where context hygiene is critical (large codebases, multi-hour sessions)

Submitted via Claude Code session

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssue is inactive

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions