hooks
Guidance for writing safe, fast and clear hooks, with reusable hook examples.
- Kind
- Rules
- Works with
- GitHub Copilot
- Source
- Awesome Copilot @ d85f762d6e52
- Path
- instructions/hooks.instructions.md
- License
- MIT
- Jobs
- Guardrails, Automation
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
# Hook Authoring Guidelines
Hooks are **small, deterministic commands or scripts** that run at specific lifecycle events.
An awesome hook does one clear job, runs quickly, and makes its side effects explicit.
## Folder Structure
A GitHub Copilot hook lives in `.github/hooks/` inside your repository:
```text
.github/
└── hooks/
├── block-dangerous-commands.json ← hook config (which event, which script, options)
└── scripts/
├── block-dangerous-commands.sh ← Bash implementation
└── block-dangerous-commands.ps1 ← PowerShell implementation (optional if Bash-only)
```
You can have multiple `.json` files — each one registers hooks for one or more events. The host loads all of them.
## The Config File
Each `.json` file maps events to an array of hook entries.
- **Command hooks** (`type: "command"`): run a local script. The host passes event JSON on stdin, your script responds through exit code and stdout.
### Config example
```json
{
"version": 1,
"hooks": {
"preToolUse": [
{
"matcher": "bash",
"type": "command",
"bash": "./.github/hooks/scripts/block-dangerous-commands.sh",
…