Back to Skills

agent-hooks

Manage shell hooks — user scripts that run at agent lifecycle points to block, rewrite, or warn on actions, via the /hooks command.

18stars8forksUpdated 7/5/2026

Security Assessment

Safe(100/100)

Detected risks:

Agent-reviewed override(Defensive security-guard hooks framework: rm -rf/mkfs/dd if=/curl|bash are the dangerous commands its pre_tool_call hooks DETECT and BLOCK (e.g. matcher 'rm -rf|dd if=|mkfs', 'Blocked (formats the disk): mkfs.ext4'). Describes dangerous patterns to prevent them, does not run them.)
Security Score100/100

About agent-hooks

agent-hooks manages shell hooks, which are user-provided scripts that run at fixed points in an agent's lifecycle to block a dangerous action, rewrite an input or outbound message, inject context into the model, or warn the user. Scripts can be written in any language and communicate with the agent over a simple JSON-on-stdin, JSON-on-stdout protocol, and are managed through the /hooks command.

Reach for hooks when a user wants the agent to automatically enforce a rule or react to an event without being asked each time, for example blocking destructive rm -rf bash via a pre_tool_call hook, preventing a private key from being pushed to a chat channel via on_outbound_message, logging every tool call via post_tool_call, or forcing a redo when an answer fails a quality check via on_stop. One-off checks are not hooks; hooks are for recurring, automatic lifecycle enforcement.

The skill can install and activate a hook end to end with zero user copy-paste: it writes the script, adds the config entry, and calls a loopback self-approve API that enables the master switch, approves the script for every event it is wired to, and hot-mounts it live without a restart. A critical rule is that both the YAML command and the approval call must use an absolute path under /data/workspace, because a relative path resolves against the server cwd and fails open, silently protecting nothing. The standard install therefore copies templates into /data/workspace/hooks/.

Internally a hook fires only when two gates hold, namely the master switch is on and the event-command pair is approved with the script's recorded mtime, but the self-approve API flips both in one shot so the user never sees them. The skill documents twelve lifecycle events (such as on_user_message, pre_tool_call, pre_llm_call, on_response_end, on_stop, on_outbound_message, and on_completion_claim) and distinguishes the three end-of-turn levers for fixing output, since on_response_end can only rewrite while on_stop and on_completion_claim can force a redo.

FAQ

What can a hook actually do?

Depending on the event, it can block a dangerous action, rewrite an input or outbound message, inject context into the model, append notes to tool results, or force the agent to redo its output.

How do I install and activate a hook?

The skill writes the script and config, then calls a loopback self-approve API that enables the master switch, approves the hook for its events, and hot-mounts it live, with no restart or manual copy-paste needed.

Why must hook script paths be absolute?

Because the bridge spawns scripts with the server's cwd; a relative path resolves to an empty directory and fails open, silently protecting nothing while still appearing mounted.

How many lifecycle events are available?

Twelve, ranging from on_user_message and pre_tool_call to pre_llm_call, on_response_end, on_stop, on_outbound_message, and on_session_end.

Which event should I use to force the agent to redo a bad answer?

on_stop (or on_completion_claim for a /goal) can block and force a redo, whereas on_response_end can only rewrite the reply, not trigger a redo.

All Files

11 files
templates/security_guard_selftest.py7.4 KB
View
templates/verify_commitments.py10.3 KB
View
templates/runtime_footer.py11.7 KB
View
templates/verify_commitments_selftest.py7.0 KB
View
templates/runtime_footer_selftest.py9.9 KB
View
templates/verify_code_changes.py12.2 KB
View
templates/security_guard.py12.9 KB
View
templates/verify_publish_claims_selftest.py10.3 KB
View
SKILL.md35.5 KB
View
templates/verify_code_changes_selftest.py7.8 KB
View
templates/verify_publish_claims.py16.5 KB
View

Install agent-hooks

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill