Claude Code Hooks: Auto-Format Every Edit (The Setup Nobody Does) — Transcript
Full transcript
- 0:00Your coding agent just rewrote twelve files in your shop app. Half came back with single quotes, half with double, so you run the formatter by hand, again.
- 0:09You could paste one block into settings dot json instead, and every edit comes out formatted before you look. That's a hook, and almost nobody sets one up.
- 0:18Can't you just write always run prettier in your instructions file? You can, but that file is a request: the agent reads it and usually listens. A hook is a shell command the tool itself runs, every single time, whether the model remembers or not.
- 0:33Picture three moments in your shop app: before the agent uses a tool, after it uses one, and while it's sitting there, waiting on you.
- 0:41That gives you three hooks. After cleans up, before says no, and waiting taps you on the shoulder. The easy mistake is wiring before and after backwards.
- 0:50Hook one is the formatter. Open dot claude, slash settings dot json, in your shop app's project, add a hooks block, and inside it, post tool use. Post means after.
- 1:00The matcher says edit or write, so it only fires when the agent edits or writes a file, not when it reads one in your shop app.
- 1:08The agent hands your hook a little blob of JSON about the edit. J Q pulls out the file path, and prettier rewrites that one file.
- 1:15Now the test: ask it to add a line with single quotes to a JavaScript file in the shop app, then open the file. Double quotes, and the chat shows nothing, because a hook that works is silent.
- 1:25The catch: without prettier installed, N P X quietly downloads the latest version on your first edit, which may not match your shop app. Add this where prettier is already a dependency.
- 1:36Hook two says no. Same file, new key: pre tool use. Pre means before, so it runs while the command is still just a plan.
- 1:45The matcher is bash, and it points at a tiny script. The script reads the command, and if it contains R M dash R F, it prints a reason and exits with code two.
- 1:55Exit two is the whole trick: it blocks the call, and your reason goes back to the agent as feedback, so instead of just failing, it picks a safer route than wiping your shop app.
- 2:05Exit zero doesn't mean approved, though. It means no objection, and your normal permission prompts still apply, so an exit code guard can only ever make things stricter.
- 2:16Test it on purpose, once. A formatter that silently breaks costs you nothing, and a guard that silently breaks costs you your shop app's folder.
- 2:23Hook three is for long runs. This one goes in the settings file in your home folder, so it follows you into every project, and the event is notification, with an empty matcher.
- 2:35The command is one line: osascript on a Mac, notify send on Linux. When the agent needs your permission, or has sat idle for about a minute, your laptop pings you, so you can walk away while your shop app builds.
- 2:47If nothing shows up on a Mac, it's not your hook. Script Editor needs notification permission in System Settings, and macOS never asks for it.
- 2:56Type slash hooks to check. It lists each hook you've set up, grouped by event, so you can see all three are live for your shop app. It's read only, though: to change one, edit the JSON.
- 3:07The rule: before, after, waiting. Anything you check by hand every single time is a hook you haven't written yet.
- 3:14Put the first two in your shop app's project file and commit it, and your whole team gets the same guard rails. All three blocks are in the description.
About this transcript
This page contains the full transcript of Claude Code Hooks: Auto-Format Every Edit (The Setup Nobody Does) by Simple Tech Man, generated from the public captions YouTube serves with the video. The transcript has 638 words across 21 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.