What you're doing
You'll learn the permission modes and pick one, add a rule that keeps Claude away from a secrets file, and write a hook that refuses git push --force, a command that can overwrite the history on GitHub. Then you'll watch the hook fire.
The modes
The bar at the bottom of Claude Code shows the mode you're in. Press Shift + Tab to move between them.
- Manual
- Claude asks before most edits, commands and network requests. Only reading runs without asking. Its setting name is
default. - Accept edits
- File edits and common file commands like
mkdirandmvrun without asking. Other commands still ask. - Plan
- Claude reads and proposes a plan but doesn't edit your files until you approve it (lesson 2).
- Auto
- No routine questions. A separate model checks each action before it runs and blocks anything that goes beyond what you asked. Recent versions start here.
- Bypass permissions
- Skips the questions altogether. Only for throwaway containers or virtual machines, never your own laptop.
Auto mode cuts down on questions, but the official docs say plainly that it doesn't guarantee safety. Rules and hooks are how you make some things never happen, whatever mode you're in.
Steps
Start in Manual mode for this lesson
Terminalcd study-timer claude --permission-mode defaultAsk for any small change and notice that Claude now stops and asks first. Press Shift + Tab a few times and watch the bar change. To make Manual your default on every project, put
"permissions": { "defaultMode": "default" }in~/.claude/settings.json.Add a deny rule
Project settings live in
.claude/settings.json. Create it with this rule, which stops Claude reading a.envfile in your project (where secrets often live):.claude/settings.json{ "permissions": { "deny": [ "Read(./.env)" ] } }Rules come in three kinds: allow, ask and deny. Deny is checked first and wins over everything else. Type
/permissionsto see every rule and which file it came from.Learn what a hook gets
A
PreToolUsehook runs just before Claude uses a tool. Claude Code hands your script a short piece of JSON describing the action. For a terminal command, the command itself is intool_input.command. If your script exits with code 2, the action is blocked, and whatever you printed to the error stream goes back to Claude as the reason.Write the hook script
Make a
.claude/hooksfolder and save the script for your system in it.macOS or Linux: .claude/hooks/block-force-push.sh#!/bin/bash # Stops git push --force before Claude Code runs it. COMMAND=$(jq -r '.tool_input.command // empty') if echo "$COMMAND" | grep -q "push --force"; then echo "Blocked: force-pushing isn't allowed in this project" >&2 exit 2 fi exit 0Windows: .claude/hooks/block-force-push.ps1$callInput = [Console]::In.ReadToEnd() | ConvertFrom-Json $command = $callInput.tool_input.command if ($command -match 'push --force') { @{ hookSpecificOutput = @{ hookEventName = "PreToolUse" permissionDecision = "deny" permissionDecisionReason = "Blocked: force-pushing isn't allowed in this project" } } | ConvertTo-Json } else { exit 0 }The Windows version blocks by answering with a "deny" decision instead of exit code 2. Both are documented ways to block. Each one only catches that exact spelling, which is fine for practice; for a hard rule on a real project, add a deny rule as well.
Get it ready to run
On macOS and Linux the script needs
jqand permission to run:macOS (with Homebrew)brew install jq chmod +x .claude/hooks/block-force-push.shUbuntu or Debiansudo apt install jq chmod +x .claude/hooks/block-force-push.shWindows needs nothing extra; the settings below run the script through PowerShell.
Register the hook
Add a
hookssection next topermissionsin.claude/settings.json. Use the version for your system.macOS or Linux: .claude/settings.json{ "permissions": { "deny": [ "Read(./.env)" ] }, "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-force-push.sh" } ] } ] } }Windows: .claude/settings.json{ "permissions": { "deny": [ "Read(./.env)" ] }, "hooks": { "PreToolUse": [ { "matcher": "Bash|PowerShell", "hooks": [ { "type": "command", "command": "powershell.exe", "args": [ "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-force-push.ps1" ] } ] } ] } }JSON is strict: no trailing commas and no comments. Inside Claude Code, type
/hooks; your hook should be listed underPreToolUse. If it isn't there after a few seconds, restart the session.Test the script by hand (macOS and Linux)
Feed it the same kind of JSON Claude Code would, and check the exit code:
Terminalecho '{"tool_name":"Bash","tool_input":{"command":"git push --force"}}' | ./.claude/hooks/block-force-push.sh echo $?You should see your Blocked: message and then 2. Try it again with
git statusas the command: no message, and 0.Watch it fire
Type into Claude CodeI'm testing a safety hook. Run exactly this command: git push --forceClaude Code stops the command before it runs and shows your reason. The push never happens. Hooks run before the permission mode is even considered, so this holds in every mode.
Commit your guardrails
Commit
.claude/settings.jsonand the.claude/hooksfolder so they travel with the project. Settings just for you go in.claude/settings.local.json, which Git ignores once Claude Code has saved a setting to it.
Exercise
Proof of doneSet your permission mode, add one hook that stops a command you never want run, and prove it fires once.
Want a different command? Ask Claude Code to change the script, then run the hand test and the live test again.
You're done when
- You can name the mode you work in and switch modes with Shift + Tab.
/permissionsshows your deny rule, and/hookslists your hook under PreToolUse.- Claude Code tried to force-push and your hook blocked it with your message.
- The settings file and the hook are committed.
Sources
Read on October 4, 2026.
- Choose a permission mode: the modes and what runs in each, Shift + Tab,
--permission-mode,defaultMode, auto mode as the starting mode on recent versions and its safety warning, bypass mode for isolated machines only. - Configure permissions: allow, ask and deny rules, deny checked first,
Read(./.env),/permissions,.claude/settings.local.json. - Automate actions with hooks: hook input, exit code 2 and the error stream, the
jqrequirement,/hooks, hook locations, hooks running before the permission mode, testing a script by piping JSON into it. - Hooks reference: the Windows PowerShell version with a "deny" decision and the
Bash|PowerShellmatcher.