Hook
Hook
Hooks are deterministic configurations to execute a command, a prompt, a webhook call, etc. when an event is fired during the session runtime.
Events are triggered at various points: a session start (SessionStart),
a user submitting an instruction (UserPromptSubmit),
before a tool execution (PreToolUse), and many other cases (diversity depends on the agent runtime being used).
Typical hook use cases include limiting access to files, guarding commands to avoid destructive actions, telemetry, code linting, or even automatically saving and restoring session memories.
- Format: Claude Code
- Also read by: Copilot (only repository level)
- Deep dive: events, matchers, actions
repository/
└── .claude/
├── settings.json
└── settings.local.json
~/.claude/
└── settings.json
~/.claude/plugins/cache/<marketplace>/<plugin>/
└── hooks/
└── hooks.json{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": ".claude/hooks/lint-check.sh",
"shell": "bash"
},
{
"type": "command",
"command": ".claude\\hooks\\lint-check.ps1",
"shell": "powershell"
}
]
}
]
}
}