An agent edits a TypeScript file. The team wants formatting feedback immediately after the edit. Project instructions can ask the agent to run a check. A hook attaches that check to an event the client emits during its own work.

From the edit to a formatting result

In Claude Code, a PostToolUse hook with an Edit|Write matcher runs after a successful call to the matching tool. The handler receives JSON describing the tool and its arguments. For an editing tool, take the path from tool_input.file_path, check the extension, and pass the file to the project’s existing formatting check. The check gets a precise input and can return a precise diagnostic. Claude Code hook examples · Event contract

This hook sees the event from the selected tool. If the agent runs a script in the shell and the script changes several files, an Edit|Write matcher misses those edits. A final check can inspect the diff or run a command for the whole project. The right event depends on whether you need quick feedback for a particular edit or coverage of all changes.

ClientWhere to attach the check
Claude CodePostToolUse with a tool matcher. PreToolUse can intervene ahead of a call, including by rejecting it with exit code 2.
CodexPostToolUse with a matcher for apply_patch or Bash. The local client supports hooks.json and inline configuration. The client loads them from trusted layers and uses /hooks to review new or changed definitions outside managed policy.
CursorafterFileEdit for Agent Chat edits. Inline Tab completions have a separate afterTabFileEdit event.
Gemini CLIAfterTool for the tool result, BeforeTool to make a decision before execution. Each event’s contract defines the effect of the handler’s output.

An after-edit handler sees a file that has already changed. If policy requires rejecting a write ahead of time, attach the check to an earlier event or enforce it with permissions. Check how each event treats crashes, timeouts, and JSON output. In Claude Code, for example, exit code 2 in PreToolUse blocks the call. The same exit code in PostToolUse sends feedback to the model after the action. Claude Code hook exit codes

Events during work and separate runs

A slash command starts an action at the user’s request in chat. A hook responds to an event in the agent loop, such as a completed edit. A scheduler can start a separate run, for example to review open pull requests every day. The machine and app must be running at the scheduled time for a local project task scheduled in the ChatGPT desktop app. Codex slash commands · Scheduled tasks