Documentation: Compaction Engine Environment Variables and 1M Context Window

Resolved 💬 3 comments Opened Feb 20, 2026 by edear548-maker Closed Feb 23, 2026

Summary

I reverse-engineered the compaction engine from cli.js v2.1.47 and documented several undocumented features that significantly impact Claude Code usage.

Key Findings

Environment Variables (undocumented)

  1. ANTHROPIC_BETAS=context-1m-2025-08-07 - Enables 1M token context window (requires tier 4)
  2. DISABLE_AUTO_COMPACT=1 - Disables automatic context compaction
  3. CLAUDE_AUTOCOMPACT_PCT_OVERRIDE - Overrides auto-compact threshold (valid range: 1-100)

Important Gotcha

CLAUDE_AUTOCOMPACT_PCT_OVERRIDE values above 100 are silently ignored (due to z <= 100 check in ep6()), falling back to the default ~83.5% threshold. This is counterintuitive since users might set it to a large number thinking it disables compaction.

The Math

| Setting | Context Window | Effective | Auto-Compact At |
|---------|---------------|-----------|----------------|
| Default | 200,000 | 180,000 | 167,000 (83.5%) |
| 1M Beta | 1,000,000 | 980,000 | 967,000 |

PreCompact Hook

  • Exit code 2 blocks compaction
  • Exit code 0 appends stdout as custom summary instructions

Model Name Hack

Using opus[1m] as model name triggers 1M context via regex /\[1m\]/i in the code.

Request

Could these environment variables and their behavior be documented officially? The silent failure of values >100 on CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is particularly worth documenting.

Source

All findings from production cli.js v2.1.47. Full technical writeup: https://telegra.ph/I-Reverse-Engineered-Claude-Code-Compaction-and-Found-a-Hidden-1M-Token-Context-Window-02-20

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗