claude-code - 💡(How to fix) Fix [BUG] Git Bash on Windows: piped commands hang, stdout never captured [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#53143Fetched 2026-04-26 05:23:19
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

On Windows 11 / Git Bash, Bash tool calls that pipe a short-lived command into another (e.g. node script.js 2>&1 | tail -60) are surfaced as background tasks but stdout never reaches the task output file. The file stays at 0 bytes indefinitely even though the underlying process runs to completion. TaskOutput blocks until timeout and reports running forever. Stuck task IDs accumulate across the session.

Appears to share root cause with several prior issues, but with a different failure shape — instead of immediate exit 1 / Bad file descriptor with empty output, the call hangs and is displayed as a background task that never completes.

Root Cause

Appears to share root cause with several prior issues, but with a different failure shape — instead of immediate exit 1 / Bad file descriptor with empty output, the call hangs and is displayed as a background task that never completes.

Fix Action

Fix / Workaround

Working workaround

Redirect inside the command and read the log file directly:

node tests/run-state-tests.js > /tmp/state-test-out.log 2>&1; echo "EXIT=$?"

Output appears as expected. Bug is specifically in how Bash-tool stdout is captured when a piped command is promoted to a background task.

Impact

  • Forces a redirect-and-poll workaround on every test/build invocation that pipes
  • Multiple stuck task IDs accumulate per session
  • Breaks the standard "run tests, parse output" agent loop

Code Example

node tests/run-state-tests.js 2>&1 | tail -60

---

node tests/run-state-tests.js > /tmp/state-test-out.log 2>&1; echo "EXIT=$?"
RAW_BUFFERClick to expand / collapse

Summary

On Windows 11 / Git Bash, Bash tool calls that pipe a short-lived command into another (e.g. node script.js 2>&1 | tail -60) are surfaced as background tasks but stdout never reaches the task output file. The file stays at 0 bytes indefinitely even though the underlying process runs to completion. TaskOutput blocks until timeout and reports running forever. Stuck task IDs accumulate across the session.

Appears to share root cause with several prior issues, but with a different failure shape — instead of immediate exit 1 / Bad file descriptor with empty output, the call hangs and is displayed as a background task that never completes.

Environment

  • Claude Code CLI (Opus 4.7) on Windows 11 Home (10.0.26200)
  • Shell: Git Bash (MSYSTEM=MINGW64), bash --version: 5.3.9
  • CLAUDE_CODE_SHELL is unset; CC is correctly defaulting to Git Bash (/usr/bin/bash resolves into MINGW64, not WSL bash). So this is not the WSL-bash-picked-by-accident failure mode from #26430.

Repro

node tests/run-state-tests.js 2>&1 | tail -60
  • Expected: ~10s runtime, prints test summary, exits 0.
  • Actual: tool returns "Command running in background with ID …", output file stays empty, TaskOutput blocks 30s+ and reports running even after the underlying process has exited.

Working workaround

Redirect inside the command and read the log file directly:

node tests/run-state-tests.js > /tmp/state-test-out.log 2>&1; echo "EXIT=$?"

Output appears as expected. Bug is specifically in how Bash-tool stdout is captured when a piped command is promoted to a background task.

Impact

  • Forces a redirect-and-poll workaround on every test/build invocation that pipes
  • Multiple stuck task IDs accumulate per session
  • Breaks the standard "run tests, parse output" agent loop

Frequency

Every invocation of a piped short command in affected sessions. Reproducible.

Prior art

Currently open:

  • #31449 — VS Code extension: Bash tool does not capture stdout. Related, but affects the VSCode extension specifically. This report is for the CLI on Windows, where the failure shape is different (hang as background task vs. popup terminal window).

Closed without fix:

  • #21915 — original "Bash tool produces no output on Windows"
  • #26430 — closed NOT_PLANNED for inactivity. Comments document the same root cause and note that npm install -g @anthropic-ai/claude-code fixed it for at least one user where the native installer / winget binary did not.
  • #25558 — CLAUDE_CODE_SHELL environment variable ignored on Windows; closed NOT_PLANNED
  • #36915 — auto-closed as duplicate of #31449
  • #20236 — TaskOutput hangs after task completes

Closed as completed (different failure shape):

  • #26413 — Bash tool: all commands fail with Bad file descriptor on Windows; closed COMPLETED. The fix shipped for the immediate-failure case, but the regression reported here (hang as a background task that never completes) was not covered.

extent analysis

TL;DR

The issue can be worked around by redirecting output inside the command and reading the log file directly, as shown in the provided workaround.

Guidance

  • The bug appears to be related to how Bash-tool stdout is captured when a piped command is promoted to a background task.
  • To verify the issue, run the repro command node tests/run-state-tests.js 2>&1 | tail -60 and check if the output file stays empty and TaskOutput blocks.
  • The provided workaround node tests/run-state-tests.js > /tmp/state-test-out.log 2>&1; echo "EXIT=$?" can be used to bypass the issue.
  • Investigate the differences between the working workaround and the original command to understand the root cause of the issue.

Example

The working workaround example node tests/run-state-tests.js > /tmp/state-test-out.log 2>&1; echo "EXIT=$?" demonstrates how to redirect output and read the log file directly.

Notes

The issue seems to be specific to the Claude Code CLI on Windows 11 with Git Bash, and the root cause may be related to the interaction between Bash-tool and the shell.

Recommendation

Apply the workaround by redirecting output inside the command and reading the log file directly, as it provides a reliable way to bypass the issue and obtain the expected output.

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