claude-code - 💡(How to fix) Fix [BUG] UserPromptSubmit hooks receive empty stdin on Windows — stdin piping broken [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#48009Fetched 2026-04-15 06:35:56
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

On Windows, UserPromptSubmit hook invocations receive empty stdin. This breaks any hook that depends on the hook input JSON passed via stdin by Claude Code.

Error Message

Error Messages/Logs

Root Cause

Root cause hypothesis

One of:

  1. Claude Code on Windows doesn't pipe stdin to UserPromptSubmit hooks (regression or breaking change in hook contract)
  2. The stdin relay through Node.js → cmd.exe → bun.cmd loses the piped data
  3. Windows-specific issue with how stdin is inherited by child processes in the hook system

Fix Action

Workaround

Add the following to settings.json "env": { "CLAUDE_CODE_GIT_BASH_PATH": "C:\Users\YOURUSERNAME\AppData\Local\Programs\Git\bin\bash.exe" } Use "where bash" to locate your bash.exe

Code Example



---

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "tee C:/temp/debug_hook_stdin.json",
            "timeout": 5
          }
        ]
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

UserPromptSubmit hooks receive empty stdin on Windows — stdin piping broken

Environment

  • Claude Code version: 2.1.107
  • OS: Windows 11 Enterprise (10.0.26100)
  • Platform: Win32
  • Node.js version: (used by hook system)

Summary

On Windows, UserPromptSubmit hook invocations receive empty stdin. This breaks any hook that depends on the hook input JSON passed via stdin by Claude Code.

Impact

Plugins and hooks that rely on stdin to receive session ID or other contextual data fail silently. Example:

  • claude-mem plugin uses stdin to receive session_id in UserPromptSubmit hooks, which it needs to initialize sessions. With empty stdin, it falls back to {} and loses all session context, so no observations are ever recorded.
  • Any custom hook or plugin using stdin for UserPromptSubmit will fail the same way

Root cause hypothesis

One of:

  1. Claude Code on Windows doesn't pipe stdin to UserPromptSubmit hooks (regression or breaking change in hook contract)
  2. The stdin relay through Node.js → cmd.exe → bun.cmd loses the piped data
  3. Windows-specific issue with how stdin is inherited by child processes in the hook system

Investigation notes

  • Other hook types may work (SessionStart, PostToolUse, Stop, SessionEnd) — unclear if they have the same issue
  • The bun-runner.js script includes a workaround for Bun's EINVAL on pipes (#646), but it falls back to writing '{}' when no stdin is available, masking the original issue
  • macOS/Linux users likely don't experience this (Unix pipes are more reliable)

Additional context

This affects the claude-mem plugin (v12.1.0), which is completely non-functional on Windows due to this stdin issue. The plugin worker is healthy and MCP tools respond, but no observations are ever collected because session initialization fails.

Relevant stdin handling code:

  • bun-runner.js line 158-188: buffers stdin from Node → Bun, falls back to '{}'
  • Affected hook: UserPromptSubmit hook invocation in Claude Code hook system

Workaround

Add the following to settings.json "env": { "CLAUDE_CODE_GIT_BASH_PATH": "C:\Users\YOURUSERNAME\AppData\Local\Programs\Git\bin\bash.exe" } Use "where bash" to locate your bash.exe

What Should Happen?

Expected behavior

UserPromptSubmit hooks should receive stdin containing JSON with at least:

  • session_id or id (session identifier)
  • cwd (current working directory)
  • prompt (user message text, if present) As per the documented hook input contract for Claude Code.

Error Messages/Logs

Steps to Reproduce

Steps to reproduce

  1. Add a debug hook to ~/.claude/settings.json:
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "tee C:/temp/debug_hook_stdin.json",
            "timeout": 5
          }
        ]
      }
    ]
  }
}
  1. Start a new Claude Code session
  2. Send any prompt (e.g., "hello")
  3. Check the captured file: cat C:/temp/debug_hook_stdin.json

Expected: File contains JSON with hook input (e.g., {"session_id": "...", "cwd": "...", "prompt": "..."})
Actual: File is empty (0 bytes)

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.107

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

No response

extent analysis

TL;DR

The issue can be potentially resolved by setting the CLAUDE_CODE_GIT_BASH_PATH environment variable in the settings.json file to use Git Bash instead of the default shell.

Guidance

  1. Verify the issue: Reproduce the problem using the provided steps to ensure that the UserPromptSubmit hook is indeed receiving empty stdin.
  2. Check the workaround: Apply the suggested workaround by adding the CLAUDE_CODE_GIT_BASH_PATH environment variable to the settings.json file and verify if it resolves the issue.
  3. Investigate stdin handling: Review the bun-runner.js script, specifically lines 158-188, to understand how stdin is being buffered and handled.
  4. Test other hook types: Investigate if other hook types, such as SessionStart or PostToolUse, are also affected by the stdin issue.

Example

No code snippet is provided as the issue is related to environment variables and shell configuration.

Notes

The root cause of the issue is still uncertain, and the suggested workaround may not be the definitive solution. Further investigation is required to determine the underlying cause of the problem.

Recommendation

Apply the workaround by setting the CLAUDE_CODE_GIT_BASH_PATH environment variable, as it may resolve the issue temporarily until a more permanent fix is found.

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…

FAQ

Expected behavior

UserPromptSubmit hooks should receive stdin containing JSON with at least:

  • session_id or id (session identifier)
  • cwd (current working directory)
  • prompt (user message text, if present) As per the documented hook input contract for Claude Code.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING