Course 04 · Lesson 3 of 8
Hooks: Automations That Run Themselves
Slash commands run when you type them hooks run automatically without you doing anything
A hook is a rule you set once. Whenever a specific event happens inside Claude Code such as a session starting, a session ending, or Claude using a particular tool, the hook fires and runs the instructions you defined.
You do not have to remember to run it. It happens on its own.
The Four Hook Types
Claude Code has four types of hooks. Each triggers on a different event.
PreToolUse fires before Claude uses a specific tool such as before it edits a file or runs a command.
PostToolUse fires after Claude uses a specific tool.
Stop fires when the Claude Code session ends or you press stop.
Notification fires when Claude sends you a notification.
For most automations the two you will use most are Stop which runs something at the end of every session and PostToolUse which runs something after Claude finishes writing a file.
Where Hooks Live
Hooks are configured in your Claude Code settings file at .claude/settings.json.
This file lives either in your project folder at .claude/settings.json which applies to that project only, or in your home folder at ~/.claude/settings.json which applies to all projects.
If neither exists you create it. Ask Claude Code to do this:
- Create a .claude/settings.json file in my home directory with an empty hooks configuration.
- Show me what it looks like.
Hook Structure
A hook configuration looks like this in settings.json:
{
"hooks": {"Stop": [
{"matcher": "",
"hooks": [
{"type": "command",
"command": "echo 'Session ended'"
}
]
}
]
} }
This runs echo 'Session ended' every time a Claude Code session stops. Not very useful by itself but it shows the structure.
The command field is where the real logic goes and it runs a shell command or a script you have prepared.
A Practical Hook: Session Summary
The most useful hook for most people is automatically writing a summary when a session ends.
Create a file called save-progress.sh in your home folder at ~/.claude/save-progress.sh:
#!/bin/bash
PROJECT=$(pwd)
DATE=$(date "+%Y-%m-%d %H:%M")
cat >> "$PROJECT/progress.md" << EOF
---
## Session: $DATE
EOF
Make it executable:
chmod +x ~/.claude/save-progress.sh
Then configure the hook in ~/.claude/settings.json:
{
"hooks": {"Stop": [
{"matcher": "",
"hooks": [
{"type": "command",
"command": "~/.claude/save-progress.sh"
}
]
}
]
} }
Now every time you stop a Claude Code session the date and time are written to progress.md in your project. You can expand on this by having Claude write the actual summary to that file as part of your session wind-down.
A Note for Desktop App Users
If you are using the Claude Code Desktop App and find the hooks configuration confusing there is a simpler path: add the equivalent behaviour to your CLAUDE.md as a standing instruction.
In your CLAUDE.md add this:
## End of Session Rule
At the end of every session, before I stop working, write a brief summary to progress.md:
- What was built or changed
- Any decisions made
- The next step when I return
Claude will follow this instruction every session as a habit. It is not automated in the same way as a hook because you have to explicitly say "we are done," but for most non-developer workflows it achieves the same result without touching JSON configuration.
Your Action Right Now
Choose one of these two paths.
Path A: Add the end-of-session rule to your CLAUDE.md
Open your global ~/.claude/CLAUDE.md and add:
## End of Session
At the end of every working session, create or update progress.md in the current project.
Write: what was done, any important decisions, and what to do next time.
Do this automatically before confirming the session is complete.
Path B: Configure the stop hook in settings.json
Follow the configuration above to set up the automatic timestamp in progress.md.
Either path gives you a persistent record of every session. Pick whichever feels more approachable.
Do it with other builders
Post your homework. Get unstuck.
Every course ends with homework. Post yours in Claude Codex Mastery, the community this course comes from, and get feedback from Yar and 400+ people building the same way.
Join the community · $29/mo