[BUG] high token usage because of duplicated bash tool output

Resolved 💬 13 comments Opened Feb 22, 2026 by NickSdot Closed Mar 6, 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?

I think I found a hint on why Claude Code token usage is through the roof for me lately. When trying to optimise token usage of some helper scripts my eye caught the following in Claudes reasoning:

<img width="839" height="136" alt="Image" src="https://github.com/user-attachments/assets/df869116-1dd4-4c65-9f08-d412312392d1" />

So, I sent Claude to explore this, and the result is that the bash tool seem to duplicate all output Claude reads if the command exits with a non zero exit status. Means: test or build failure with each 100 lines? Well, Claude sees 200 lines. The multiplication per session is insane.

Claudes Report

Bug Report: Bash Tool Output Duplicated for Failed Commands

### Summary

When a Bash command exits with a non-zero status code, the output displayed in Claude Code's tool result
is duplicated (shown twice). Successful commands (exit 0) display output correctly once.

### Environment

  • Claude Code CLI
  • macOS Darwin 24.6.0
  • Model: claude-opus-4-5

### Steps to Reproduce

Run this via the Bash tool:

  echo "Line 1" && echo "Line 2" && exit 1

Tool result shows:

  Line 1
  Line 2

  Line 1
  Line 2

Expected:

  Line 1
  Line 2

### Verification That Actual Output Is Not Duplicated

(echo "Line 1" && echo "Line 2" && exit 1) 2>&1 | wc -l 
#  Returns: 2 (correct)

The shell produces 2 lines. The tool result displays 4.

### Comparison: Success vs Failure

| Command | Exit Code | Output Duplication |
| --- | --- | ---|
| echo "Line 1" && echo "Line 2" |0|No (shown once) |
| echo "Line 1" && echo "Line 2" && exit 1 |1| Yes (shown twice) |

### Impact on Context Usage

Yes, this increases context usage. The duplicated output consumes approximately 2x the tokens it should.
For verbose compiler errors or test failures, this can add thousands of unnecessary tokens to the
conversation context.

### Additional Observations

  • The duplication appears in the <error> block of the tool result
  • Both stdout and stderr content are duplicated together
  • The duplication is identical (not interleaved or reordered)
  • Wrapping in a subshell and counting lines confirms the actual output is correct

### Workaround

None identified. The duplication happens at the tool result display level, not in the actual command
execution.

---

What Should Happen?

No duplicate output

How to reproduce

  1. Open fresh Claude session
  2. Run ! echo "Line 1" && echo "Line 2" && exit 1

<img width="408" height="301" alt="Image" src="https://github.com/user-attachments/assets/f33bfa22-9bfb-4bdb-8b12-6bfbf996d4aa" />

Claude Model

Opus

Is this a regression?

I don't know

Claude Code Version

2.1.50

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

View original on GitHub ↗

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