Hooks, or triggers, are points where you plug your own command into the middle of a code agent's operation. When the event happens, the command runs on its own.

The concept comes from programming in general and today appears in tools like Claude Code, which allows configuring hooks in configuration files.

How it works

The agent works in steps: it receives a request, decides to use a tool, executes, responds. At some of these moments, the tool can call a hook you configured.

Typical events include before using a tool, after using a tool and when finishing a response. The exact names depend on the tool, so consult the official documentation.

The hook receives information about the event and executes a script. This script can only log something, or can block the action, depending on what the tool allows.

The important point is that the hook is normal code. It does not depend on the model interpreting an instruction well.

Practical example

Your team wants every Python file edited by the agent to go through a formatter. Instead of repeating this in the prompt, you create a hook for after editing.

JSON · .claude/settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit",
        "hooks": [{ "type": "command", "command": "ruff format ." }]
      }
    ]
  }
}

The format above is an illustrative example. Check the current schema in the documentation of the tool you use.

Another common use is to block risky commands, like deleting entire folders, before they run.

What it's for

Hooks serve to enforce rules that cannot fail: formatting, tests, secret checking and action logging for audit.

In flows with multiple agents, like those you organize in bridgecode, hooks help maintain the same quality standard regardless of which agent did the task.

Difference between hooks and slash commands

Slash commands are shortcuts you type to trigger an instruction. Hooks trigger on their own because of an event. One depends on you calling it, the other happens automatically.