ITADN

PreToolUse warn-only hooks: stderr output not visible to users

#2082Closedywang-xiazi 创建于 2026-05-28
bugneeds-fixP1
Y
ywang-xiazicommented
## Problem Description Warn-only PreToolUse hooks like `doc-file-warning.js` output warnings to `stderr`, but users cannot see these warnings when `exitCode: 0`. ### Problematic Code (doc-file-warning.js) ```javascript return { exitCode: 0, stderr: '[Hook] WARNING: Ad-hoc documentation filename detected\n' + '[Hook] File: ${filePath}\n' + '[Hook] Consider using a structured path...' }; ``` ### Official Documentation Behavior According to Claude Code official docs: | Exit Code | stderr behavior | User visible? | |-----------|----------------|---------------| | 0 (success) | Written to debug log | No | | 2 (block) | Shown as error message | Yes | | Other non-zero | First line shown, needs --verbose for full | Partial | ### Correct Approach According to official docs, warn-only hooks should use JSON stdout: ```javascript return { exitCode: 0, stdout: JSON.stringify({ systemMessage: '⚠️ WARNING: Ad-hoc documentation filename detected. Consider using a structured path.', hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: 'Warning: Ad-hoc documentation file. Suggest using docs/, .claude/, skills/ etc.' } }) }; ``` ### Affected Hooks The following hooks have the same issue: | Hook | File | Current Output | |------|------|----------------| | doc-file-warning | doc-file-warning.js | Pure stderr | | tmux-reminder | pre-bash-tmux-reminder.js | Pure stderr | | git-push-reminder | pre-bash-git-push-reminder.js | Pure stderr | ### Correct Reference `suggest-compact.js` correctly uses `additionalContext`: ```javascript output({ hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: msg }}); ``` ### Suggestions 1. Modify warn-only hooks to use `systemMessage` or `additionalContext` 2. Or document that these hooks are designed to write to debug log (view with --verbose) --- Environment: Windows 11 Pro, ECC_HOOK_PROFILE=standard
关闭于 2026-05-28 0 条评论