claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open DuaneNielsen opened this issue 1 year ago • 13 comments

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.

DuaneNielsen avatar Aug 27 '25 22:08 DuaneNielsen

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

github-actions[bot] avatar Aug 27 '25 22:08 github-actions[bot]

+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

coygeek avatar Aug 27 '25 23:08 coygeek

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.

kcosr avatar Aug 28 '25 00:08 kcosr

/context with auto-compact set to true:

Image

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

Image

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

dalito avatar Oct 12 '25 23:10 dalito

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.

ShanePresley avatar Oct 17 '25 14:10 ShanePresley

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!!!!

richservo avatar Oct 18 '25 02:10 richservo

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.

github-actions[bot] avatar Dec 09 '25 10:12 github-actions[bot]

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. 🤦

QuintinWillison avatar Dec 14 '25 16:12 QuintinWillison

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

PaulRBerg avatar Dec 20 '25 06:12 PaulRBerg

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.

jb747 avatar Jan 14 '26 14:01 jb747

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.

yurukusa avatar Mar 29 '26 05:03 yurukusa

You can turn auto-compact off today: set DISABLE_AUTO_COMPACT=1 in your environment, or set "autoCompactEnabled": false in settings (also toggleable in /config as "Auto-compact"). Manual /compact keeps working. Docs: https://code.claude.com/docs/en/env-vars

🤖 Generated with Claude Code

bcherny avatar Aug 17 '26 03:08 bcherny

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Oct 07 '26 14:10 github-actions[bot]