Lesson 5.3 — Harnesses: CLAUDE.md, Permissions, Hooks
Introduction to AI · Module 5: AI Agents · About 75 min · Windows PC, PowerShell 5, Claude Code (Max)
Goal: control how your Folder Tidy agent behaves: standing instructions, a rule it can't break (no deleting), and a one-word command /tidy.
Before you start
Step 1 · Reset the mess (⏱ 0:00–0:05)
dir messy -Recurse -File | Move-Item -Destination messy -Force
Remove-Item messy\Documents, messy\Images, messy\Spreadsheets -Recurse -ErrorAction SilentlyContinue
Remove-Item messy\REPORT.md -ErrorAction SilentlyContinue
.\check.ps1You should see FAIL.
Step 2 · Upgrade CLAUDE.md (⏱ 0:05–0:15)
Open it:
notepad CLAUDE.mdAdd these lines at the bottom, then save:
Style:
- Before moving anything, print a short plan (max 5 lines).
- After PASS, reply with one line: "Tidied N files. PASS."Step 3 · Add a hard rule: no deleting (⏱ 0:15–0:30)
CLAUDE.md is advice. Permission rules are enforced by the harness, whatever the model wants. Paste the whole block:
mkdir .claude -Force | Out-Null
$json = @'
{
"permissions": {
"allow": ["Read", "Glob", "Edit", "Write"],
"deny": [
"Bash(rm:*)", "Bash(del:*)",
"PowerShell(Remove-Item:*)", "PowerShell(rm:*)", "PowerShell(del:*)"
]
}
}
'@
[IO.File]::WriteAllText("$HOME\agent-night\.claude\settings.json", $json)
Get-Content .claude\settings.jsonInside Claude, /permissions shows the active rules.
Step 4 · Test the rule (⏱ 0:30–0:40)
claudeType:
Delete the file messy\a-receipt.pdfYou should see Claude get blocked or refuse (a "denied" message or similar). If it asks permission instead, choose No and note that the rule didn't match the command it tried.
Then **type /exit and press Enter. Wait until you see PS C:\...> before the next command.** Then check the file is still there:
Test-Path messy\a-receipt.pdfYou should see True.
Step 5 · Make a /tidy command (⏱ 0:40–0:55)
mkdir .claude\commands -Force | Out-Null
$cmd = @'
Tidy the messy folder following CLAUDE.md. Run .\check.ps1 at the end and report the result.
'@
[IO.File]::WriteAllText("$HOME\agent-night\.claude\commands\tidy.md", $cmd)
claudeIn Claude, type:
/tidyYou should see a short plan, the moves, then Tidied 12 files. PASS.
Step 6 · Peek at hooks (⏱ 0:55–1:10, optional)
Hooks are scripts the harness runs automatically, e.g. after every file edit. In Claude, type /hooks to see the menu. Just look for now: you'll build one in Module 7.
Write one line: a hook I'd want is .
Then **type /exit and press Enter. Wait until you see PS C:\...> before the next command.**
✅ Pass check
Troubleshooting
| Problem | Fix |
|---|---|
/tidy not found | Check the file is at .claude\commands\tidy.md, then restart claude. |
| settings.json error on start | The JSON is broken. Re-paste Step 3 exactly. |
| Delete wasn't blocked | Claude used a different command form. Ask it "what exact command did you try?" and add a matching deny rule, e.g. "PowerShell(Remove-Item *)". |
| Moves now need approval every time | That's expected for commands not in allow. Approve them, or add "PowerShell(Move-Item:*)" to allow. |
Finish this lesson
Nice work! Pick your next step: