feat: add PostToolUse hook for PII redaction in Claude Code#22
feat: add PostToolUse hook for PII redaction in Claude Code#22byapparov wants to merge 2 commits into
Conversation
Adds `hush redact-hook` command that runs as a Claude Code PostToolUse hook, redacting PII from tool outputs before Claude ever sees them. Works standalone or alongside the proxy for defense-in-depth. - `hush redact-hook`: stdin/stdout hook handler using existing Redactor - `hush init --hooks`: generates/merges hook config into settings.json - CLI subcommand routing with dynamic imports (no heavy deps for hooks) - 14 new tests (redact-hook + init integration tests) - README: Hooks Mode section with setup, diagram, comparison table - Team config example updated with defense-in-depth setup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Coverage Report
File CoverageNo changed files found. |
Code Review: PostToolUse Hook for PII RedactionSummaryThis PR adds a Claude Code 1. Redaction Logic ✅Strengths:
Concerns:
2. Streaming Integrity ✅Proxy mode (not in this PR's scope but related):
Hook mode:
3. Security ✅Strengths:
No concerns identified. 4. Reliability
|
| File | Observation |
|---|---|
src/commands/redact-hook.ts:55-65 |
extractText silently ignores unknown fields in tool_output. Consider logging when unexpected fields are encountered for debugging. |
src/cli.ts |
Dynamic imports are a good pattern—keeps hook execution lightweight. |
tests/redact-hook.test.ts |
Good coverage of edge cases (empty stdin, invalid JSON, combined stdout+stderr). |
Verdict
Approve with minor suggestions. The core logic is sound. Consider addressing the 10s timeout and secret length threshold before merging, or document as known limitations.
Reviewed SHA: 1221c38
- Use `tool_response` field (not `tool_output`) matching actual payload - Use `decision: "block"` + `reason` output format (PostToolUse has no outputOverride — confirmed via spec and closed GitHub issues #4635, #18594) - Handle Read tool's nested `file.content` response shape - Add Grep content field test case (10 tests total) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Technical Review: PostToolUse Hook for PII Redaction✅ StrengthsHook Spec Compliance
PII Pattern Coverage
Security
Reliability
Test Coverage
|
|
Superseded by #23 which includes all changes from this PR plus the OpenCode plugin, cloud provider key detection, and GitLab E2E pipeline. |
Summary
hush redact-hook— a Claude CodePostToolUsehook that redacts PII from tool outputs (Bash, Read, Grep, WebFetch) before Claude ever sees themhush init --hooks— generates/merges hook config into.claude/settings.json(idempotent, supports--local)import()so hook commands never load Express/pino/blessedChanges
src/commands/redact-hook.tssrc/commands/init.tssrc/cli.tstests/redact-hook.test.tstests/init.test.tsREADME.mdexamples/team-config/.claude/settings.jsonTest plan
npm run buildcompiles cleanlynpm test— all 44 tests pass (6 files, including 14 new)echo '{"tool_output":{"stdout":"email: test@foo.com"}}' | node dist/cli.js redact-hook→ redacted JSONecho '{"tool_output":{"stdout":"hello world"}}' | node dist/cli.js redact-hook→ no outputnode dist/cli.js init --hooksin temp dir → creates.claude/settings.jsonnode dist/cli.js(no args) → proxy still starts normally🤖 Generated with Claude Code