Defra PII redaction — intercepts all LLM interactions (prompts, tool inputs, tool outputs) and redacts UK PII using a Python script before data reaches or leaves the model. Use when the agent is operating in an environment where PII must never appear in LLM context.
Ships in defra-pii-redaction. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This plugin provides three deterministic guardrail hooks that intercept all data flowing to and from the LLM and redact UK PII using an external Python script.
| Hook | Event | What happens |
|---|---|---|
pii-redact-prompt | UserPromptSubmit | Prompts containing PII are blocked — Claude Code cannot replace prompt text, only block |
pii-redact-pre | PreToolUse | PII in tool inputs is redacted before the tool executes |
pii-redact-post | PostToolUse | PII in tool outputs is redacted before the results are fed back into LLM context |
All three hooks are synchronous and blocking — execution does not proceed until redaction is complete.
Claude Code's hook API does not support replacing prompt text. When a prompt contains PII, the hook returns {"decision": "block"} with a human-readable reason asking the user to rephrase without personal data. Clean prompts exit 0 with no output and proceed normally.
Redaction is delegated to scripts/redact_pii.py inside the plugin directory. The script:
UserPromptSubmit: returns a block decision if PII is detected; exits 0 silently for clean promptsPreToolUse: returns hookSpecificOutput.updatedInput with PII replaced; exits 0 silently for clean inputsPostToolUse: returns hookSpecificOutput.updatedToolOutput with PII replaced; exits 0 silently for clean outputsThe plugin resolves the script path using ${PLUGIN_ROOT:-$CLAUDE_PLUGIN_ROOT}. Copilot CLI sets PLUGIN_ROOT and Claude Code sets CLAUDE_PLUGIN_ROOT automatically to the plugin's install directory; the fallback lets the same hook command work on either host. If the script cannot be found, the hook degrades gracefully by passing the data through unmodified.
Windows note: hook commands use POSIX shell parameter expansion (
${PLUGIN_ROOT:-$CLAUDE_PLUGIN_ROOT}), so both Copilot CLI and Claude Code must invoke them through a POSIX-compatible shell (e.g. Git Bash or WSL). Under a nativecmd.exe/PowerShell session without such a shell available, the variable will not expand,uv runwill fail to find the script, and the hook will silently degrade to pass-through (no redaction, no error).
PATHjq available on PATHWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
/defra-pii-redaction:defra-pii-redactionfrom defra-pii-redaction
npx claudepluginhub defra/defra-ai-plugins --plugin defra-pii-redaction