Files
claude-mem/context/claude-code/exit-codes.md
T
Alex Newman 874815770a fix: Add missing process.exit(0) calls in hook entry points
All 4 hook entry point scripts were missing process.exit(0) after successful
execution, causing Node processes to hang indefinitely instead of returning
control to Claude Code with exit code 0.

Root cause: In commit 6f62a56, process.exit(0) calls were removed from the
hook functions but were never added to the entry point scripts that wrap them.

Fixed files:
- src/bin/hooks/save-hook.ts (PostToolUse)
- src/bin/hooks/new-hook.ts (UserPromptSubmit)
- src/bin/hooks/summary-hook.ts (Stop)
- src/bin/hooks/context-hook.ts (SessionStart)

This restores proper hook exit behavior and prevents Claude Code from waiting
indefinitely for hook completion.
2025-10-18 18:49:11 -04:00

2.5 KiB

Claude Code Hooks Exit Code Cheat Sheet

Exit Code Behavior (1)

  • Exit code 0: Success. stdout is shown to the user in transcript mode, except for UserPromptSubmit hook where stdout is injected as context (1)
  • Exit code 2: Blocking error. stderr is fed back to Claude to process automatically (1)
  • Other exit codes: Non-blocking error. stderr is shown to the user and execution continues (1)

Per-Hook Event Behavior (1)

Hook Event Exit Code 2 Behavior
PreToolUse Blocks the tool call, shows stderr to Claude (1)
PostToolUse Shows stderr to Claude (tool already ran) (1)
Notification N/A, shows stderr to user only (1)
UserPromptSubmit Blocks prompt processing, erases prompt, shows stderr to user only (1)
Stop Blocks stoppage, shows stderr to Claude (1)
SubagentStop Blocks stoppage, shows stderr to Claude subagent (1)
PreCompact N/A, shows stderr to user only (1)
SessionStart N/A, shows stderr to user only (1)
SessionEnd N/A, shows stderr to user only (1)

Quick Reference

  • Success: process.exit(0) - Operation completed successfully
  • Block & feedback: process.exit(2) - Block operation and give Claude feedback via stderr
  • Non-blocking error: process.exit(1) - Show error to user but continue execution

Important: Claude Code does not see stdout if the exit code is 0, except for the UserPromptSubmit hook where stdout is injected as context (1)