Skip to content

fix(security-guidance): output structured JSON so model receives security warnings#29097

Open
4RH1T3CT0R7 wants to merge 1 commit intoanthropics:mainfrom
4RH1T3CT0R7:fix/security-hook-json-output
Open

fix(security-guidance): output structured JSON so model receives security warnings#29097
4RH1T3CT0R7 wants to merge 1 commit intoanthropics:mainfrom
4RH1T3CT0R7:fix/security-hook-json-output

Conversation

@4RH1T3CT0R7
Copy link

Summary

  • The security reminder hook wrote plain text warnings to stderr with exit(2)
  • The model (Claude) never received the security warning in its context — it was only visible in the terminal
  • The hookify plugin demonstrates the correct pattern: output JSON to stdout with hookSpecificOutput.permissionDecision and systemMessage fields

Changes

  • plugins/security-guidance/hooks/security_reminder_hook.py lines 271-273: replaced print(reminder, file=sys.stderr) + sys.exit(2) with structured JSON output to stdout + sys.exit(0)
  • The JSON format matches the hookify plugin's established pattern (rule_engine.py lines 72-79)

Before

print(reminder, file=sys.stderr)   # model never sees this
sys.exit(2)

After

output = {
    "hookSpecificOutput": {
        "hookEventName": "PreToolUse",
        "permissionDecision": "deny"
    },
    "systemMessage": reminder        # model receives this
}
print(json.dumps(output))
sys.exit(0)

Test plan

  • Edit a .github/workflows/*.yml file — Claude should see the security warning in its context and deny the operation
  • Edit a file containing eval( — same behavior
  • Edit the same file again in the same session — warning should NOT repeat (dedup still works)
  • Edit a normal file — should proceed without any output

Fixes #18509

…ings

The hook wrote plain text to stderr with exit code 2, but the model
never received the security warning in its context. The hookify plugin
demonstrates the correct pattern: output JSON to stdout with
hookSpecificOutput.permissionDecision and systemMessage fields.

Switch to stdout JSON with permissionDecision:"deny" and exit 0,
matching the established hook protocol. This ensures Claude sees
security warnings and can act on them.

Fixes anthropics#18509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security reminder should return explicit PreToolUse denial output

1 participant