[Feature Request] Allow custom commands to hook and invoke `/compact` with generated arguments
Status Open
Reported on v2.1.220
Maintainer reply None cached
Activity 3 comments · opened Jul 30, 2026
Bug Description
I have my own /compact command that constructs args for the system /compact command but unfortunately it can neither hook the /compact command to give it those args nor invoke /compact itself. So I have to do this all the time:
❯ /cc-context-preserving-compact ⏺ /compact @.claude/compact-context-9858f5b0.md Copy-run the above to compact — writing the instructions to that file now; I can't trigger /compact myself. · Booping… (46s · ↓ 2.0k tokens) ❯ /compact @.claude/compact-context-9858f5b0.md
Please enhance the compact hook so /compact or auto compact will run my command to generate the args to compact. Thank you! :)
Environment Info
- Platform: darwin
- Terminal: ghostty
- Version: 2.1.220
- Feedback ID: f5297dc7-6bfd-4e21-a657-a18a31a07e67
Errors
[]
3 Comments
Any reason not to add this?
Note: I see many requests for this and most are marked duplicate of 3349 which has been closed as not planned and with zero reasons as to why.
Is this really how feature requests are supposed to work?
Autocompact seems to be a huge hole in agentic workflow. How are we supposed to do long lived agents if we can't manage the context?
A way around the copy-paste step: sub-agent-compact (disclosure: mine, MIT) gives Claude a
compacttool whosefocusargument becomes the summarizer's instructions. Your/cc-context-preserving-compactcan end with "call the compact tool with the focus written to .claude/compact-context-….md" instead of asking you to type/compact @file. Claude generates the args and triggers the compaction itself.It also nudges Claude to do this on its own as the context grows, and it has a forced point for when it doesn't. That covers the "auto compact should run my command" half too, as long as your command's instructions live in the model's reach (CLAUDE.md or the command itself).
Limits: it's built on early-access function hooks (
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1), and it can only let through a compaction Claude Code asks for. WithCLAUDE_CODE_AUTO_COMPACT_WINDOW=100000, that's from about 65k tokens.