Stderr/Stdout Interleaving Broken in Claude Code's Bash Tool Execution

Status Closed — not planned
Maintainer reply None cached
Activity 4 comments · opened Jun 29, 2025 · closed Dec 10, 2025

Bug Description
Claude Code's bash tool does not preserve interleaving of stdout and stderr. If you print to unbuffered stdout and stderr from Go with out1/err1/out2/err2 pattern, you get out1/out2/err1/err2, and this can cause confusing behavior when a tool uses both out and err channels and does correct line buffering / flushing.

Environment Info

  • Platform: darwin
  • Terminal: vscode
  • Version: 1.0.33
  • Feedback ID: 5df98393-266f-46d9-ac30-90fc2794d4c7

Test Program

interleave.go:

package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Fprintln(os.Stdout, "stdout line 1")
	fmt.Fprintln(os.Stderr, "stderr line 1")
	fmt.Fprintln(os.Stdout, "stdout line 2")
	fmt.Fprintln(os.Stderr, "stderr line 2")
}

Run in claude: !go run ./interleave.go

Outputs:

stdout line 1
stdout line 2
stderr line 1
stderr line 2

But it should output:

stdout line 1
stderr line 1
stdout line 2
stderr line 2

Workaround:

!go run ./interleave.go 2>&1

View original on GitHub ↗

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