Skip to content
Follow on Telegram

Home / Tutorials / Tools

Tutorial · Tools

Turn off auto-compaction in Claude Code

Claude Code compacts your long sessions on its own, even when you don’t want it to: I’ll show you the two settings.json keys that turn off auto-compaction and idle compaction, and how to compact by hand when you need to

Turn off auto-compaction in Claude Code
Type
Tutorial: steps to follow, one at a time
Time
2 min read · 5 minutes to do it
Level
Beginner
You’ll need
Claude Code 2.1.311 or later
What you’ll get
  • Auto-compaction off with two lines
  • Compaction when you decide

I don’t use auto-compaction. But since version 2.1.311, sessions with a standard context window that go over 200,000 tokens compact on their own instead of stopping. If you want to decide when, two lines in a file are all it takes.

1

Check your version

You need 2.1.311 or later. Open your terminal and run:

claude --version

If the number is lower, update Claude Code first.

2

Open the settings file

Claude Code’s settings live in ~/.claude/settings.json. Open it with any editor you like; if it doesn’t exist, create it.

3

Add the two keys

Let’s get to the point. Here are the two lines:

{
  "autoCompactEnabled": false,
  "idleCompaction": false
}

With "autoCompactEnabled": false, Claude Code no longer compacts on its own when the context goes over the threshold. With "idleCompaction": false, it also stops compacting a long session you’ve left idle, something it can otherwise do shortly before the one-hour cache expires.

If the file already has other settings, add only these two lines inside the curly braces, separated from the others by a comma (JSON is picky).

4

Run compaction yourself when you need to

Without auto-compaction, what happens when the window is full? The session stops, so you run compaction yourself, at the end of a task. With /compact you can also tell it what to focus on:

/compact focus on the auth bug fix

If you’d rather keep auto-compaction on. Do you work with the 1-million-token window? Lower the threshold with /autocompact: by default it is set at about 967,000 tokens, and the LangWatch analysis (873 compactions by a single developer) points to a threshold between 250,000 and 450,000 tokens.

/autocompact 450k

I update my HANDOFF.md at the end of a task and close the session with a /clear.

Do it your way: now you decide when.

Sources

The why

“Auto-compaction is a colossal piece of crap” explains why it works this way.

I try the next tutorial first, you get it on Monday

Every Monday morning: a new tutorial to try (one I’ve already tested myself) and the week in AI, filtered, with sources.

One email every Monday morning, in Italian. Unsubscribe with one click. Privacy

Prefer Telegram? I’ll tell you there, in Italian, as soon as a new tutorial is out.

Notify me on Telegram
The character points at the invitation, with the parrot on his right shoulder
ShareLinkedInTelegram

Read next