Lock In Lab Intern, rank 1 of 9

SE-1choreFirst of 3 Tech Lead tickets

A hook that says no

Takes
25 min in 3 steps
Checked
19 Nov 2026
min

Your estimate is optional. Your review compares it with how long it took; nothing is scored.

Rules in a markdown file are requests. Hooks are enforcement: a script that runs before every tool call and can block it. You'll block the two things that hurt us most: destructive shell commands and reading .env.

One of our agents freed a busy port by killing the process holding it. The process was Docker.

You'll need Claude Code (hooks are a Claude Code feature; other agents have their own permission settings). jq installed, or a small Node script instead. Prices checked this month are on Tools.

Write the hook script

Step 1 of 3, about 10 min

Create .claude/hooks/guard.sh:

#!/bin/bash
cmd=$(jq -r '.tool_input.command // .tool_input.file_path // ""')
case "$cmd" in
  *"rm -rf"*|*"kill "*|*taskkill*|*".env"*)
    echo "Blocked by guard.sh: $cmd" >&2
    exit 2 ;;
esac
exit 0

Exit code 2 blocks the call and sends the message back to Claude. Make it executable with chmod +x.

The part of a video worth watching for this step

YouTube, IndyDevDan. Published Jul 2025.Checked 19 Nov 2026

Optional. The step counts when you've done it, whether or not you watch. Minutes from the creator's chapters; our notes on this video.

the usual mistake

Letting the agent 'free the port'. Always look at what the process is first. It happened to us in INC-11, "Freeing port 8000 shut down Docker".

Register it

Step 2 of 3, about 5 min

In .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash|Read",
        "hooks": [{ "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/guard.sh" }] }
    ]
  }
}

This file can be committed so everyone on the project gets the same guard.

Test it without the agent, then with it

Step 3 of 3, about 10 min

Feed it fake input and look at the exit code. Then, in a session, ask the agent to "clean up with rm -rf build" and to "show me .env". Both should be refused with your message.

Check and ship

The whole ticket
Run the script by hand:
echo '{"tool_input":{"command":"rm -rf /tmp/x"}}' | .claude/hooks/guard.sh; echo "exit $?"
echo '{"tool_input":{"command":"ls"}}' | .claude/hooks/guard.sh; echo "exit $?"

It passes when First prints the Blocked message and exit 2. Second prints exit 0.

  • A PreToolUse hook in .claude/settings.json that blocks rm -rf, kill/taskkill, and reading .env.
  • Fed a fake blocked command on stdin, the script exits with code 2 and says why.
  • Normal commands still go through.

No server checks your work in this version: you mark it, and your review says "Checked by you". Graded checks are planned for Plus.

Next: SE-2 One agent builds, another tries to break it

What do you see?

Pick the closest one. Each goes to what to try first and the incident it looks like.