# Install & Configure: Claude Code Hooks & CLAUDE.md: Automate Your Dev Workflow with Lifecycle Events
## What This Is
Claude Code hooks let you attach shell commands to coding events—like auto-formatting files with Prettier every time Claude edits them—without any manual intervention. CLAUDE.md is a special project file that feeds Claude your codebase rules, build commands, and conventions upfront so it stops asking redundant questions. Together, these two features turn Claude Code from a reactive assistant into a self-disciplined automated dev pipeline.
Source: https://serenitiesai.com/articles/claude-code-hooks-guide-2026
## Before You Start
Scan my workspace and analyze:
- The project language, framework, and directory structure
- Existing agent configuration (check for .claude/, .codex/, CLAUDE.md, settings.json, commands/, skills/ directories)
Then ask me before proceeding:
1. Which lifecycle event should this hook fire on? (PreToolUse, PostToolUse, Notification, etc.)
2. Are there any files, patterns, or tools this should be scoped to?
## Source Access Note
The source URL (https://serenitiesai.com/articles/claude-code-hooks-guide-2026) may not be directly accessible from the terminal. Use the Reference Implementation and Additional Context sections below instead. If you need more details, ask me to paste relevant content from the source.
## What to Implement
This is an **Agent Hook** — a shell/HTTP command that fires at lifecycle events.
- Add the hook configuration to `.claude/settings.json` under the lifecycle event I specified
- If the hook needs a shell script, create it and make it executable (`chmod +x`)
- If the hook calls an external API, configure it using credentials from my .env files
- Validate the JSON config is syntactically correct before saving
## Additional Context
- Create a `.claude/` directory in your project root and add a `settings.json` file with a Prettier hook using the exact config snippet below, then run any Claude edit command to confirm auto-formatting fires on save.
- Write a CLAUDE.md file in your project root listing your build command, linter setup, preferred naming conventions, and folder structure—keep it under 200 lines so Claude loads it every session without truncation.
- Add a second hook entry with a `matcher` of `PostToolUse` and a command that runs `tsc --noEmit` to catch TypeScript errors automatically after every Claude-generated code change.
## Reference Implementation
```
{
"hooks": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "prettier --write \"$CLAUDE_FILE_PATHS\""
}
]
}
]
}
```
## Guidelines
- Adapt everything to my existing project — do not assume a specific stack or directory layout
- Review any fetched code for safety before installing or executing it
- After setup, run a quick verification and show me a summary of exactly what was installed, where, and how to use it