TL;DR Put
"modelSettings": { "haiku": { "autoCompactWindow": 130000 } }in yoursettings.json. Haiku 5.5 will compact around 97K, right before the price step at 100K, in your session and in your Haiku subagents. Don't use 100000: with a base like mine (49K), the main session gets stuck in a compaction loop and never finishes.
Haiku 5.5 costs $0.10/$0.50 per million tokens while the prompt stays under 100K, and $0.50/$2.50 above that (the step, explained here). The catch is that Claude Code doesn't compact it until about 967K, because Haiku 5.5 has a native 1M window. A long Haiku session sends almost all of its requests above the line.
What you pay if you change nothing
A Haiku 5.5 session reading 45 files, one per message, on Claude Code v2.1.293:
requests 48
over 100K 36
largest 248,654 tokens
Haiku cost $0.508
The fix: an autocompact window just for Haiku
The autocompact window is how full the context can get before Claude Code summarizes the conversation (how it works and who sets it). You can set it per model, under modelSettings:
{
"modelSettings": {
"haiku": { "autoCompactWindow": 130000 }
}
}
In ~/.claude/settings.json it covers every project. The haiku key works the same as claude-haiku-5-5: I tried both. If your session is already on Haiku, /autocompact 130k saves it for the current model.
Same work, same version, with the window at 130K:
| No window | 130K window | |
|---|---|---|
| Main Haiku session: requests over 100K | 36 of 48 | 0 of 48 |
| Main Haiku session: Haiku cost | $0.508 | $0.145 |
| Haiku subagent: requests over 100K | 27 of 48 | 0 of 48 |
| Haiku subagent: Haiku cost | $0.372 | $0.076 |
71% less in the session and 79% less in the subagent, one run each. The working requests stayed under 97,400 tokens; only the moment of compaction touches the line. Costs are Haiku's line in the modelUsage of claude -p --output-format json, leaving out the model of the session that launches the subagent.
Why 130K and not 100K
Claude Code keeps a buffer inside the window. On v2.1.293, /context shows it as Autocompact buffer 33k, with the 1M window and with a 100K one alike, and it compacts when the context reaches the window minus that buffer:
| Window | Compacts around | What happened in my test |
|---|---|---|
| 1M (default) | ~967K | Never compacts: 36 of 48 requests at the high rate |
| 100K | ~67K | Main session looped, task never finished |
| 130K | ~97K | Every request under 100K |
At 100K, the main session (which starts at 49K with my setup, between system prompt, tools and skills) had 18K of room. It compacted, read one file and was full again. On the ninth read, Claude Code gave up:
Autocompact is thrashing: the context refilled to the limit within 3 turns of the previous compact, 3 times in a row. A file being read or a tool output is likely too large for the context window. Try reading in smaller chunks, or use /clear to start fresh.
In a subagent, which starts at 5K, 100K did work, but it compacted 5 times instead of 2 and came out a bit more expensive than 130K ($0.088). For one value that covers both cases, 130K.
Before you set it, check your base with /context in a fresh Haiku session. If it's over 60K, you get less than 40K between compactions and you'll compact often.
The fine print
- If a subagent reads everything at once, the window won't save you. In another test, Haiku asked for all 45 files in a single turn, even though I told it one per message. It jumped from 9K to 126K in one go, compacted afterwards and cost 3 times more than with no window ($0.438 against $0.149), because after compacting it was still at 114K. The window helps step-by-step work, not a turn that swallows everything.
CLAUDE_CODE_AUTO_COMPACT_WINDOWbeats everything. If that variable is in your environment, say at 350000, your Haiku entry doesn't count. The four places that set the window and which one wins are in the autocompact tip.- Compacting isn't free. Each compaction is a request that summarizes the conversation, and the new context gets cached again afterwards. That's why, in the subagent, 130K (fewer compactions) beat 100K.
- Haiku 5.5 on the Anthropic API only. On Bedrock, Google Cloud's Agent Platform, Microsoft Foundry and Claude Platform on AWS,
haikustill means Haiku 4.5.
Official docs: Set the auto-compact window · Subagents: auto-compaction · Claude Haiku 5.5
Requirements
- Claude Code v2.1.293 or later, the version Haiku 5.5 asks for. Every number here comes from that version, with my user settings: yours will start from a different base, so check it with
/context.