GrepBoard/Manuals
605 manuals ·

Claude Code Forgets Rules in Long Chats: /compact vs /clear

·Tested on Claude Code 2.1.302 · official docs as of 2026-10·Test scope ↓·7 steps

When a long session loses early instructions, check usage with /context, pick /compact or /clear, and see what survives compaction and what drops out.

If Claude Code starts ignoring a rule you gave earlier, the context was either summarized or is nearly full. Check its state, then compact or clear.

[1] Run /context in the session to see what takes up space: tokens per category, the CLAUDE.md files that loaded, and the reserve for auto-compaction. The output below is an excerpt from claude -p "/context" in an empty session, with the path changed.

output
## Context Usage **Tokens:** 18.6k / 1m (2%) | Category | Tokens | Percentage ||----------|--------|------------|| System prompt | 2.2k | 0.2% || System tools | 8.1k | 0.8% || Memory files | 6.2k | 0.6% || Messages | 10 | 0.0% || Free space | 948.4k | 94.8% || Autocompact buffer | 33k | 3.3% | ### Memory Files | Type | Path | Tokens ||------|------|--------|| Project | /srv/app/CLAUDE.md | 22 |

[2] To keep working on the same task and free space, run /compact. It replaces the conversation so far with a summary. Add instructions and the summary keeps those parts first.

text
/compact focus on the auth bug fix

[3] When you move to unrelated work, run /clear. It starts a new conversation with empty context. Aliases are /reset and /new. Give it a name and the old conversation shows under that name in the /resume picker.

text
/clear api-refactor/resume api-refactor

The docs' reasoning: old conversation crowds out the files you need next and costs tokens on every message. Same task, use /compact. Finished task, use /clear.

[4] Know what survives compaction. This table is condensed from the official docs.

ContentAfter compaction
Project-root CLAUDE.md, unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
Rules with paths: frontmatterReloaded when a matching file is touched again
CLAUDE.md in subdirectoriesReloaded when files in that directory are touched again
Files read or editedUp to five re-read, most recently modified first
Invoked skill bodiesRe-injected, 5,000 tokens per skill, 25,000 total
Instructions given only in chatSummarized with the rest; details may be lost

Nested CLAUDE.md files and paths: rules enter the message history when Claude reads or edits a trigger file, so compaction summarizes them away with everything else. To keep a rule across compaction, drop paths: or move it to the root CLAUDE.md.

[5] Put chat-only instructions in CLAUDE.md; the memory page's troubleshooting section reaches the same conclusion. To steer what compaction keeps, add a Compact Instructions section to CLAUDE.md or pass instructions to /compact.

CLAUDE.md
# Rules- Answer in Korean. ## Compact InstructionsWhen compacting, keep the list of changed files and the failing test names.

[6] Auto-compaction runs by itself near the model's limit, and the point differs by model. The docs say models with a native 1M window compact at about 967K tokens, and Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary. To compact earlier, set the window between 100K and 1M tokens.

console
$ claude --autocompact 200k

In a session, use /autocompact 500k (v2.1.221 or later) and auto to revert. The settings key is autoCompactWindow; for scripts, the environment variable is CLAUDE_CODE_AUTO_COMPACT_WINDOW (plain token counts only). When set, the variable overrides the command, flag, and setting.

[7] To compact only part of the conversation, run /rewind, pick a message, and choose Summarize from here or Summarize up to here. Hand research that reads big files to a subagent so the contents never pile up in your main conversation.

#claude-code#context#claude-md