Leanpub Header

Skip to main content

The Claude Code Safety Field Manual

A free, verified guide to Claude Code hooks: which PreToolUse or PostToolUse matcher can refuse a tool call, what to check when a hook is not working, and how to prove a guard actually fires.

The Claude Code Safety Field Manual
This book is 100% completeLast updated on 2026-09-15

Installing safety hooks for Claude Code takes about thirty seconds. Proving they actually refuse anything is the step almost everyone skips — and an unverified guard looks exactly like a working one. Free: the pre-flight checklist, which event can refuse a tool call and which only watches, how to make a guard fire on purpose, what a broken hook does, and a catalogue of all 915 example hooks in cc-safe-setup.

Minimum price

Free!

$1.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

You leave Claude Code running while you do something else. You come back and something is gone. That is the moment this manual is written against. Hooks can stop the common ways it happens: a recursive delete, a hard reset, a secret going into a commit. Installing them takes about thirty seconds. But an installed guard and a working guard look identical from the outside, and almost nobody checks which one they have. This is that check, written out.

Chapter 1 — the pre-flight checklist. Four stages you can copy into your project: before the first session, before letting it run unattended, during, and after.

Chapter 2 — measure before installing. The audit is read-only. Nine findings on an empty project is a baseline, not a crisis; what matters is which of them are still there a week later.

Chapter 3 — what the guards actually refuse. The block messages, taken from the shipped hook definitions rather than from the documentation, followed by a section on what a hook cannot see at all.

Chapter 4 — prove they fire. Feed a guard the input it is supposed to refuse, and watch what comes back.

Chapter 5 — the npm package is the wrong one. It is frozen at 29.8.0 (2026-04-20). Fired against forty-one command shapes, twenty-five that the current code refuses are let through by the version npm serves, and nothing goes the other way. The obvious install command is the one that gets you that version.

Chapter 6 — after the session. An empty log of blocked commands means either that nothing dangerous was attempted or that nothing is matching, and from the outside those look the same.

Chapter 7 — which event can even stop a call. Only a `PreToolUse` hook can refuse. A `PostToolUse` hook is a witness: by the time it runs, the file is written and the branch is already reset. A guard wired to the wrong event is a guard that logs your loss.

Chapter 8 — an audit of the collection this book accompanies, and it is not flattering. Of the 915 example hooks in the repository, 609 cannot refuse anything on any path. They warn, they count, they log. That is a reasonable thing for a hook to be, and it stops being reasonable the moment you install one expecting a door.

Chapter 9 — what a broken hook does. It has two behaviours, not one, and which you get depends on how it broke. One is loud. The other is silent, and the silent one is the failure mode of the defensive line most people put on line 2. A hook that dies is a hook that said yes.

Chapter 10 — the catalogue. Every one of the 915 scripts, with the two facts you want before installing anything and cannot get from the filename: when it runs, and whether it can refuse.

Chapter 11 — what `--dangerously-skip-permissions` actually skips. The question behind every phrasing of it is the same: if I run with that flag, have I turned off everything I set up? Measured with the flag on, against the same guards, rather than argued from the documentation.

Appendix A — a citation index. 353 of the scripts name at least one issue number, covering 487 distinct issues. Given a number, it tells you which scripts cite it. It does not paraphrase the issues, because a paraphrase of an issue nobody re-read is how a book starts being wrong.

Every command output printed in Chapters 1 to 6 came from a clean sandbox, and the output you see is the output that came back. From Chapter 7 onward some numbers come from the author's own machine and from counting the repository — where that is the case, the text says so. Where a command fails, the failure is printed too, because a check that cannot fail is not a check.

It is the companion to cc-safe-setup, an MIT-licensed tool, and everything in it is also in that repository. You are not paying for secrets — and at a minimum price of zero, you are not paying at all. What you get is the parts that matter, in the order you need them.

What it is not: a guarantee. A hook sees one tool call at a time; it does not see intent. Chapter 3 says where the floor ends, and Chapter 8 says how much of the collection is standing on it. If you want a book that tells you your agent is now safe, this is not that book.

This manual is free and it stays free. Installing the guards is a different job and a different book. Claude Code Safety Mastery has the hooks themselves — git, credentials, token spikes, autonomous operation, multi-agent work — a chapter on hooks that do not fire, eight dated incidents where the guard failed silently, and the 50-point audit checklist, which is itself free and MIT-licensed in the repository. If you would rather work from the accident than from the mechanism, Claude Code Safety is arranged that way: four irreversible failures, and for three of them the hook that blocks the command before it runs. All seven of these books — the two above, this manual, and the four in the Operator's Library — are also sold together as Claude Code Operator's Library: Complete Edition: $39 against $74.94 bought separately.

Bundle

Bundles that include this book

Author

About the Author

yurukusa

Everything I publish starts from something that actually broke.

I run Claude Code on real projects, often unattended, and I have lost work to it. Most of what the books catalogue did not happen to me, though. It happened to other people, in public: every incident is tied to a numbered issue you can open and read, including the ones that were closed without a fix. The hooks in cc-safe-setup (MIT, open source) exist because I wanted a floor under an agent nobody was watching, and I would rather show you a stranger's incident with a link than a story of my own without one.

Two things I hold myself to. If a number in one of my books is not something I measured, it says so. And if a command is printed, the output beside it came back from an actual run — failures included, because a check that cannot fail is not a check.

I am not selling certainty. Most of what I know here, I learned by breaking my own setup.

Contents

Table of Contents

What this manual checks, and what it does not (Preface)

  1. How it is arranged
  2. Who this is for

A pre-flight checklist for leaving Claude Code running unattended (Chapter 1)

  1. Before your first session
  2. Before letting it run unattended
  3. During the session
  4. After the session
  5. For a team

How to audit your Claude Code setup before installing anything (Chapter 2)

Which of the default hooks can actually block a command (Chapter 3)

  1. What this list does not cover

How to prove your Claude Code hooks actually fire (Chapter 4)

Why npx cc-safe-setup installs an outdated version, and what to run instead (Chapter 5)

What to check after a Claude Code session ends (Chapter 6)

Which hook event can stop a tool call, and which only watches (Chapter 7)

  1. What the repository actually uses
  2. What each event can and cannot do
  3. When the thing you are afraid of never reaches an event
  4. The practical rule

How to tell whether your hooks can actually refuse anything (Chapter 8)

  1. The count
  2. Having a refusal is necessary, not sufficient
  3. The name is not the answer
  4. What that leaves you with
  5. How to check yours, in one command
  6. The rule

What happens when a Claude Code hook is broken or not working (Chapter 9)

  1. The contract, and where it applies
  2. What actually comes out
  3. The first table assumes your hook has a shebang
  4. The one that will actually get you
  5. The defensive line that changes the answer
  6. Check yours

A catalogue of every hook in cc-safe-setup: which event each runs on, and whether it can refuse (Chapter 10)

  1. Safety Guards
  2. Auto-Approve
  3. Quality
  4. Agent Controls
  5. Monitoring
  6. Recovery
  7. UX
  8. Other
  9. Uncategorised

What —dangerously-skip-permissions actually skips, and what still stops you (Chapter 11)

  1. The short answer
  2. How I checked
  3. The other layer: permissions.deny
  4. The interactive observation, and what it is worth
  5. What this does not prove
  6. Check yours in about a minute
  7. The part that should still worry you

Which GitHub issue each hook answers (Appendix A)

Afterword

  1. How this book was made

Also by the Author

Also by the Author

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub