[BUG] Slash command typed during a pending background-task notification renders twice (echo + dispatch), looks like /compact ran twice
What's Wrong?
In a long-running session that receives background task notifications (for example a persistent Monitor task), typing /compact while a notification turn is pending produces a confusing double render:
- The typed
> /compactbar is echoed immediately. - The queued notification turn is processed first (the assistant responds to the background event).
- The queued
/compactthen dispatches, and the CLI renders a second, identical> /compactbar, followed by the actual compaction output.
The user sees two /compact command bars with an assistant turn between them, and reasonably concludes the command was issued twice or that compaction ran twice. The first bar carries no "queued" indicator in this path, and only the second bar carries the "Compacted" result.
The session transcript proves the command executed exactly once per keypress. Accounting across 7 manual compactions in one session: 7 user command events, 7 compact_boundary entries (all trigger: "manual"), 7 "Compacted" stdout confirmations. The command event is written at dispatch time, and compactMetadata.durationMs spans dispatch to boundary exactly.
Example timeline from the transcript (UTC):
- 19:11:00 the assistant turn for the queued background notification ends (
stop_hook_summary); the user had typed/compactaround this window and its bar was already rendered - 19:11:50 the queued
/compactdispatches: user command event written, second bar rendered, compaction starts - 19:14:38
compact_boundarywritten (durationMs166809 matches 19:11:50 to 19:14:38 to the second)
What Should Happen?
Either render the queued command once (at dispatch time only), or clearly mark the first render as queued (dimmed or a "queued" badge) so the second render is recognizable as the same command reaching execution, not a new invocation.
Steps to Reproduce
- Run a long session with a background task that posts task notifications (for example a persistent Monitor watching a file).
- Type
/compactwhile a notification turn is pending (easiest to hit when notifications arrive frequently). - Observe: the command bar renders at type time, the notification turn runs, then the same command re-renders at dispatch and executes once.
Related (checked, different shapes)
- #17808: re-compaction after exiting and
claude --continue - #55293: assistant response duplicated in scrollback after compaction (closed as duplicate)
Claude Code Version
2.1.217
Platform
Claude Max (claude.ai login)
Operating System
Linux
Terminal/Shell
bash, daemon-managed background session attached in the terminal UI