Skip to content

Commit 67a2c49

Browse files
nhortonclaude
andcommitted
Fix hook exit code to always return 0 with JSON format
Hooks using JSON output format should always exit with code 0. The blocking behavior is controlled by the "decision" field in the JSON output, not the exit code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 56ae120 commit 67a2c49

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/deepwork/hooks/wrapper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ def run_hook(
358358
output_json = denormalize_output(hook_output, platform, hook_input.event)
359359
write_stdout(output_json)
360360

361-
# Return exit code based on decision
362-
if hook_output.decision in ("block", "deny"):
363-
return 2
361+
# Always return 0 when using JSON output format
362+
# The decision field in the JSON controls blocking behavior
364363
return 0

tests/shell_script_tests/test_hook_wrappers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ def test_claude_wrapper_with_stop_event(
209209
env=env,
210210
)
211211

212-
assert result.returncode == 2, f"Expected exit code 2 for blocking. stderr: {result.stderr}"
212+
# Exit code 0 even when blocking - the JSON decision field controls behavior
213+
assert result.returncode == 0, f"Expected exit code 0. stderr: {result.stderr}"
213214

214215
output = json.loads(result.stdout.strip())
215216
assert output["decision"] == "block"
@@ -242,7 +243,8 @@ def test_gemini_wrapper_with_afteragent_event(
242243
env=env,
243244
)
244245

245-
assert result.returncode == 2, f"Expected exit code 2 for blocking. stderr: {result.stderr}"
246+
# Exit code 0 even when blocking - the JSON decision field controls behavior
247+
assert result.returncode == 0, f"Expected exit code 0. stderr: {result.stderr}"
246248

247249
output = json.loads(result.stdout.strip())
248250
# Gemini should get "deny" instead of "block"

0 commit comments

Comments
 (0)