# CLAUDE_CODE_AUTO_COMPACT_WINDOW

> It sets how full a chat gets before it is squeezed.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable

## Think of it like

It is like you pick the size of a box. Then you fill it.

## Definition

CLAUDE_CODE_AUTO_COMPACT_WINDOW sets how many tokens a chat can hold before Claude Code squeezes it. Pick a value from 100,000 to 1,000,000 tokens. A short form such as 200k needs version 2.1.304 or later. A smaller window squeezes the chat sooner and keeps each request smaller.

## Example

Jack runs on a 1M model, but long chats get slow and costly. He sets the window to 300,000, so chats are squeezed well before that.

## Example code

```bash
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000
claude
```

Squeeze the chat at 200,000 tokens.

## Why it matters

A huge window can cost a lot per request. A smaller one keeps each turn lean.

## Common mistake

Setting a value below 100,000. That is out of range, so it does not work.

## Three principles

- **100,000 to 1,000,000.** Tokens.
- **Smaller squeezes sooner.** Leaner requests.
- **200k form.** Needs 2.1.304.

## Related terms

- [Auto-Compact](https://learn.benibix.com/term/ai/auto-compact)
- [Context Window](https://learn.benibix.com/term/ai/context-window)
- [CLAUDE_AUTOCOMPACT_PCT_OVERRIDE](https://learn.benibix.com/term/ai/claude-autocompact-pct-override-variable)

## Told apart from

- [CLAUDE_CODE_AUTO_COMPACT_WINDOW vs CLAUDE_AUTOCOMPACT_PCT_OVERRIDE](https://learn.benibix.com/compare/claude-code-auto-compact-window-variable-vs-claude-autocompact-pct-override-variable): People think these two do the same thing in two units. One sets the size of the box, and the other sets how full it gets. The window variable sets how many tokens the chat can hold, from 100,000 to 1,000,000. The percent variable sets the point in that window where squeezing starts, and it can only move that point lower. Use the window to cap cost per request, and the percent to squeeze a little sooner.

![The auto-compact window and its percent set when a chat is squeezed. Output room comes off the top.](https://learn.benibix.com/diagrams/env-context-window.svg)

---

Source: https://learn.benibix.com/term/ai/claude-code-auto-compact-window-variable
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
