Home › All prompts › Claude Code Guardrails

Mini pack

Free

Claude Code Guardrails

Tired of writing "NEVER do this" in CLAUDE.md and watching Claude Code do it anyway? These 10 free prompts help you see what Claude Code can do without asking, add permission rules that say no or ask first, set up hooks that run every time, and test it all before you rely on it.

Hooks and permission rules that actually enforce your rules, so the agent asks first, stays out of your secret files, and can't skip the checks you set.

10 prompts in 4 sections. Replace everything in [BRACKETS IN CAPS], then copy and paste into your AI tool.

Download the free PDF

PDF, 18 pages

Written for use with

  • Claude Code: all 10 prompts go to a Claude Code session opened in your project. Permission rules (allow, ask, deny, checked in that order), settings file locations, hook events (PreToolUse, PostToolUse, Stop), matchers, and exit code 2 were checked against the Claude Code permissions, settings, and hooks docs.
  • Honest limits: the pack says what each guardrail won't catch, as the docs do: Bash rules match command text, Read deny rules don't cover scripts that open files themselves, and PostToolUse hooks can't undo an action. The built-in sandbox (/sandbox, macOS, Linux, and WSL2) is mentioned as the next layer.
  • Safety net: Prompt 4.1 uses a git branch as the main undo, with /rewind as an extra, since the checkpointing docs say files changed only by shell commands aren't tracked.

Written for use with Claude Code. Not yet tested against it.

All 10 prompts

  1. 1.1 Guardrail Check-Up: What Can You Do Without Asking Me?
  2. 1.2 Turn My CLAUDE.md "Never" Rules Into Real Rules
  3. 2.1 Lock Away My Secret Files
  4. 2.2 Make Risky Commands Ask Me First
  5. 3.1 Explain Hooks and Pick 3 for My Project
  6. 3.2 Run My Formatter or Linter After Every Edit
  7. 3.3 Block Edits to My Protected Files
  8. 3.4 Don't Say "Done" Until the Tests Pass
  9. 4.1 Save a Checkpoint Before Risky Work
  10. 4.2 Test My Guardrails Without Breaking Anything

Section 1: See What the Agent Can Do Today

1.1 Guardrail Check-Up: What Can You Do Without Asking Me?

Untested: not yet run against a model.

Use this when you've been using Claude Code for a while and aren't sure what it's allowed to do on its own anymore. It's for a plain-English list of every rule and hook that's active in this project, and where each one comes from.

Use in: Claude Code, opened in your project. Start in plan mode (press Shift+Tab until the status bar shows it) so nothing gets changed.

Fill in: [WHAT WORRIES ME MOST] (e.g. "deleting files, pushing to main, touching my .env file").

I want a check-up of your guardrails in this project. Don't change any files. Just read and report.

What worries me most: [WHAT WORRIES ME MOST]

Please:
1. Find every Claude Code settings file that applies here: ~/.claude/settings.json, .claude/settings.json, and .claude/settings.local.json. For each one, say whether it exists and whether it's committed to git.
2. List every permission rule in them as a table: rule, allow / ask / deny, which file it's in, and what it means in one plain line.
3. List every hook: which event it runs on, its matcher, what the command does, and which file it's in. If a hook runs a script, read the script and explain it in two lines.
4. Point out any allow rule that looks too broad for what worries me most, like a rule that lets every Bash command run without asking.
5. Tell me which worries are NOT covered by any rule or hook yet.
6. Remind me how to see the same list myself with /permissions and /hooks.
End with the top 3 changes you'd suggest, but don't make them.

Tips to customize: Clicking "Yes, and don't ask again" on a Bash command saves a rule to .claude/settings.local.json for that repository, so this check-up often finds rules you forgot you made. The Claude Code docs say file-edit approvals last only until the session ends. Type /permissions to see every rule and the file it came from, and /hooks to browse your hooks. If your company manages your Claude Code settings, some rules may come from there and you can't change them.

1.2 Turn My CLAUDE.md "Never" Rules Into Real Rules

Untested: not yet run against a model.

Use this when your CLAUDE.md is full of "never" and "always" lines that the agent sometimes ignores. It's for sorting those lines into ones Claude Code can enforce with a rule or a hook, and ones that can only stay as advice.

Use in: Claude Code, opened in your project, in plan mode.

Fill in: [MY RULES FILE] (e.g. "CLAUDE.md", or "CLAUDE.md and AGENTS.md"), [THE RULES THAT MATTER MOST] (e.g. "never edit .env, never push to main, always run tests before saying done").

My rules file has instructions you sometimes don't follow. Help me turn the important ones into guardrails that Claude Code actually enforces. Don't change any files yet.

My rules file: [MY RULES FILE]
The rules that matter most: [THE RULES THAT MATTER MOST]

Please:
1. Read my rules file and list every rule that says never, always, don't, or must.
2. Sort each one into a table with these columns: the rule, best way to enforce it (permission rule / hook / can't be enforced, keep as advice), and why in one line.
   - Permission rules are for blocking or asking before a tool, a command, or a file path.
   - Hooks are for things that should happen every time at a fixed moment, like running a formatter after an edit or running tests before you finish.
   - Things like "write clean code" or "explain simply" can't be enforced. Keep those as advice.
3. For each rule that can be enforced, write the exact permission rule or describe the hook, in the format from the Claude Code docs. Say which settings file it should go in and why.
4. Tell me honestly what each one won't catch. For example, a Bash rule only matches commands written a certain way.
5. Suggest which advice lines I can delete from my rules file once a real guardrail covers them.
Wait for my OK before you edit anything.

Tips to customize: Do the sorting first, then use Section 2 for the permission rules and Section 3 for the hooks. Keep the line in CLAUDE.md even after you add a guardrail if it explains *why*. Claude works better when it knows the reason, and the guardrail catches it when it forgets. If you use more than one AI tool, One Rules File for Every AI Tool helps you keep the advice part tidy.

Section 2: Permission Rules That Say No

2.1 Lock Away My Secret Files

Untested: not yet run against a model.

Use this when you have .env files, API keys, or other secrets in your project and don't want Claude reading or changing them. It's for deny rules that block Claude's file tools from those paths, plus an honest list of what they don't cover.

Use in: Claude Code, opened in your project.

Fill in: [MY SECRET FILES] (e.g. ".env, .env.local, and the secrets folder", or "please find them"), [JUST ME OR MY WHOLE TEAM] (e.g. "just me" or "everyone who clones this repo").

Help me block you from reading or changing my secret files, using permission deny rules. Explain each step in plain words. Never print what's inside any secret file.

My secret files: [MY SECRET FILES]
Who these rules are for: [JUST ME OR MY WHOLE TEAM]

Please:
1. Find files in this project that look like they hold secrets (like .env files, key files, or credential files). List only their paths, never their contents.
2. Write Read deny rules for them in the format from the Claude Code docs, for example "Read(./.env)" or "Read(./secrets/**)". Use the gitignore-style path patterns the docs describe, and cover every .env variant I have.
3. Put them in the right file: .claude/settings.local.json if they're just for me, or .claude/settings.json if they're for my whole team. Keep everything already in that file. Show me the final file before saving.
4. Explain what these rules cover and what they don't. In particular, tell me whether a script you run, or a search over the whole folder, could still read the file.
5. Suggest the next layer if I need a stronger wall, and tell me to check the Claude Code docs for it.
Wait for my OK before saving.

Tips to customize: The Claude Code docs say a Read deny rule also blocks Claude's Edit and Write tools on the same path. They also say these rules apply to Claude's file tools and to file commands Claude Code recognizes, like cat, but not to a Python or Node script that opens files on its own, or to a search like grep -r that doesn't name the file. For a wall around every shell command, the docs describe a built-in sandbox (macOS, Linux, and WSL2; off by default; turn it on with /sandbox). A .claudeignore file does nothing, according to the docs, so move its entries into Read deny rules. And if a real key was ever pasted into a chat or committed, change the key. A rule can't un-share it.

2.2 Make Risky Commands Ask Me First

Untested: not yet run against a model.

Use this when you want the agent to keep working on its own, but stop and ask before it pushes code, deletes things, or changes your database. It's for a short list of ask and deny rules for the commands that could really hurt.

Use in: Claude Code, opened in your project.

Fill in: [COMMANDS THAT MUST ASK FIRST] (e.g. "git push, deleting files, database migrations"), [COMMANDS THAT MUST NEVER RUN] (e.g. "git push --force, dropping database tables", or "none"), [MY PACKAGE MANAGER AND DATABASE TOOL] (e.g. "npm and Prisma", or "not sure").

I want you to keep working on your own, but some commands must ask me first and a few must never run. Help me set this up with permission rules. Explain each one in plain words.

Commands that must ask first: [COMMANDS THAT MUST ASK FIRST]
Commands that must never run: [COMMANDS THAT MUST NEVER RUN]
My package manager and database tool: [MY PACKAGE MANAGER AND DATABASE TOOL]

Please:
1. Look at my project (package.json scripts, migration tools, git setup) and add any risky commands I forgot, like a script that resets the database.
2. Write ask rules and deny rules in the Bash rule format from the Claude Code docs, for example "Bash(git push *)". Keep the list short and focused on real damage.
3. Explain the order Claude Code checks them in (deny, then ask, then allow), and point out any of my existing allow rules that these will override.
4. Put them in .claude/settings.local.json for just me, or .claude/settings.json if I say it's for my team. Keep everything already in the file. Show me the final file before saving.
5. Tell me honestly what these rules won't catch, using the examples from the docs (for instance, the same program called by its full path, or inside "bash -c").
6. Tell me how to check they're active with /permissions.
Wait for my OK before saving.

Tips to customize: Start with ask rules rather than deny rules. You'll learn what the agent really tries to run, and you can make the worst ones deny rules later. The docs say an allow rule can't carve an exception out of a deny rule, so a broad deny like Bash(git push *) blocks every push, even if you also allow a narrower one. If you need a rule a Bash pattern can't express, a PreToolUse hook on Bash can check the full command with your own logic. Prompt 3.3 shows the same idea for files.

Section 3: Hooks That Run Every Single Time

3.1 Explain Hooks and Pick 3 for My Project

Untested: not yet run against a model.

Use this when you've heard hooks can fix "the agent keeps forgetting," but you don't know what they are or which ones you'd need. It's for a plain explanation and three hook ideas that fit your project, with nothing installed yet.

Use in: Claude Code, opened in your project, in plan mode.

Fill in: [WHAT KEEPS GOING WRONG] (e.g. "it forgets to run tests, leaves messy formatting, and edits my lock file"), [MY TECH STACK] (e.g. "Next.js with Supabase"), [MY COMPUTER] (e.g. "Mac", "Windows", "Linux").

Explain Claude Code hooks to me like I'm new to this, then suggest 3 hooks for this project. Don't create anything yet.

What keeps going wrong: [WHAT KEEPS GOING WRONG]
My tech stack: [MY TECH STACK]
My computer: [MY COMPUTER]

Please:
1. In 5 short sentences: what a hook is, where hooks live (which settings file), what an event is, what a matcher is, and how a hook can block something.
2. Tell me the difference between a hook and a line in CLAUDE.md, in one sentence.
3. Suggest exactly 3 hooks for what keeps going wrong. For each one, give: the event it runs on (use the exact event names from the Claude Code docs, like PreToolUse, PostToolUse, or Stop), the matcher, what it does, and whether it can block anything.
4. For each, say what tools it needs on my computer (for example jq), and whether those are installed.
5. Warn me about anything a hook can't do, like undoing an action that already happened.
6. Tell me which prompt in my guardrails pack to use next for each hook: 3.2 for formatting or linting after edits, 3.3 for blocking protected files, 3.4 for tests before finishing.
Keep it short and plain.

Tips to customize: The Claude Code docs say hooks run with your full user permissions, so read every hook command before you add it, especially ones you copy from the internet. Type /hooks at any time to see what's set up. In a normal session, the docs say Claude Code waits to run hooks from settings files until you accept the "trust this folder" dialog for the project.

3.2 Run My Formatter or Linter After Every Edit

Untested: not yet run against a model.

Use this when the agent's edits keep leaving messy formatting or lint errors behind. It's for a PostToolUse hook that runs your formatter or linter on every file Claude edits, automatically.

Use in: Claude Code, opened in your project.

Fill in: [MY FORMATTER OR LINTER] (e.g. "Prettier", "ESLint", "Ruff", or "please find what this project uses"), [MY COMPUTER] (e.g. "Mac", "Windows", "Linux").

Set up a Claude Code hook that runs my formatter or linter on each file you edit, right after you edit it. Explain each step in plain words.

My formatter or linter: [MY FORMATTER OR LINTER]
My computer: [MY COMPUTER]

Please:
1. Check what this project already uses for formatting or linting, and the exact command to run it on one file. If nothing is set up, tell me and stop.
2. Write a PostToolUse hook with the matcher "Edit|Write", following the format in the Claude Code hooks docs. It should read the edited file's path from the hook input and run the tool on just that file.
3. Check whether the hook needs jq, and whether it's installed. If not, tell me how to install it, or use another way to read the file path.
4. Put the hook in .claude/settings.json in this project. If the file already has a "hooks" section, add to it instead of replacing it. Show me the final file before saving.
5. Tell me how to test it: one small edit you'll make, and what I should see afterward.
6. Tell me what this hook won't catch, like files changed by a shell command instead of your edit tools.
Wait for my OK before saving.

Tips to customize: The docs say a PostToolUse hook runs after the tool already ran, so it can't undo an edit. It can only tidy up or report back. When this kind of hook succeeds, Claude Code shows nothing in the chat, so check the file itself to see that it worked. Use a formatter that changes files on its own (like Prettier) for the "after edit" step. Save slower checks, like a full test run, for Prompt 3.4.

3.3 Block Edits to My Protected Files

Untested: not yet run against a model.

Use this when the agent keeps changing files it should leave alone, like your lock file, old migrations, or a config you set up by hand. It's for a PreToolUse hook that blocks the edit before it happens and tells Claude why.

Use in: Claude Code, opened in your project.

Fill in: [FILES AND FOLDERS TO PROTECT] (e.g. "package-lock.json, the migrations folder, .env files, anything in .git"), [MY COMPUTER] (e.g. "Mac", "Windows", "Linux").

Set up a Claude Code hook that blocks you from editing my protected files. Explain each step in plain words.

Files and folders to protect: [FILES AND FOLDERS TO PROTECT]
My computer: [MY COMPUTER]

Please:
1. Check that each protected path exists, and tell me about any I might have missed (for example, other lock files or generated folders).
2. Write a small script at .claude/hooks/protect-files.sh, based on the "Block edits to protected files" example in the Claude Code hooks docs. It should read the file path from the hook input, check it against my list, and exit with code 2 and a clear "Blocked:" message if it matches.
3. Register it as a PreToolUse hook with the matcher "Edit|Write" in .claude/settings.json. Keep anything already in that file. Show me the script and the final settings file before saving.
4. Tell me the command to make the script executable, if my computer needs it.
5. Explain why a hook is the right tool here, compared with a permission rule, in two sentences.
6. Tell me what this won't catch (for example, a shell command that changes the file), and one way to cover that too.
Wait for my OK before saving.

Tips to customize: The docs say a hook that exits with code 2 blocks the tool call even when an allow rule would let it through, and a hook's block holds in every permission mode. Claude sees your "Blocked:" message, so make it useful, like "Blocked: never edit old migrations. Make a new migration instead." Matchers are case-sensitive, so write Edit|Write exactly. If you only need to block one file path, a permission rule like Edit(./package-lock.json) in the deny list is simpler.

3.4 Don't Say "Done" Until the Tests Pass

Untested: not yet run against a model.

Use this when the agent keeps finishing with "All done!" but the tests fail, or it never ran them at all. It's for a Stop hook that runs your checks when Claude tries to finish, and sends it back to work if they fail.

Use in: Claude Code, opened in your project.

Fill in: [MY CHECK COMMAND] (e.g. "npm test", "npm run build && npm test", or "please find it"), [HOW LONG IT TAKES] (e.g. "about 20 seconds").

Set up a Claude Code Stop hook that runs my checks whenever you try to finish, and keeps you working if they fail. Explain each step in plain words.

My check command: [MY CHECK COMMAND]
How long it takes: [HOW LONG IT TAKES]

Please:
1. Confirm my check command works by running it once now, and show me the result.
2. Write a small script at .claude/hooks/check-before-done.sh that:
   - reads the hook input and exits right away (allowing you to stop) if stop_hook_active is true, as the Claude Code docs recommend, so it can't loop forever;
   - runs my check command;
   - if the checks fail, exits with code 2 and writes a short message with the failing part, so you keep working on it;
   - if the checks pass, exits with code 0.
3. Register it as a Stop hook in .claude/settings.json. Keep anything already there. Show me the script and the final file before saving.
4. If my checks are slow, suggest a faster version for this hook (for example, only the quick tests), so I'm not waiting after every reply.
5. Tell me how to turn this hook off for a while if I need to.
Wait for my OK before saving.

Tips to customize: The docs say a Stop hook runs every time Claude finishes responding, not only at the end of a big task, so a quick question will trigger your checks too. That's why a fast check command matters. The docs also say Claude Code overrides a Stop hook once it has blocked eight times in a row with no tool call in between, and checking stop_hook_active is how your script avoids hitting that limit. If your checks need the internet or a database, make sure they can run on your computer without you clicking anything.

Section 4: Safety Nets and Proof

4.1 Save a Checkpoint Before Risky Work

Untested: not yet run against a model.

Use this when you're about to let the agent do something big: a refactor, a migration, a cleanup, or anything that deletes. It's for a clean git save point you can go back to, and a plan for what the agent may and may not touch.

Use in: Claude Code, opened in your project.

Fill in: [THE RISKY TASK] (e.g. "rename the users table and update every query"), [MY MAIN BRANCH] (usually "main").

Before you start a risky task, help me make a clean save point I can go back to. I'm a beginner with git, so explain each command in one plain line.

The risky task: [THE RISKY TASK]
My main branch: [MY MAIN BRANCH]

Please:
1. Run git status and tell me if I have uncommitted changes. If I do, ask me whether to commit them first. Don't commit anything without my OK.
2. Suggest a new branch name for this task and give me the command to create it, so [MY MAIN BRANCH] stays untouched.
3. List what this task could break or delete that git can't bring back, like data in a real database, files outside this project, or anything already pushed or deployed. For each one, tell me how to back it up first, or say "check with me before touching this."
4. Write a short plan: the steps you'll take, and the point where you'll stop and show me before doing anything that can't be undone.
5. Tell me exactly how to go back to this save point if things go wrong.
Wait for my OK before starting the task.

Tips to customize: Claude Code also has /rewind (or press Esc twice when the prompt is empty) to go back to an earlier checkpoint. But the docs say a file that only shell commands changed isn't tracked, and changes made outside Claude Code usually aren't either, so git is still your real safety net. A git branch can't bring back rows deleted from a live database. For that, back up the database first, or test on a copy.

4.2 Test My Guardrails Without Breaking Anything

Untested: not yet run against a model.

Use this when you've added permission rules or hooks and want proof they really work. It's for a safe test of each guardrail, with a simple pass or fail for each one.

Use in: Claude Code, opened in your project, on a branch where you've committed your work.

Fill in: [THE GUARDRAILS I ADDED] (e.g. "deny reading .env, ask before git push, the protect-files hook, the tests-before-done hook").

I added guardrails to this project. Help me test each one safely, without breaking anything or touching real secrets.

The guardrails I added: [THE GUARDRAILS I ADDED]

Please:
1. List every permission rule and hook that's active here, and which settings file each comes from. Flag anything I listed that you can't find, and anything you found that I didn't list.
2. For each guardrail, plan one harmless test that should be blocked or asked about. Use fake or empty targets, like a test file you create for this, never my real .env, a real push, or a real delete. Show me the plan first.
3. For each hook script, show me how to test it by itself by piping sample JSON into it and checking the exit code, as the Claude Code hooks docs show.
4. After my OK, run the tests one at a time and report each as: guardrail, what you tried, what happened, pass or fail.
5. For anything that failed, explain why (for example, a wrong matcher, a typo in the JSON, or a script that isn't executable) and suggest a fix. Don't apply fixes without my OK.
6. Clean up any test files you created.

Tips to customize: If a hook doesn't seem to run, the docs suggest checking /hooks first. Also check that your JSON has no trailing commas or comments, that the matcher matches the tool name exactly, and that the script is executable. Press Ctrl+O to open the transcript view and see what a hook did. Run this test again whenever you change your settings, or after you update Claude Code.

Get new free packs in your inbox

Optional. Every prompt here is free, and you don't need to sign up to use any of them. We email when we add new free packs. Unsubscribe anytime.

More free packs: Vibe Code Starter Pack Ship It Safe Fix My Bugs Ship It Live Make It Pretty Get Paid Signup Emails That Actually Arrive Lovable Credit Saver One Rules File for Every AI Tool Make Your Claude Code Limit Last Graduate From Lovable First App Store Submission Survive Your First Traffic Spike Get Found on Google First 100 Users Two AIs, One Project It Broke in Production Hit the Slop Wall? Refactor Without Breaking Everything Vibe Code From Your Phone AI Reverse Engineering Run Several AI Agents at Once Let AI Review Your AI's Code Make Your Cursor Usage Last Privacy Policy and Terms That Match Your App Install Skills, Plugins and MCP Servers Without Getting Burned Say What You Mean Prompt Injection: Don't Let a Web Page or a Strange File Hijack Your Agent Hit Your Limit Mid-Task? Switch AI Tools Without Losing Your Place Don't Let the AI Delete Your Data: Safe Database Changes Make the AI Teach You While It Builds Bolt Token Saver v0 to Production Claude Code Subagents and Skills for Beginners Logins, Tokens and JWTs in Plain English Put Your Web App on Their Phone Add AI Features in Lovable Is Anyone Using It? Simple Analytics for Vibe Coders Use the Cheap Model for the Easy Stuff: Claude Code Model Mixing Ship Updates Without Breaking the Live App: Preview Links, Checks and One-Click Rollback Try to Break It: Stress-Test Your App Before Strangers Do Claude Code Memory: Stop It Forgetting Your Decisions Fix Your Lovable Security Warnings Without Breaking the Live App What Will My App Cost to Run? A Monthly Bill You Can Predict Leave Claude Code Running Without It Getting Stuck Put Your Lovable App on Autopilot: Automations That Check and Report for You Spec and Tests First: Tell the Agent When It's Done Only Change What I Asked: Stop the AI Rewriting Code You Didn't Mention Stop Getting 429'd: Call Other People's APIs Without Hitting Limits Use the Current Version: Stop the AI Writing Outdated Library Code What Did My Agent Actually Do? Read Your Claude Code Session History Your First Google Play Launch: Get Through the 12-Tester, 14-Day Closed Test Will Anyone Want It? Check Your App Idea Before You Build Claude Code Code Mode: Try It Without Breaking Your Safety Checks Coding With Gemini 4 Neon: Make It Double-Check Its Own Work Understand the App You Already Built: A Guided Tour of Your Own Code Your Guess Might Be Wrong: Make the AI Find the Real Cause Before It Fixes Replit Missions: Give Agents a Goal, a Budget and Approval Rules Make Your Antigravity Quota Last: Pick the Right Gemini Model and Check /usage Turn a Claude Artifact Into a Desktop App, Without Giving It Too Much Access Built It for Work? Make Sure Only Your Team Can Open It Plan Before It Builds: Use GitHub Spec Kit So the Agent Builds the Right Thing Saves That Stick: Fix Data That Disappears Rebuilt Your Site With AI? Make Sure Google Can Still See Every Page Subscriptions and Paywalls: Gate Features by Plan Your AI App Builder Is Shutting Down: Get Your Code, Data and Domain Out Your Own Android App From a Prompt: Build It in Google AI Studio and Put It on Your Phone Backups You Can Actually Restore: Check, Copy and Test Your Supabase Data Accessibility Pass Before You Ship: Make Your App Work With a Keyboard, a Screen Reader and Zoom Update Your Dependencies Without Breaking the App: npm Updates, Audits, Major Upgrades and Dependabot