[BUG] `/compact` typed inside the subagent view compacts the main conversation instead

Status Open
Reported on v2.1.251
Maintainer reply None cached
Activity 0 comments · opened Sep 28, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Typing /compact while viewing a running subagent's transcript compacts the main (lead) conversation instead of the subagent. There is no confirmation or notice. Reproduced twice in a fresh interactive session (steps below). I first hit it in a background session, where it cut the lead's context from 246,778 to 11,202 tokens while three subagents it was coordinating were still running.

The view signals that input goes to the subagent: the prompt placeholder reads "Message @name…" (changelog 2.1.251), and plain messages typed there are delivered to the subagent (changelog 2.1.113). Yet /compact went to the lead; the only output was "Compacted (ctrl+o to see full summary)".

2.1.199 fixed the same routing for two other commands: "Fixed typing /model or /fast while viewing a subagent silently opening the lead's model picker — a notice now explains the command applies to the lead." /compact did not get that treatment, and unlike those two it throws away the lead's context.

Feedback ID for the original session: 58419e34-29d9-41ce-befa-c5297fc65eca (sent with /bug 18 s after the /compact, while compaction was running).

What Should Happen?

Either /compact compacts the subagent being viewed, or it is refused in that view with a notice that it applies to the lead, as /model and /fast now do. Compacting the lead from a subagent view needs an explicit confirmation.

Error Messages/Logs

Main session transcript from repro run 1, abridged, in timestamp order. Both runs wrote the `/compact` record and a manual `compact_boundary` to the main `<session>.jsonl`; the viewed subagent's `subagents/agent-*.jsonl` has neither. The original background session shows the same pattern (`sessionKind:"bg"`, 246,778 → 11,202).


{"type":"user","timestamp":"2026-09-28T11:39:53.315Z","isSidechain":false,"message":{"content":"/compact"}}
{"type":"system","subtype":"compact_boundary","timestamp":"2026-09-28T11:40:12.969Z","isSidechain":false,"compactMetadata":{"trigger":"manual","preTokens":39923,"postTokens":3829,"durationMs":19639}}
{"type":"user","timestamp":"2026-09-28T11:40:13.068Z","isSidechain":false,"message":{"content":"<local-command-stdout>Compacted (ctrl+o to see full summary)</local-command-stdout>"}}

Steps to Reproduce

In a fresh interactive session (claude --model haiku, default permission mode):

  1. Ask Claude to launch a background general-purpose subagent that runs timeout 110 tail -f /dev/null; true in the foreground (approve its Bash prompt if asked). A plain sleep gets backgrounded or blocked, and the subagent then finishes too soon.
  2. While it runs, press Down from the empty prompt to focus the agent list, select the running agent and press Enter. The placeholder changes to "Message @general-purpose…".
  3. Press Esc once to return focus to the prompt. You stay in the subagent view.
  4. Type /compact and press Enter.

Result: the input clears, no notice appears, and the subagent keeps running uncompacted. Switching back to main shows ❯ /compact / ⎿ Compacted (ctrl+o to see full summary) in the lead's transcript. The second run compacted the lead again (36,852 → 3,885 tokens); the viewed subagent (~22k tokens) was never compacted.

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.283

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

Claude Code runs in a Docker devcontainer (Ubuntu, arm64) on macOS.

Related:

  • #62853 (the opposite direction: agent view forwarded slash commands to the subagent as prompts; auto-closed as stale)
  • #95851 (VS Code compact icon runs /compact without confirmation)
  • #96619 (a subagent's compaction summary points at the parent's transcript)

View original on GitHub ↗