Skip to content

CLAUDE_AUTOCOMPACT_PCT_OVERRIDE cannot raise threshold above default (~83%) #31806

Description

@souliane

Summary

CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is documented as allowing users to control when auto-compaction triggers, but it can only lower the threshold below the default — never raise it. Setting it to 95 (meaning "compact at 95% usage") has no effect because of a Math.min clamp in the threshold calculation.

Root cause

In the minified source, the threshold function (deobfuscated) does:

function getAutoCompactThreshold(model) {
  let effectiveWindow = getEffectiveWindow(model);
  let defaultThreshold = effectiveWindow - 13000;     // ~83.5% of 200k
  let override = process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE;
  if (override) {
    let pct = parseFloat(override);
    if (!isNaN(pct) && pct > 0 && pct <= 100) {
      let userThreshold = Math.floor(effectiveWindow * (pct / 100));
      return Math.min(userThreshold, defaultThreshold);  // ← override silently capped
    }
  }
  return defaultThreshold;
}

Math.min(userThreshold, defaultThreshold) means any value above ~83% is ignored.

Expected behavior

Setting CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=95 should trigger auto-compaction at 95% context usage, not ~83%. If there's a safety reason for the buffer, it should be documented — and the env var should either work as advertised or not exist.

Reproduction

  1. Set "env": { "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "95" } in ~/.claude/settings.json
  2. Start a long conversation
  3. Observe compaction triggers at ~80-85%, not 95%

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions