claude-code - 💡(How to fix) Fix [BUG] CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 does not trigger autocompact — context reaches 100% requiring manual /compact [3 comments, 4 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#52390Fetched 2026-04-24 06:08:28
View on GitHub
Comments
3
Participants
4
Timeline
6
Reactions
0
Author
Timeline (top)
commented ×3labeled ×3

Code Example

{
  "env": {
    "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
  }
}
RAW_BUFFERClick to expand / collapse

Bug

CLAUDE_AUTOCOMPACT_PCT_OVERRIDE set to 50 in settings.json does not trigger automatic compaction. The context window reaches 100% and Claude Code shows the hard limit prompt (Context limit reached · /compact or /clear to continue), requiring manual /compact every time.

Version

Claude Code v2.1.118, Sonnet 4.6 (200k context), macOS Darwin 25.4.0

Reproduction

Settings (~/.claude/settings.json)

{
  "env": {
    "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
  }
}

Steps

  1. Start a Claude Code session with the above setting
  2. Run a moderately long session with multi-agent tasks and file reads (e.g., 5–10 subagent spawns)
  3. Observe that autocompact never fires at 50% — context grows to 100%
  4. Claude Code shows: Context limit reached · /compact or /clear to continue
  5. Must manually type /compact to continue

Expected behavior

Autocompact should trigger when context usage reaches 50%, preventing the hard limit.

Actual behavior

Autocompact never fires. Context reaches 100% regardless of the configured threshold.

Notes

  • Related to #42394 (same env var unreliable, but that report is about firing too early; this is the opposite: never fires)
  • The PreCompact hook (~/.claude/hooks/pre-compact.sh) runs correctly when manual /compact is executed, confirming the hook setup itself is not the issue
  • The problem appears to be that CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is not being read or applied at all in v2.1.118 for Sonnet 4.6 sessions

extent analysis

TL;DR

The issue can be worked around by verifying that the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE environment variable is correctly set and applied in the Claude Code session.

Guidance

  • Check if the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE environment variable is being set correctly in the settings.json file and if it's being overridden by any other configuration.
  • Verify that the Claude Code version (v2.1.118) supports the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE environment variable for Sonnet 4.6 sessions.
  • Test if setting the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE environment variable directly in the operating system (instead of settings.json) resolves the issue.
  • Review the related issue #42394 to see if there are any insights or workarounds that can be applied to this case.

Example

No code snippet is provided as the issue seems to be related to configuration and environment variables.

Notes

The problem might be specific to the combination of Claude Code version (v2.1.118) and Sonnet 4.6, and it's possible that the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE environment variable is not being applied correctly in this setup.

Recommendation

Apply workaround: Set the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE environment variable directly in the operating system to test if it resolves the issue, as the current configuration method seems to be unreliable.

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…

FAQ

Expected behavior

Autocompact should trigger when context usage reaches 50%, preventing the hard limit.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING