[FEATURE] User ability to choose the right context after compaction
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Problem
After a compaction, Claude Code automatically reattaches up to 5 recently used files, along with the root CLAUDE.md and the
text of any skill already used. The user cannot change which files these are.
Those files are often the wrong context for the next step. They are simply the files that were read most recently. Some of
them no longer matter to the task. When they are large, they fill a large part of the context that compaction just freed.
How to reproduce
- Start a session and ask Claude to read any source file.
- Run /compact.
- The output shows that file among the reattached files, although the next task may not need it.
What I tried
- A SessionStart hook with matcher compact. It runs after the files are already attached, so it can only stop Claude from
reading more files on its own.
- A PostCompact hook. Its output never reaches Claude's context, so it cannot help.
- /compact <instructions>. It only changes what the summary keeps, not which files are reattached.
- /clear with a notes file that records task progress. It avoids the reattached files but loses the summary, and auto-compact
still falls back to the default behavior.
Proposed Solution
Give users control over the files reattached after compaction. Any of these would solve it:
- A setting that turns off automatic file reattachment.
- A setting that lists the files or glob patterns to reattach, for example ["CLAUDE.md", "docs/notes.md"].
- A PreCompact hook that can return the list of files to reattach.
- A limit on the size of reattached files, below the current 5,000 tokens per file.
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
Configuration and settings
Use Case Example
_No response_
Additional Context
_No response_