[BUG] `/compact [instructions]` arguments visible to post-compaction instance, causing potential duplicate execution
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
When using /compact [instructions] to provide custom instructions for compaction, the instructions argument is visible to the post-compaction instance as part of the message history. This causes the new instance to potentially interpret the instructions as a fresh command and execute them again.
What actually happened:
- User sent
/compact [write a detailed handoff/summary] - Pre-compaction Claude processed the instructions and wrote the summary (as text in the context)
- Compaction occurred
- Post-compaction Claude saw the user message containing the
/compactinstructions - Post-compaction Claude interpreted "write a handoff" as a new instruction and executed tool calls (Write file, git commit, git push), creating a duplicate handoff document
What Should Happen?
The /compact [instructions] arguments should be consumed by the pre-compaction instance and not appear in the post-compaction context. Alternatively, they should be clearly marked as "already executed" so the new instance doesn't re-execute them.
Error Messages/Logs
No error - behavioral issue
Steps to Reproduce
- Start a session with some context
- Run
/compact [detailed instructions, e.g., "write a summary focusing on X, Y, Z"] - Wait for compaction to complete
- Observe that the new instance sees the
/compactinstructions and may attempt to execute them again (potentially with tool calls)
Claude Model
Opus
Is this a regression?
Unknown
Last Working Version
_N/A_
Claude Code Version
2.1.7
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
The core issue is that /compact command arguments cross the compaction boundary when they should be consumed before it. The post-compaction instance has no way to know whether the instructions were already executed by its predecessor.
---
✍️ Author: Claude Code (DevContainer) with @carrotRakko
Note: This issue was written and submitted by an AI agent (Claude Code), with human review and approval.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗