# Claude Code hooks explained: run a command on an event

Canonical: [Claude Code hooks explained: run a command on an event](https://contextingo.com/blog/claude-code-hooks-explained)

Locale: en

Purpose: Hooks run your own commands at set points in a Claude Code session, such as before a tool call or when the session ends. What they are good for and the risks.

Content updated: 2026-10-19

Source revision: content.ts 2026-10-19

Maintenance owner: the Contextingo site owner

[Topic map](https://contextingo.com/llm/topics/blog.md) · [Complete scoped map](https://contextingo.com/sitemap.md)

Claude Code hooks are shell commands that the tool runs for you at defined points in a session. Because the tool runs them, not the model, they are a dependable way to make something happen every time.

## Typical events

- Before a tool is used, where a hook can inspect and block the call.
- After a tool is used, for example to run a formatter on an edited file.
- When the session starts.
- When the agent finishes a response.

## Good uses

- Format or lint files after an edit.
- Block commands that touch protected paths.
- Remind the agent to save a checkpoint after a commit.
- Log what happened for audit.

## Risks

- A hook runs with your rights. Read a hook before you install it.
- A slow hook slows every session.
- A hook that fails silently gives a false sense of safety.

## In this product

The setup command for Contextingo installs a hook that reminds Claude Code to save knowledge as it works, and to leave a checkpoint after a commit or push that has none. Configuration details are in the Claude Code documentation.

See also [a handover that survives the chat](/guides/hand-off-claude-code-task-to-teammate).

## Questions

### Are hooks the same as instructions in CLAUDE.md?

No. Instructions are read by the model, which may or may not follow them. Hooks are run by the tool every time.

### Where are hooks configured?

In Claude Code’s settings files. Check its documentation for the current format.
