ATLAS ROOM
← Home
🪝HOOKS

Claude tests your code on its own

Hey! 👋 Here's what I promised you:

Claude Code Hooks — commands that run automatically with every step Claude takes: it edits, and the hook tests right after — without you telling it to. These are the two hooks I use myself:

- ON EDIT → any code you edit gets test + lint run on it automatically.

- PRE-COMMIT → before any commit, it checks whether there's any secret / password / API key in the files — if it finds something, it blocks the commit so you don't break anything.

🔗Official docshttps://code.claude.com/docs/en/hooks

How to start

  1. Add this to your project's `.claude/settings.json` (replace `npm test && npm run lint` with your project's commands):
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "npm test && npm run lint" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "git diff --cached | grep -qiE 'api[_-]?key|secret|password' && echo 'STOP: secrets f staged files!' >&2 && exit 2 || exit 0" }
        ]
      }
    ]
  }
}
`exit 2` is what blocks: Claude stops and reads the error message.
  1. Add the rule to your project's `CLAUDE.md` so it becomes a habit for Claude:
Any code you write or edit, run the tests before you consider the task done.
Big changes = test the whole workflow.
  1. Try it: ask Claude to edit a file — you'll see the tests run on their own right after. ✅