[BUG] /compact custom instructions cross compaction boundary on 2.1.121 (reproduction of #20370)

Resolved 💬 3 comments Opened May 2, 2026 by richardtkemp Closed May 6, 2026

Preflight Checklist

  • I have searched existing issues — this is a fresh report of the bug originally filed as #20370, which was auto-closed as inactive on 2026-02-28 without a fix. The bug reproduces on the current version.
  • This is a single bug report
  • I am using the latest version of Claude Code (2.1.121)

What's Wrong?

Reproduction of #20370 on Claude Code 2.1.121. The original report was filed against 2.1.7, auto-closed as inactive without fix. Behaviour is unchanged.

When /compact is invoked with custom instruction arguments, the <command-name>/compact</command-name> + <command-args>...</command-args> block crosses the compaction boundary. The post-compaction instance sees the original instruction args still in its context, interprets them as a live request, and re-executes them — typically producing a duplicate summary or duplicate side effects.

What actually happened in our reproduction:

  1. /compact injected with ~3.5k chars of custom format-spec instructions at 2026-05-02T10:17:54.472Z UTC
  2. Pre-compaction instance generated a summary (compaction took 154 seconds; summary became the session-continued preamble)
  3. compact_boundary written at 2026-05-02T10:20:28.777Z UTC. JSONL compactMetadata: preTokens=237943, postTokens=13493, trigger="manual", durationMs=154217
  4. Post-compaction instance saw the original <command-name>/compact</command-name> block still in its context (alongside the session-continued preamble that already contained the summary), treated it as a fresh request, and produced a SECOND summary (~7.7 KB of text) as a normal assistant text turn at 2026-05-02T10:22:21Z

What Should Happen?

Per #20370: /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 (e.g. [ALREADY_EXECUTED]) so the post-compaction instance doesn't re-execute them.

Steps to Reproduce

Same as #20370:

  1. Start a session, accumulate context
  2. Run /compact [instructions] with non-trivial custom instructions (we sent ~3.5k chars of summary-format spec; the original report used a "write a detailed handoff" prompt)
  3. Wait for compaction to complete
  4. Observe: post-compaction instance sees the original <command-args> block in context and re-executes — producing a duplicate summary or duplicate side effects (Write/git etc.)

Claude Model

claude-opus-4-7

Claude Code Version

2.1.121

Platform

Anthropic API (via Claude Code SDK)

Operating System

Debian Linux

Additional Information

This bug is particularly impactful for automated/SDK-driven workflows (CI/CD compaction triggers, agent platforms, scheduled compaction, etc.) where there's no human in the loop to notice the duplicate execution. In our case the duplicate was just a text response, but #20370 reports cases where the post-compaction instance executed Write, git commit, git push tool calls — creating a duplicate handoff document.

The fix shape is small: either strip the <command-args> payload from the user message before it crosses the compact_boundary, or replace the args with a marker indicating they've been consumed.

References: original report #20370 (closed as inactive 2026-02-28).

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗