Parent
Epic: #43
Problem
The current pre_tool_use.sh hook only processes TOOL_NAME == "Bash" for Aho-Corasick text replacement. During manuscript writing, agents use Write and Edit tools. Avoid terms in these tools bypass the hook entirely.
Proposed Change
Extend ~/.claude/hooks/pre_tool_use.sh to handle Write and Edit tool inputs:
Design Decision
For Write/Edit, do NOT silently replace text. Instead, warn by emitting a permissionDecision: "ask" with a message listing the avoid terms found. The human author decides whether to accept or reject.
Implementation
case "$TOOL_NAME" in
"Write")
TEXT=$(echo "$TOOL_INPUT" | jq -r '.content // empty')
;;
"Edit")
TEXT=$(echo "$TOOL_INPUT" | jq -r '.new_string // empty')
;;
esac
if [ -n "$TEXT" ]; then
cd ~/.config/terraphim
RESULT=$(echo "$TEXT" | terraphim-agent replace --role "Publishing Editor" --json 2>/dev/null)
CHANGED=$(echo "$RESULT" | jq -r '.changed // false')
if [ "$CHANGED" = "true" ]; then
REPLACEMENTS=$(echo "$RESULT" | jq -r '.replacements[] | " \(.from) -> \(.to)"')
echo '{"decision": "ask", "message": "Avoid terms detected in manuscript text:\n'"$REPLACEMENTS"'\n\nAccept replacements?"}'
exit 0
fi
fi
Configuration
TERRAPHIM_PUBLISHING_ENFORCE env var (default: warn):
warn: Show avoid-term warnings for Write/Edit, replace silently for Bash
strict: Block Write/Edit if avoid terms found
off: Disable publishing enforcement
Files Changed
~/.claude/hooks/pre_tool_use.sh -- add Write/Edit cases
- New:
~/.claude/hooks/publishing-enforce.sh (extracted logic for testability)
Dependencies
Parent
Epic: #43
Problem
The current
pre_tool_use.shhook only processesTOOL_NAME == "Bash"for Aho-Corasick text replacement. During manuscript writing, agents use Write and Edit tools. Avoid terms in these tools bypass the hook entirely.Proposed Change
Extend
~/.claude/hooks/pre_tool_use.shto handle Write and Edit tool inputs:Design Decision
For Write/Edit, do NOT silently replace text. Instead, warn by emitting a
permissionDecision: "ask"with a message listing the avoid terms found. The human author decides whether to accept or reject.Implementation
Configuration
TERRAPHIM_PUBLISHING_ENFORCEenv var (default:warn):warn: Show avoid-term warnings for Write/Edit, replace silently for Bashstrict: Block Write/Edit if avoid terms foundoff: Disable publishing enforcementFiles Changed
~/.claude/hooks/pre_tool_use.sh-- add Write/Edit cases~/.claude/hooks/publishing-enforce.sh(extracted logic for testability)Dependencies
--role "Publishing Editor"--avoid-mode replace)