1
0
Fork 0
claude-code-hooks/CLAUDE.md
2026-03-30 10:38:57 +02:00

51 lines
1.9 KiB
Markdown

# Hooks: Run Code When Claude Code Acts
## What this project is
A companion repo for the From AI to Chitta article on **Hooks**
(concept ID: `CC-024`). It contains working hook scripts and exercises
that let you set up real guardrails and audit logging in Claude Code.
Article: https://fromaitochitta.com/cc-024
## How to use this
1. Open Claude Code in this directory: `cd claude-code-hooks && claude`
2. Work through exercises in order: `exercises/01-block-danger.md`, then 02, then 03
3. Each exercise has concrete steps with expected output
4. Compare your results to the expected output described in each exercise
## What is configured
- **Pre-tool-use hook** (`hooks/pre-tool-use.sh`): Blocks a set of dangerous
shell commands before Claude executes them. Reads JSON from stdin, matches
against blocked patterns, exits 2 to block or 0 to allow.
- **Post-tool-use hook** (`hooks/post-tool-use.sh`): Logs every tool call to
`hooks/audit.log` with a timestamp, tool name, and input summary.
- **Settings** (`.claude/settings.json`): Wires both hooks into Claude Code.
## Code quality expectations
- This is a learning repo. Clarity over cleverness.
- Every exercise must run without modification on a clean clone
- No external dependencies beyond Python 3 (standard on macOS)
- If something does not work as expected, that is useful information: note it
## Project structure
```
hooks/ pre-tool-use.sh, post-tool-use.sh, audit.log (generated)
exercises/ Three numbered exercises with steps and expected output
.claude/ settings.json with hook configuration
CLAUDE.md This file: project instructions
README.md Overview for anyone who clones this repo
```
## Domain
Claude Code Automation
## Memory
Keep session notes in a local `MEMORY.md` (gitignored). This file
(CLAUDE.md) is for instructions. MEMORY.md is for state.