Bash tool output duplicated on non-zero exit code

Resolved 💬 3 comments Opened Mar 4, 2026 by linus-ingage Closed Mar 5, 2026

Description

When a command run via the Bash tool exits with a non-zero exit code, its output is displayed twice in the error block. This happens regardless of whether output goes to stdout, stderr, or both.

Reproduction

Any command that produces output and exits non-zero:

python3 -c "print('hello'); import sys; sys.exit(1)"

Displayed as:

Error: Exit code 1
hello

hello

Additional tests confirm the duplication is not stream-dependent:

  • stdout only (stderr closed) → duplicated
  • stderr only (nothing on stdout) → duplicated
  • os._exit(1) after flush → duplicated

Commands that exit 0 display output once as expected.

Expected behavior

Output should appear once, not twice.

Environment

  • Claude Code CLI
  • macOS (Darwin 24.6.0)
  • Model: claude-opus-4-6

View original on GitHub ↗

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