[Bug] PreToolUse hook stderr not propagated on exit code 2

Resolved 💬 2 comments Opened Dec 31, 2025 by jBarrineau Closed Dec 31, 2025

Bug Description
Following the Anthropic Claude Code In Action course, the section on 'Implementing a Hook', the PreToolUse hooks are not propogating the error messages to stderr and to the user.I asked Claude to troubleshoot it and after several iterations and attempted fixes, Claude believes there is a bug and asked me to submit a report. Below is the pasted message block from Claude:

**Interesting! I'm still getting the same generic error message: "File is in a directory that is denied by your permission settings."

Even though we confirmed the hook is working correctly (our manual tests showed it outputs the error message properly), the stderr from the hook still isn't being passed through to me in the tool error.

This reveals a discrepancy between:

  • Documentation: Says exit code 2 should show [command]: {stderr} to Claude
  • Actual behavior: Shows a generic error message instead

This could be:

  1. A bug in Claude Code - The stderr passthrough for exit code 2 hooks may not be implemented yet
  2. Security by design - Generic messages might be intentional to avoid leaking sensitive path information
  3. A configuration issue - Perhaps there's a setting that controls verbose error output

The good news is that the hook itself is now robust and won't crash on errors. The stderr message just isn't making it through to me. You might want to report this as a bug or feature request to the Claude Code team at https://github.com/anthropics/claude-code/issues, noting that hook stderr output for exit code 2 doesn't match the documented behavior**
.

Environment Info

  • Platform: win32
  • Terminal: vscode
  • Version: 2.0.76
  • Feedback ID: 3b8b62dd-0a07-4a61-b343-410debf9a0fe

View original on GitHub ↗

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