claude-code - 💡(How to fix) Fix [BUG] /compact custom instructions cross compaction boundary on 2.1.121 (reproduction of #20370) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#55555Fetched 2026-05-03 04:50:22
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1
RAW_BUFFERClick to expand / collapse

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).

extent analysis

TL;DR

The issue can be fixed by modifying the compaction process to either strip or mark the custom instruction arguments so they are not re-executed by the post-compaction instance.

Guidance

  • Verify that the custom instruction arguments are indeed being passed through the compaction boundary by checking the compactMetadata JSONL output for any signs of the original command.
  • Consider modifying the compaction process to strip the <command-args> payload from the user message before it crosses the compact_boundary.
  • Alternatively, replace the original command arguments with a marker (e.g., [ALREADY_EXECUTED]) to indicate they have been consumed and should not be re-executed.
  • Review automated workflows that trigger compaction to assess the impact of this bug and plan for mitigation or updates once a fix is applied.

Example

No specific code snippet can be provided without more context on the implementation details of the compaction process in Claude Code. However, the fix would involve ensuring that the code handling the compaction boundary correctly processes the custom instruction arguments to prevent re-execution.

Notes

The exact implementation of the fix depends on the internal workings of the Claude Code compaction mechanism, which is not fully detailed in the issue report. The suggested approaches (stripping or marking the command arguments) are based on the problem description and may require adjustments based on the actual codebase.

Recommendation

Apply a workaround by manually monitoring and handling the custom instruction arguments in automated workflows until a formal fix is released, as the bug's impact is significant in environments without human oversight.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING