Skip to content

Claude Code hooks explained: how to run a command when something happens

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.

Published by Contextingo.

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.

Questions

Good to know.

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.

Nothing learned is lost. Nothing unchecked is done.