r/ClaudeCode • u/NextSoftware8102 • 13h ago
Tips & Workflows I halved Claude Code's auto-compact window for a month to save tokens. It barely saved anything, but the hooks I built for it were worth keeping.
I use Claude Code all day, across about 40 repos (firmware, a home server, a couple of web apps). In early November I tried an experiment: make Opus compact sooner so each call carries less context and costs less.
**The change -** autoCompactWindow for Opus went from 600K to 300K. Before that, I wrote two hooks so compaction wouldn't lose the thread:
**PreCompact** saves a small state file: the task list, the step in progress, my last request, and the start of Claude's last reply.
**SessionStart (matcher compact)** puts that file back into context right after the summary.
**What I measured (Opus sessions only)**
| Period | Window | Sessions | Avg context per call | Compactions per 100 calls | Sessions that went over 300K anyway |
|---|---|---|---|---|---|
| Baseline week | 600K | 100 | 190K | 0.45 | 27 |
| Week 1 | 300K | 77 | 181K | 1.00 | 29 |
| Week 2 | 300K | 55 | 166K | 0.72 | 7 |
| Days 15–25 | 300K | 89 | 176K | 0.65 | 18 |
**What I learned**
**The smaller window barely moved average context** (5–13% lower, which is inside normal week-to-week swings). Most calls never get near the limit, so cutting the limit mostly changes the rare long session.
**Compactions went up 1.4–2.2×.** Each one is a summary pass, a slower turn, and a chance to lose something.
**The window is not a hard cap.** Compaction seems to happen between turns, so one long agentic turn can blow straight through it. My largest peak with a 300K window was 774K.
**The hooks were the real win.** 152 PreCompact runs and 130 post-compact runs in two weeks, zero failures, median about 0.8 s. In the session I scored by hand, Claude came back from compaction with its plan, its pending step and every key fact, and I didn't have to repeat anything.
**A gate test caught a real gap:** when the plan only existed as text in a reply (no task-list tool), it got lost in the summary. Saving the first 800 characters of the last reply fixed that.
I've now set Opus to 400K, the same as my other models, and kept the hooks.
**Caveats:** one person's workload, not a controlled trial, and only one compaction scored by hand. Treat it as a field report.
Hooks, tests and the full write-up: https://github.com/ColdBore-RD/claude-compaction-state
Happy to answer questions about the hook payloads or how I pulled the numbers from transcripts.
