OpenWriterControle/plugins/claude-code/scripts/context/openagents-repo/concepts/hooks-system.md
Darren Hinde a8fc9c7715
feat(plugin): enhance context management and skill invocation (#239)
* fix(shellcheck): declare and assign separately in router.sh (SC2155)

* feat(plugin): enhance context management and skill invocation

- Update .context-manifest.json to include profile and detailed source information.
- Revise context-scout.md to clarify context root discovery and navigation.
- Modify commands to replace deprecated skills with updated ones (brainstorming → approach, systematic-debugging → debugger).
- Streamline install-context.md for clarity and remove interactive profile selection.
- Improve oac-status.md to provide a more comprehensive status report.
- Add OAC system paths to session-start.sh for better context management.
- Remove obsolete skills and improve documentation for existing commands.
2026-02-23 12:12:29 +00:00

66 lines
1.7 KiB
Markdown

<!-- Context: openagents-repo/concepts | Priority: critical | Version: 1.0 | Updated: 2026-02-15 -->
# Hooks System
**Purpose**: User-defined shell commands that execute at Claude Code lifecycle points
---
## Core Concept
Hooks provide **deterministic control** over Claude Code's behavior. Unlike prompting (which suggests), hooks **guarantee** certain actions happen at specific points in the workflow.
---
## Key Points
- Hooks are shell commands triggered by events
- Run automatically during agent loop with your credentials
- Can block operations (exit code 2), allow silently, or provide feedback
- Configure in `settings.json` or plugin's `hooks/hooks.json`
- Matchers filter which tools/events trigger the hook
---
## Common Use Cases
| Use Case | Event | Example |
|----------|-------|---------|
| Auto-format | `PostToolUse` | Run prettier after Edit/Write |
| Notifications | `Notification` | Desktop alert when input needed |
| File protection | `PreToolUse` | Block edits to .env files |
| Logging | `PreToolUse` | Track all bash commands |
| Feedback | `PostToolUse` | Lint check after code changes |
---
## Quick Example
```json
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "jq -r '.tool_input.command' >> ~/.claude/bash-log.txt"
}]
}]
}
}
```
---
## Security Warning
Hooks run with your credentials. Malicious hooks can exfiltrate data. Always review hook implementations before adding them.
---
## Related
- `../lookup/hook-events.md` - All hook events
- `../examples/hooks/` - Hook examples
**Reference**: https://docs.anthropic.com/en/docs/claude-code/hooks