[FEATURE] Add --no-auto-compact command switch to Disable the auto-compaction

Status Fixed / completed
Maintainer reply None cached
Activity 12 comments · opened Aug 27, 2025 · closed Aug 17, 2026

Allow the user to disable the auto-compact, and fully manage the context and continuation process themselves if they want.

This would be a very simple feature to implement. Just add a flag --no-auto-compact

I'm quite certain that 80% of users, and definitely 100% of power users already manage their own context via saving and restoring plans from files. And there are already scripts in the community that manage continuation better than anthropics current implementation.

Embrace the community here and I'm sure you will be rewarded.

View original on GitHub ↗

11 Comments

github-actions[bot] · 1 year ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/3349

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

coygeek · 1 year ago

+1, this is a really thoughtful feature request.

I've also run into situations where the auto-compaction kicks in when I'm trying to carefully manage a long context for a complex task. Having a startup flag for this would be super convenient, especially for scripting or when launching claude with a specific, long-running goal in mind.

In case you weren't aware (and for anyone else finding this thread), you can actually disable this behavior in the current version, though not via a command-line flag. You can run the /config slash command in an interactive session and toggle the "Auto-compact enabled" setting to off. It seems to remember this setting between sessions, which helps.

I found it mentioned in the Manage costs effectively documentation:

Compact conversations: Claude uses auto-compact by default when context exceeds 95% capacity Toggle auto-compact: Run /config and navigate to "Auto-compact enabled" * Use /compact manually when context gets large

This also pairs well with the manual /compact command, which lets you decide exactly when to shrink the context, and even provide custom instructions on what to focus on during the compaction.

So while it's not a command-line flag, you can at least disable it globally for your user. For scripting, you'd have to remember to have it disabled beforehand, which is where your --no-auto-compact flag would still be a great addition for guaranteeing the behavior of a script.

But I totally agree, having a command-line switch for this would be a power-user feature that fits the "Unix philosophy" vibe of the tool perfectly. Hope the team considers it

kcosr · 1 year ago

To add to this, with the new /context command I can see that I have around 25% free context when the auto-compact occurs. This is wasteful for me. I don't want to compact manually or automatically. I prefer to leave things in a good state and /clear providing fresh context when I resume.

dalito · 10 months ago

/context with auto-compact set to true:

<img width="797" height="273" alt="Image" src="https://github.com/user-attachments/assets/b208aeb4-190f-47be-afee-524d0b2e7d3d" />

After setting auto-compact to flase via /config command the /context command shows that the previously reserved context is now available:

<img width="805" height="263" alt="Image" src="https://github.com/user-attachments/assets/8cb9ccb4-7fd4-461c-b732-fc0f3c0ddb08" />

This is great but not a replacement for the feature request.

ShanePresley · 10 months ago

It seems this is set across the board in ~/.claude.json and I can't find documentation for it.

disabled


$ jq .autoCompactEnabled ~/.claude.json
false

enabled


$ jq .autoCompactEnabled ~/.claude.json
null

I tried overriding it with claude --settings to no avail. In it's current form, I don't see a way to override it at invocation or at a project level but I absolutely agree such a feature would be useful.

richservo · 10 months ago

Auto compact is about the WORST thing about Claude code!!!! Drives me crazy, it WASTES tokens for nothing and often causes problems because it doesn't give full context. I've found that escaping it before it starts allows me to copy the last relelevent lines of conversation and it picks up PERFECTLY. Dalito you're my hero!!!!

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

QuintinWillison · 8 months ago

This is, by a country mile, the biggest pain point I am finding with Claude Code. When I'm deep into refining a plan, suddenly compaction kicks in and all the nuance and detail that I cared about is lost.

UPDATE: Looks like this might be controlled via /config and persisted to ~/.claude.json (global state) rather than ~/.claude/settings.json (user preferences) as I had initially and naievely assumed. 🤦

PaulRBerg · 8 months ago
It seems this is set across the board in ~/.claude.json and I can't find documentation for it.

Yep. It's an undocumented boolean flag in the ugly ~/.claude.json:

{
"autoCompactEnabled": false
}

it would be really great to have a CLI flag for enabling/disabling it, as well as a bespoke flag that users can set in settings.json

jb747 · 7 months ago

Most users may lack sufficient data to rate the last compaction at the point where they are asked it so the value of the metric may not be high relative to the amount of irritation created by the constant prompting.

yurukusa · 5 months ago

Hook workaround: block auto-compaction with PreCompact
In addition to the autoCompactEnabled: false flag in ~/.claude.json mentioned above, you can use a PreCompact hook for more granular control — e.g., block compaction conditionally, or save context before allowing it.
compact-blocker.sh (unconditional block):

exit 2

Install in .claude/settings.json:

{
  "hooks": {
    "PreCompact": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash /path/to/compact-blocker.sh"
          }
        ]
      }
    ]
  }
}

Conditional variant — block only when a flag file exists:

[ -f /tmp/allow-compact ] && exit 0
exit 2

This way you can touch /tmp/allow-compact when you're ready for compaction, and rm /tmp/allow-compact when you want to preserve full context.
You can also combine this with a pre-compact checkpoint hook that saves uncommitted changes to git before compaction fires, so nothing is lost even when compaction is allowed.

Showing cached comments. Read the full discussion on GitHub ↗