Think about the things you do every single time without fail — like always checking your spelling before sending an email. Automatic actions (hooks) are rules that tell Claude Code: "Every time you do X, also do Y." They run automatically, every time, no exceptions.
Why Automatic Actions Matter
The difference between a shortcut (skill) and an automatic action (hook) is simple:
- A shortcut runs when you ask for it — like pressing a speed-dial button
- An automatic action runs by itself, every time its trigger fires — like a smoke detector that always goes off when there's smoke
Real-life example: Auto-formatting
"Every time Claude Code edits a file, automatically clean up the formatting." You never have to think about it — files always look neat.
Real-life example: Safety guard
"Never let Claude Code modify my passwords file or financial records." Even if you accidentally ask it to, the automatic action blocks it.
Real-life example: Notification
"When Claude Code finishes a task and needs my attention, show a desktop notification." Great for when you walk away and let it work.
What this means for you
Automatic actions eliminate the things you'd forget or get tired of doing manually. Set them up once and they work forever — like training an assistant to always double-check their work before showing it to you.
When Do Automatic Actions Fire?
Here are the key moments where you can attach automatic actions. Think of them as "trigger points" — the moments when something happens:
| Trigger | When it fires | Example use |
|---|---|---|
| Session starts | When you open Claude Code | Show today's date, current project status, or a reminder |
| Before a change | Right before Claude Code edits or creates a file | Block changes to protected files, validate the change is safe |
| After a change | Right after Claude Code finishes editing a file | Auto-format the file, run a quick check, log what changed |
| Needs attention | When Claude Code needs your input or permission | Desktop notification so you know to come back |
| Session ends | When you close Claude Code | Save a summary of what was accomplished |
Most Popular Automatic Actions
1. Get a desktop notification when Claude Code needs you
Perfect for when you start a long task and walk away to get coffee. Your computer will ping you when Claude Code needs your attention.
What it does: Shows a popup notification on your screen
When it fires: Whenever Claude Code needs your permission or has a question
2. Protect important files from changes
Create a safety net around your most important files. Even if you accidentally ask Claude Code to edit them, this automatic action blocks it.
What it does: Blocks any edit to files you've marked as protected
When it fires: Before any file change
Protected files: passwords, financial records, configuration secrets
3. Auto-format files after editing
Every time Claude Code edits a file, this automatically cleans up the formatting so your files always look consistent.
What it does: Runs a formatter on any file that was just edited
When it fires: After every file edit
Result: Files always have consistent spacing and formatting
4. Run checks before committing work
Before saving your work to the project history, automatically run tests to make sure nothing is broken.
What it does: Runs your test suite before allowing a commit
When it fires: Before any "save to history" (git commit) action
Result: You never accidentally save broken work
5. Show project context when starting a session
When you open Claude Code, automatically show useful context like what branch you're on and what you were working on last.
What it does: Displays your current project status
When it fires: When you start a session
Result: You always know exactly where you left off
How to Set Up Automatic Actions
Automatic actions are configured in your settings file. You can set them up by editing your settings, or by asking Claude Code to do it for you:
> Set up an automatic action that notifies me whenever you need my attention
> Create a hook that protects my .env file from being edited
> Add an automatic action that formats files after you edit them
Claude Code can set up the hooks for you — just describe what you want in plain English.
What this means for you
You don't need to write any configuration yourself. Just tell Claude Code what automatic behavior you want, and it will set it up for you. You can always review what's set up by typing /hooks.
How Automatic Actions Decide What to Do
When an automatic action fires, it can do one of three things:
| Response | What happens | Example |
|---|---|---|
| Allow | The action proceeds normally | The file check passes, so the edit goes through |
| Block | The action is stopped and Claude Code is told why | The file is protected, so the edit is rejected |
| Allow + add context | The action proceeds, with extra information added | The edit goes through, plus Claude Code is told "this file was recently changed by someone else" |
Where Automatic Actions Are Stored
| Location | Applies to |
|---|---|
| Your personal settings | All your projects |
| Project settings | Just this project (shared with your team) |
| Inside a shortcut or agent | Only when that shortcut or agent is running |
Tips
- Start with notifications — the desktop notification hook is the most universally useful one
- Protect your secrets — set up a hook that blocks edits to password and credential files
- Keep them fast — automatic actions run before or after every action, so they should complete quickly
- Test them — after setting up a hook, do the action it watches to make sure it works
- View them anytime — type
/hooksto see all your configured automatic actions - Ask Claude Code to set them up — just describe what you want in plain English and it will configure the hook for you
Source: ClaudeCodeMastery beginner docs (localhost:3055/docs/hooks), fetched 2026-09-04