Bash tool hangs when piped stdin used with npx

Resolved 💬 3 comments Opened Feb 21, 2026 by ierceg Closed Feb 25, 2026

Description

The Bash tool hangs indefinitely when a command receives piped stdin (heredoc or pipe) and is invoked via npx. The child process exits successfully but the Bash tool never reports completion, causing it to be moved to a background task.

Reproduction

Create a minimal test script (/tmp/stdin-test.ts):

const chunks: string[] = [];
process.stdin.on('data', (chunk) => chunks.push(chunk.toString()));
process.stdin.on('end', () => {
  console.log(`Received: ${chunks.join('').trim()}`);
  console.log('Exiting now...');
  process.exit(0);
});

Then in a Claude Code session, run via the Bash tool:

# This WORKS (exits cleanly):
echo "hello" | bun run /tmp/stdin-test.ts

# This HANGS (output appears but Bash tool never completes):
echo "hello" | npx bun run /tmp/stdin-test.ts

# This also HANGS:
cat <<'EOF' | npx bun run /tmp/stdin-test.ts
multi line input
EOF

Key finding

The same commands work perfectly fine outside Claude Code:

#!/bin/bash
timeout 5 bash -c 'echo "hello" | npx bun run /tmp/stdin-test.ts'
echo "Exit code: $?"  # Prints 0, not 124 (timeout)

So the hang is specific to Claude Code's Bash tool process management, not npx or bun.

Pattern

| Command | Piped stdin | Claude Code | Result |
|---------|-------------|-------------|--------|
| bun run | yes | yes | OK |
| npx bun run | no | yes | OK |
| npx bun run | yes | no | OK |
| npx bun run | yes | yes | HANGS |

Impact

In a real session, 21+ background bash processes accumulated from piped stdin commands to a CLI tool invoked via npx bun run. Each command completed successfully (output was printed) but the Bash tool never returned.

Environment

  • macOS Darwin 25.2.0
  • Claude Code (latest as of 2026-02-21)
  • Shell: zsh
  • npm 11.2.0 / npx 11.2.0
  • bun 1.2.4

View original on GitHub ↗

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