Windows: Hook system missing TOOL_NAME and EXIT_CODE environment variables
Issue Summary
The Claude Code hook system on Windows (VSCode extension) does not set the TOOL_NAME and EXIT_CODE environment variables that are essential for implementing useful PreToolUse and PostToolUse hooks. This makes it impossible to log which tools are being executed and whether they succeed or fail.
Environment
- Platform: Windows 10 Pro
- Claude Code Version: VSCode extension
- Entry Point:
claude-vscode(fromCLAUDE_CODE_ENTRYPOINTenv var) - SDK Version:
0.1.75(fromCLAUDE_AGENT_SDK_VERSIONenv var) - Shell: Git Bash (MINGW64)
Expected Behavior
According to the Claude Code hook system design:
- PreToolUse hooks should have access to:
TOOL_NAMEenvironment variable containing the name of the tool about to be executed
- PostToolUse hooks should have access to:
TOOL_NAMEenvironment variable containing the name of the tool that was executedEXIT_CODEenvironment variable containing the exit code (0 for success, non-zero for failure)
This allows implementing logging and debugging workflows like:
[14:23:15] PRE: Bash
[14:23:15] POST: Bash (exit: 0) ✓
[14:23:16] PRE: Read
[14:23:16] POST: Read (exit: 0) ✓
Actual Behavior
On Windows:
- ✅ Hooks DO execute successfully
- ❌
TOOL_NAMEenvironment variable is NOT set - ❌
EXIT_CODEenvironment variable is NOT set
This results in hooks having no context about what tool was executed or whether it succeeded, making the hook system essentially useless for debugging and logging purposes.
Steps to Reproduce
1. Configure Hooks
Add to ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [{
"matcher": ".*",
"hooks": [{
"type": "command",
"command": "powershell -Command \"Add-Content -Path 'C:\\Users\\Luke\\.claude\\debug.log' -Value 'PRE: %TOOL_NAME%'\""
}]
}],
"PostToolUse": [{
"matcher": ".*",
"hooks": [{
"type": "command",
"command": "powershell -Command \"Add-Content -Path 'C:\\Users\\Luke\\.claude\\debug.log' -Value 'POST: %TOOL_NAME% (exit: %EXIT_CODE%)'\""
}]
}]
}
}
2. Execute Any Tool
Run any Claude Code command (e.g., ls, echo "test")
3. Check Log Output
Expected:
PRE: Bash
POST: Bash (exit: 0)
Actual:
PRE:
POST: (exit: )
The variables are empty/not set.
Evidence
Testing Iterations
We exhaustively tested multiple approaches to rule out configuration errors:
- ✅ Bash commands - Hooks executed, but path resolution failed on Windows
- ✅ PowerShell with various quote escaping - Hooks executed, variables empty
- ✅ PowerShell script files - Hooks executed, variables empty
- ✅ Windows batch files - Hooks executed, variables empty
- ✅ Full environment dump - Confirmed variables don't exist
Environment Variables That ARE Available
When we dumped ALL environment variables from inside a hook, we found these Claude-specific variables:
CLAUDE_AGENT_SDK_VERSION=0.1.75
CLAUDE_CODE_ENABLE_SDK_FILE_CHECKPOINTING=true
CLAUDE_CODE_ENTRYPOINT=claude-vscode
CLAUDE_PROJECT_DIR=c:\Users\Luke\Documents\Claude Code\hq
Environment Variables That Are MISSING
TOOL_NAME=<not set>
EXIT_CODE=<not set>
We checked for multiple variations:
TOOL_NAME,ToolName,CLAUDE_TOOL_NAME- None existEXIT_CODE,ExitCode,CLAUDE_EXIT_CODE- None exist
Example Log Output
From our testing session:
[23:48:26] PRE:
[23:48:27] POST: (exit: ) ERROR
[23:48:34] PRE:
[23:48:35] POST: (exit: ) ERROR
The hooks execute (timestamps appear), but the variable placeholders are empty.
Impact
Current State
- Cannot implement debugging workflows on Windows
- Cannot log tool execution for troubleshooting
- Cannot track success/failure of tool executions
- Platform disparity if this works on Linux/macOS (unconfirmed)
Use Cases Blocked
- Debugging Claude Code behavior by logging all tool calls
- Tracking tool failures for error analysis
- Building execution metrics
- Creating custom error recovery workflows
- Self-correction based on execution history
Workaround Status
None available. The environment variables simply don't exist.
Questions
- Is this expected behavior?
- Should these variables be set on Windows?
- Is there a platform-specific limitation?
- Does this work on Linux/macOS?
- If yes, this is a Windows-specific bug
- If no, this might be a documentation gap
- Is there an alternative approach?
- Are there other environment variables we should use?
- Is there a different hook mechanism for Windows?
Suggested Fix
If this is a bug, the Windows version should set these environment variables when executing hooks:
PreToolUse:
TOOL_NAME=<name of tool about to execute>
PostToolUse:
TOOL_NAME=<name of tool that executed>
EXIT_CODE=<exit code: 0 for success, non-zero for error>
This would bring Windows hook functionality to parity with the documented behavior and enable powerful debugging/logging workflows.
---
Summary: Hooks execute on Windows but lack the TOOL_NAME and EXIT_CODE environment variables needed for useful logging/debugging workflows. Request confirmation if this is expected behavior or a platform-specific bug that needs fixing.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗