claude-code - 💡(How to fix) Fix Feature request: configurable auto-compact threshold (e.g. autoCompactThreshold in settings.json) [3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52487Fetched 2026-04-24 06:05:52
View on GitHub
Comments
3
Participants
3
Timeline
6
Reactions
0
Timeline (top)
commented ×3labeled ×2closed ×1

Currently there is no way to configure when auto-compact triggers. Claude Code manages context automatically, but users cannot set a threshold to control this behavior.

Root Cause

Users working on large, long-running sessions need to predict and control when compaction happens. An unexpected auto-compact mid-task can disrupt workflow. A configurable threshold gives users control without requiring manual /compact every session.

Fix Action

Fix / Workaround

Implementing a Stop hook that reads context % and triggers /compact — this works as a local workaround but requires custom scripting and is not as clean as a native setting.

Code Example

{
  "autoCompactThreshold": 0.9
}
RAW_BUFFERClick to expand / collapse

Summary

Currently there is no way to configure when auto-compact triggers. Claude Code manages context automatically, but users cannot set a threshold to control this behavior.

Current behavior

  • Auto-compact fires at an undocumented internal threshold with no user control
  • No setting in settings.json, no environment variable, no CLI flag
  • The only option is manual /compact

Requested behavior

Add a configurable threshold in settings.json, for example:

{
  "autoCompactThreshold": 0.9
}

Or alternatively an environment variable: CLAUDE_AUTOCOMPACT_THRESHOLD=90

This would let users define at what context percentage auto-compact triggers (e.g. 80%, 90%).

Why this matters

Users working on large, long-running sessions need to predict and control when compaction happens. An unexpected auto-compact mid-task can disrupt workflow. A configurable threshold gives users control without requiring manual /compact every session.

Alternatives considered

Implementing a Stop hook that reads context % and triggers /compact — this works as a local workaround but requires custom scripting and is not as clean as a native setting.

extent analysis

TL;DR

To address the issue, consider adding a configurable threshold for auto-compact in settings.json or as an environment variable to give users control over when auto-compact triggers.

Guidance

  • Introduce a new setting in settings.json, such as "autoCompactThreshold", to allow users to configure the threshold at which auto-compact is triggered.
  • Alternatively, consider adding an environment variable, like CLAUDE_AUTOCOMPACT_THRESHOLD, for the same purpose.
  • Evaluate the feasibility of implementing a threshold check within the auto-compact logic to trigger compaction based on the user-defined threshold.
  • Assess the impact of adding this feature on existing workflows and potential edge cases.

Example

{
  "autoCompactThreshold": 0.8
}

This example shows how a user might configure the auto-compact threshold to 80% in their settings.json file.

Notes

The solution depends on the ability to modify the auto-compact trigger logic and access to the settings.json file or environment variables. The exact implementation details may vary based on the underlying system architecture.

Recommendation

Apply a workaround by introducing a configurable threshold setting, as this provides users with the necessary control over auto-compact behavior without requiring significant changes to the existing system.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING