Skip to content

PreToolUse guard shows 'hook error' label — upstream Claude Code bug #2

@Joncik91

Description

@Joncik91

Problem

Every Write or Edit call displays PreToolUse:Write hook error even though the hook runs correctly (exit 0, no output for non-protected files). This is a cosmetic TUI bug in Claude Code, not a bug in our handler.

Evidence

Handler is correct

The guard (hooks/handlers/pretooluse-guard.js) works perfectly in local testing:

# Non-protected file — exits 0, no output (= allow fast path)
echo '{"tool_input":{"file_path":"src/dera/config.py"}}' | node hooks/handlers/pretooluse-guard.js
# Exit code: 0, stdout: (empty)

# Protected file — exits 0, outputs ask decision
echo '{"tool_input":{"file_path":"plugin.json"}}' | node hooks/handlers/pretooluse-guard.js
# Exit code: 0, stdout: {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"ask",...}}

5 fix attempts made (all addressing the wrong root cause)

Commit What was tried
5b54ddd Fix output format, updatedInput at top level
d050fa9 Move updatedInput inside hookSpecificOutput, add permissionDecision: "allow"
908881b Remove permissionDecision: "allow", move updatedInput back to top level
cac01fe Move updatedInput inside hookSpecificOutput again, restore "allow"
7d8e703 Remove all path normalization, simplify to bare minimum

None of these fixed it because the bug is upstream.

Upstream Claude Code issues

  • #17088PreToolUse hook shows 'error' label even for successful (exit 0) hook runs (open, has repro, 9 comments)
  • #16950[BUG] Error: PreToolUse:Write hook error (open)

Current behavior

Write(src/dera/config.py)
  ⎿  PreToolUse:Write hook error     ← misleading label

The file is actually written — the "error" label is cosmetic only.

Impact

  • No functional impact — writes succeed despite the label
  • UX confusion — users (and Claude itself) see "error" and may incorrectly assume the operation failed
  • Wasted effort — 5 commits trying to fix an unfixable upstream bug

Resolution

Blocked on upstream fix. Options:

  1. Wait for Claude Code to fix #17088 (labels: bug, has repro, area:tui)
  2. Remove the PreToolUse hook entirely to eliminate the cosmetic error (loses config protection)
  3. Accept the noise and document it as a known issue

Environment

  • Claude Code: latest
  • Node.js: v22.16.0
  • Platform: Windows 11 (bash shell)
  • Plugin: ucai v1.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions