claude-code - 💡(How to fix) Fix Feature request: percentage-based autoCompactWindow for cross-model behavior [2 comments, 2 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#54819Fetched 2026-04-30 06:35:04
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×3commented ×2cross-referenced ×1

Code Example

{
  "autoCompactWindowFraction": 0.55
}
RAW_BUFFERClick to expand / collapse

Problem

autoCompactWindow is an absolute integer (100k–1M tokens), so a single global value can't express a consistent compaction policy across models with different context sizes:

  • autoCompactWindow: 550000 → fires at 55% on 1M-context Opus, but never fires on 200k-context models (above their entire window, falls back to harness ~95% default).
  • autoCompactWindow: 110000 → fires at 55% on 200k models, but at ~11% on 1M (way too aggressive).

Users who switch between 1M Opus and 200k Sonnet/Haiku in the same workflow have no way to set a single "compact at X% full" policy.

Proposed

Add a fractional alternative:

{
  "autoCompactWindowFraction": 0.55
}

When set, the harness computes the threshold as fraction * activeModelContextWindow at session start (or per-turn). When both autoCompactWindow and autoCompactWindowFraction are set, the absolute value wins for back-compat.

Why hooks can't solve this

  • No hook output field mutates settings.
  • SessionStart fires after settings are loaded.
  • Stop hooks can't invoke /compact.

So this needs to live in the harness, not user-land.

Use case

Long agent-team sessions on smaller-context models currently rot before reaching the harness's ~95% default; users want to compact earlier (50–70%) regardless of which model is active.

extent analysis

TL;DR

Implementing a fractional autoCompactWindowFraction setting allows users to set a consistent compaction policy across models with different context sizes.

Guidance

  • Introduce a new setting autoCompactWindowFraction to enable fractional compaction thresholds.
  • When set, compute the threshold as fraction * activeModelContextWindow at session start or per-turn.
  • Ensure backward compatibility by prioritizing the absolute autoCompactWindow value when both settings are present.
  • Test the new setting with different model context sizes to verify consistent compaction behavior.

Example

{
  "autoCompactWindowFraction": 0.55
}

This example sets the compaction threshold to 55% of the active model's context window.

Notes

The proposed solution requires changes to the harness, as hooks cannot solve this issue due to their limitations in mutating settings and invoking the /compact endpoint.

Recommendation

Apply the proposed workaround by introducing the autoCompactWindowFraction setting, as it provides a flexible and consistent compaction policy across different model context sizes.

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

claude-code - 💡(How to fix) Fix Feature request: percentage-based autoCompactWindow for cross-model behavior [2 comments, 2 participants]