Permissions in Claude Code

Permissions in Claude Code

Understand how Claude Code decides what it may read, change, and run on your computer: the default approvals, the permission modes, allow and deny rules, where the settings live, and how to build a safe, comfortable policy for yourself or your team.

Claude Code is an assistant that works inside your software projects. It can read your files, edit your code, run commands in your terminal, and use outside tools. That is exactly what makes it useful, and it is also exactly why it needs rules. An assistant that can run commands on your machine is powerful. An assistant that can run any command without asking would be risky.

Permissions are the rules that sit between what Claude Code wants to do and what it is actually allowed to do. They answer simple but important questions. May it read this file? May it change that one? May it run this command, or must it ask first? May it never touch a particular folder at all? With good answers to these questions, you can let Claude Code work smoothly while keeping a firm hand on the things that matter.

This guide explains permissions from the very beginning. We cover why they exist, the layers of the system, the modes you can choose, how to write rules, where settings are stored, how sandboxing and hooks add protection, and how to design a sensible policy. Claude Code is updated often, and names of settings, commands, and options can change, so for the exact current wording, check the official documentation at docs.claude.com. This article focuses on the ideas that stay true as the details move.

1What Are Permissions, and Why Do They Exist?

Permissions are the safety rules that keep a powerful coding assistant inside boundaries you chose.

The plain-words definition

A permission is a yes-or-no decision about one action. Claude Code is about to read a file, edit a file, run a command, fetch a web page, or call an outside tool. For each action, the system asks: is this allowed automatically, does it need the user’s approval, or is it forbidden? The collection of all such decisions, together with the rules that produce them, is called the permission system.

Why a coding assistant needs them

Most programs do only what their buttons allow. A coding assistant is different, because it can combine small actions into big effects. Reading a file is harmless, but editing many files can break a project, and a single terminal command can delete a folder, install software, or send data across the internet. Permissions exist so that the small harmless actions can flow freely while the powerful ones get your attention.

Protect

Your files and machine

Stop accidental damage, such as deleting the wrong folder or overwriting important work.

Guard

Your secrets

Keep keys, tokens, and private files out of reach, so they cannot be read or leaked.

Control

Your pace

Let you choose how much to approve by hand and how much to leave to Claude.

Trust

Your team’s standards

Let a team share one set of safe rules, so everyone works under the same boundaries.

Everyday analogy

Think of lending your car to a skilled driver. You might say: “Drive wherever you need in the city, ask me before a long trip, and never take it onto the highway at night.” Permissions are those instructions. They let a capable driver be useful without making you nervous every time the engine starts.

i
Good to know

Permissions control what Claude Code is allowed to do. They are one layer of safety among several, alongside sandboxing, hooks, and your own review of its work.

2The Core Idea: Tools and Their Risk

Claude Code acts through tools, and permissions are attached to tools according to how risky they are.

What is a tool?

In Claude Code, everything Claude does in your environment happens through a tool. There is a tool for reading files, a tool for searching, a tool for editing, a tool for running terminal commands, a tool for fetching web pages, and others. When Claude wants to do something, it asks to use a tool with specific inputs. The permission system looks at that request and decides what to do.

A ladder of risk

Tools are not equally dangerous. A helpful way to see them is as a ladder, from harmless at the bottom to serious at the top.

flowchart TD
  A["Request to use a tool"] --> B{"What kind of action?"}
  B -- "Look only: read, search, list" --> C["Lowest risk: usually allowed without asking"]
  B -- "Change files: edit, write" --> D["Medium risk: ask, or allow inside the project"]
  B -- "Run commands" --> E["Higher risk: ask unless the command is known safe"]
  B -- "Reach outside: web, network, outside tools" --> F["Highest variety: ask, or follow your rules"]
    
Figure 1: The ladder of risk. The more an action can change or reach, the more likely it needs approval.

The ladder explains most of the default behavior. Looking at things is safe enough to allow freely. Changing files deserves a decision, because changes can be unwanted. Running commands is more serious because commands can do almost anything. Reaching outside the machine adds the risk of leaking data or pulling in untrusted content.

Kind of actionExampleWhat can go wrong
ReadOpen a source fileLittle, unless the file holds secrets
SearchFind where a function is usedLittle
EditChange a source fileUnwanted or broken changes
RunRun the tests, or a build scriptAnything the command can do
FetchDownload a web pageUntrusted content, hidden instructions
Outside toolsUse a connected serviceChanges in systems beyond your computer
Everyday analogy

In a workshop, anyone can look at the blueprints, but you ask before using the saw, and the chemical store is locked. Permissions follow the same common sense: easy access to the harmless, a decision for the powerful, and a lock on the dangerous.

i
The key idea

Permissions are about actions, not about trust in Claude’s intentions. Even a well-behaved assistant can make a mistake, or be misled by content it reads, so boundaries matter either way.

3The Default: Ask Before Acting

Out of the box, Claude Code is cautious. It reads freely and asks before it changes or runs things.

When you start Claude Code in its standard setup, it follows a careful default. Reading and searching within your project generally happen without interruption. When Claude wants to edit a file or run a command that is not already approved, it stops and shows you what it plans to do. You then choose whether to allow it. This is the safest everyday setting, and it teaches you how Claude works.

What an approval prompt tells you

An approval prompt is a small window of information. It names the tool, shows the specific input, such as the file to edit or the command to run, and offers choices. Typical choices are to allow this one time, to allow this kind of action from now on, or to refuse and tell Claude to try something else. Reading the prompt is the heart of the system, because it is the moment when you check what is really about to happen.

1

Claude proposes an action

It decides it needs to edit a file or run a command to move your task forward.

2

The system checks the rules

Deny rules are checked first, then ask rules, then allow rules, and the current mode.

3

You may be asked

If nothing allows or forbids the action, the prompt appears with the details.

4

You decide

You allow once, allow similar actions, or say no and redirect Claude.

5

The action runs or is refused

Claude continues with the result, or adapts its plan if it was refused.

Everyday analogy

Think of a new house-painter who asks, “May I move this table?” and “Shall I paint over this old patch?” before each non-obvious step. At first the questions are frequent. As you come to trust the painter, you say, “Go ahead and move the furniture, just ask me about color changes.” The default gives you the chance to build that trust step by step.

i
Practical tip

In your first sessions, read each prompt carefully. You will quickly learn which actions are routine and which deserve a pause, and that tells you what to automate.

Learning from the prompts

Treat your first week of approvals as a free lesson. Each prompt shows you what Claude considers necessary to do your task. Over time you will notice patterns: it often runs the tests, checks the version control status, and searches for names. These repeated, low-risk actions are natural candidates for allow rules. The unusual prompts, such as a command you do not recognize or a file outside the project, are the ones deserving a pause. The skill you are building is the ability to tell routine from surprising at a glance.

4Permission Modes

A mode is a quick setting that changes how much Claude Code does without asking.

Instead of editing rules for every situation, you can switch the overall mode of a session. Modes are like gears in a car: each suits a different road. The set of modes and their names can change between versions, so treat the table below as a guide to the idea and check the documentation for the current list.

Mode (idea)What Claude does without askingBest for
Default, ask as neededReads and searches; asks before edits and commandsLearning, sensitive projects
Accept editsEdits files in the project freely; still asks for most commandsFocused coding sessions you can review afterward
Plan onlyReads and thinks; makes a plan but changes nothingExploring a big change before committing to it
Bypass all checksEverything without askingOnly isolated, disposable environments
flowchart LR
  A["Plan only: think, no changes"] --> B["Default: ask for edits and commands"]
  B --> C["Accept edits: edits flow, commands asked"]
  C --> D["Bypass all checks: no questions asked"]
    
Figure 2: Modes arranged from most cautious to least. Moving right trades oversight for speed.

Choosing a mode

Think about the stakes and the reversibility. If your work is under version control and you can inspect and undo changes easily, allowing edits to flow can be comfortable. If you are exploring an unfamiliar codebase, plan-only mode lets Claude study and propose without touching anything. If the project is sensitive, stay with the default and add rules. The last mode, which skips all checks, removes your safety net entirely. It is meant for isolated, throwaway environments such as a container that can be destroyed, never for your everyday machine with real credentials.

Everyday analogy

Driving modes work the same way. You use first gear on a steep, narrow lane and top gear on an empty highway. You would not stay in top gear down a mountain road. Choosing the mode for the road you are on is a sign of skill, not a lack of ambition.

!
The no-questions mode is a last resort

Skipping all permission checks means a mistake or a hidden malicious instruction can run commands unchecked. Use it only where nothing valuable can be reached and the environment can be thrown away.

5Rules: Allow, Ask, and Deny

Rules are standing decisions that save you from answering the same prompt again and again.

Modes are broad. Rules are precise. A rule names a tool, and optionally a pattern describing exactly what it applies to, and states what to do: allow it, ask about it, or deny it. For example, you might allow running the project’s test command, ask before any command that installs software, and deny reading your secrets file.

Allow

Go ahead

The action runs without a prompt. Use it for safe, routine, repeated actions.

Ask

Check with me

The action always prompts, even if a broader rule might allow it. Use it for actions you want to see every time.

Deny

Never

The action is blocked, and Claude cannot do it even if asked. Use it for secrets and dangerous operations.

Which rule wins?

When more than one rule could apply, a simple order of strength decides. A deny rule beats an ask rule, and an ask rule beats an allow rule. This means a specific refusal always holds, even if another rule is generous. It is the same logic as a building where “staff only” on one door overrides a general welcome sign in the lobby.

SituationResult
Both a deny rule and an allow rule matchDenied
Both an ask rule and an allow rule matchAsked
Only an allow rule matchesAllowed
No rule matchesThe current mode decides, usually by asking

Patterns: narrowing a rule

A rule can be broad, such as “any file read”, or narrow, such as “reading files in one folder only”, or “running only commands that begin with a given word”. Patterns often use wildcards, which are symbols that stand for “anything here”. The art of writing rules is to be narrow enough to be safe and broad enough to be useful. A rule that allows only the exact test command is safe but may need a companion for a variant. A rule that allows any command beginning with a common word may allow far more than you intended.

Everyday analogy

Think of a school’s rules for pupils on a trip. “You may buy snacks” is allow. “Ask a teacher before leaving the group” is ask. “Never go near the water” is deny. If a pupil finds a loophole in the snack rule that leads to the water, the stronger rule about water still wins. Deny always has the last word.

i
Practical tip

Start with deny rules for what must never happen, then add allow rules one at a time for actions you approve repeatedly. This order builds safety first and convenience second.

Keeping rules readable

Rules are read by people as well as by the program. Keep the list short, group similar rules together, and prefer many clear rules over one clever pattern that nobody can decode. When a rule exists for a reason that is not obvious, write the reason in your team notes. A policy that a new teammate can understand in ten minutes is far more likely to be kept up to date, and far less likely to hide a gap.

6Where Settings Live: Scopes

The same rule can apply to just you, to one project, to your whole team, or to a whole company, depending on where it is stored.

Claude Code reads its settings from several places, called scopes. Each scope has a different reach. Understanding them tells you where to put a rule and which one wins when they differ.

ScopeWho it affectsShared?Typical use
User settingsYou, in every projectNo, personalYour own habits and general deny rules
Project settingsEveryone who uses this projectYes, stored with the codeTeam rules, such as allowing the test command
Local project settingsYou, in this project onlyNo, kept out of version controlPersonal tweaks for one project
Managed policyEveryone in an organizationYes, set by administratorsCompany-wide rules that individuals cannot override
flowchart TD
  A["Managed policy: set by administrators, strongest"] --> B["Command-line options for this session"]
  B --> C["Local project settings: personal, this project"]
  C --> D["Shared project settings: team, this project"]
  D --> E["User settings: personal, all projects"]
    
Figure 3: Layers of settings, from the strongest at the top to the weakest at the bottom. Higher layers win when they disagree.

The picture shows a chain of authority. An organization’s managed policy sits at the top and cannot be overridden by an individual. Below it, options you give for one session take priority over stored files. Among stored files, those closer to the specific project win over your general ones. Because the exact order is a detail that could change, confirm it in the documentation before relying on it for something critical.

Which scope for which rule?

Team

Shared project settings

Rules that everyone on the team should follow, kept with the code so new members get them automatically.

Personal

User and local settings

Your own preferences, which should not force themselves on teammates.

Company

Managed policy

Non-negotiable rules, such as blocking access to certain files or tools across the whole organization.

Everyday analogy

A workplace has laws of the country, company policy, team rules, and your own habits at your desk. When they conflict, the law and company policy come first. A sensible person puts each rule at the right level: personal habits at the desk, team agreements on the team wall, and non-negotiables in the company handbook.

i
Do not store secrets in shared settings

Shared project settings travel with the code. Keep passwords and keys out of them, and use deny rules to protect secret files instead.

7Managing Permissions Day to Day

You can adjust permissions as you work, instead of editing files by hand.

Claude Code gives you a way to view and change permissions from within a session. A dedicated command opens a screen listing your current allow, ask, and deny rules, and lets you add or remove them. There is also a quick way to cycle through modes during a session, so you can move from careful to fast and back again as the work changes. The exact commands and keys can change, so check the documentation or the in-product help for the current ones.

The “always allow” choice

When an approval prompt offers to allow an action from now on, it is creating an allow rule for you. This is convenient, and also the main way that permissions quietly grow. A rule made in a hurry on a Tuesday can still be there a year later, allowing something you have forgotten. Treat “always allow” as a real decision. Ask yourself whether you would be comfortable if this action ran every time, in any project covered by that rule.

A healthy review habit

1

List your rules

Open the permissions screen and read every allow rule slowly.

2

Remove the stale ones

Delete rules for projects or tools you no longer use.

3

Narrow the broad ones

Replace a wide rule with several specific ones where possible.

4

Add missing denies

Check that secrets and dangerous operations are blocked.

Everyday analogy

Think of the spare keys you hand out over the years: to a neighbor, a cleaner, a contractor. If you never check, you eventually do not know who has one. A yearly tidy-up, collecting the keys you no longer need, keeps your home secure. Reviewing allow rules is the same kind of tidy-up.

!
Convenience creeps

Each “always allow” is small, but together they can open far more than you meant. Review them regularly.

When the prompts become noise

If you are being asked dozens of questions in a session, something is out of balance. Either the rules are too tight for the work you do, or the work is too varied for a single setting. Do not respond by turning everything off. Instead, note which prompts are repeated and harmless, turn exactly those into narrow allow rules, and keep the rest. Fewer, more meaningful prompts mean you read each one, and reading each one is what makes the system safe.

8Working Directories and Boundaries

Claude Code normally works inside the folder where you started it, and that boundary is part of its safety.

When you start Claude Code in a project folder, that folder becomes its home base. File edits are generally limited to this working area and its subfolders. If Claude wants to go beyond, to a neighboring project, your home folder, or a system location, it usually needs your explicit permission. This keeps a task about one project from wandering into unrelated parts of your computer.

Adding more folders on purpose

Sometimes you genuinely need more than one folder, such as a shared library next to your main project. You can add extra directories to the session, which makes them part of the allowed area. Do this deliberately and only for the folders you need. Each added folder widens what Claude can read and change.

LocationTypical treatmentAdvice
The project folderHome base; normal rules applyStart Claude Code here, not higher up
Subfolders of the projectIncludedDeny sensitive subfolders explicitly
A sibling projectOutside; needs permission or an added directoryAdd only if the task requires it
Your home folderOutside; may hold personal files and keysAvoid starting sessions here
System foldersOutside; sensitiveKeep out of reach

Start in the right place

A common mistake is to start Claude Code in a very high-level folder because it is convenient. That folder becomes the boundary, and everything below it is in reach, including old projects, downloads, and private files. Start as deep as the task allows. A smaller boundary is easier to reason about and safer if anything goes wrong.

Everyday analogy

A decorator hired to paint one room is given access to that room. If they also need the hallway, you open the hallway. You do not hand over keys to every room in the house on the first day. Working directories are the rooms you open for Claude Code.

i
Practical tip

If you find yourself adding many extra directories, consider whether the task is really several tasks, each of which could run in its own session.

9Protecting Secrets with Deny Rules

The most valuable use of deny rules is to keep sensitive files completely out of reach.

Every project has files that Claude does not need and should not see: environment files with passwords, private keys, token files, local configuration for services, and folders of customer data. Reading is usually allowed freely, which is why a deny rule on these files matters. If Claude cannot open them, their contents cannot end up in a conversation, a log, or a message to an outside service.

What to protect

Credentials

Passwords and tokens

Environment files, credential stores, and any file holding keys for services.

Keys

Private keys and certificates

Files used to sign in, sign code, or prove identity.

Data

Customer and personal data

Exports, backups, and test data that came from real people.

Config

Machine and cloud settings

Cloud account files, shell history, and other personal configuration.

Reading is not the only risk

A good secret-protection policy denies reading and editing. It also pays attention to commands, because a command can read a file even when the file-reading tool is blocked. If shell access is allowed, a denied file might still be reachable by a command that prints it. So pair file-level denies with careful command rules, and with sandboxing, which we discuss later, for stronger protection.

Protect againstLayer that helps
Claude reading a secrets file directlyDeny rules on file reading
A command that prints the secretCommand rules and sandboxing
Secrets committed to the repositoryIgnore files, scanning, and review
Secrets sent to an outside serviceNetwork limits and approvals
Secrets pasted into the chat by a personHabits and training, since no rule can stop this
Everyday analogy

Imagine a house-sitter who may roam freely but never enter the study with the safe. A lock on the study door is the deny rule. But if the study window is open, the lock alone is not enough. Several layers, a lock, a window latch, and an alarm, together make a secure home.

!
Do not rely on one layer

A single deny rule is good, but secrets deserve defense in depth. Combine rules, sandboxing, careful commands, and good habits.

Keep secrets out of the project in the first place

The strongest protection is not to have secrets lying in the project folder at all. Where possible, load credentials from a secure store at the moment they are needed, give them narrow rights, and rotate them on a schedule. Deny rules are a safety net, not a license to leave keys in plain files. If a secret has ever been exposed to a conversation or committed to a repository, treat it as compromised and replace it.

10Command Permissions: The Sharpest Tool

Running commands is the most flexible and most dangerous thing Claude Code can do, so it needs the most careful rules.

Why commands are special

A terminal command can do almost anything the user can do: read any file, change any setting, install software, contact the internet, or delete everything. Because of this breadth, it is not enough to say “allow commands” or “deny commands”. Rules need to be specific about which commands, and with what arguments.

Safe, careful, and dangerous commands

CategoryExamples (in words)Typical policy
Read-only and informationalListing files, showing the version control status, printing a file you may readOften allowed
Project routinesRunning the test suite, running the linter, building the projectAllow the exact commands
Changing stateInstalling packages, committing changes, changing branchesAsk each time, or allow narrowly
Reaching outsideDownloading files, calling web services, pushing code to a shared serverAsk, with caution
Destructive or privilegedDeleting folders recursively, changing permissions broadly, running as administrator, changing system settingsDeny or always ask

The trouble with wildcards and chains

Command rules often use a prefix match: allow any command that begins with a certain word. This is convenient, and it can be too generous. A rule that allows “anything starting with a common tool” may also allow variants with dangerous options. Commands can also be chained together on one line, so a harmless-looking first part can be followed by something harmful. Good systems look at the pieces of a chained command, but you should still write rules defensively and keep risky commands behind approval.

Do

Allow exact, repeatable commands

The test, lint, and build commands your project uses every day.

Do

Keep state-changing commands visible

Installing, committing, and pushing deserve a glance.

Avoid

Allowing a whole program

Permitting every use of a powerful tool permits its worst uses too.

Avoid

Trusting the first words only

What follows the prefix, including options and chained parts, matters as much.

Everyday analogy

Giving someone access to a toolbox is not the same as giving them permission to use every tool in every way. You might say, “use the screwdriver on the shelves”, not “use any tool on anything”. The precision of the instruction is what keeps the house standing.

i
Practical tip

Let Claude run a task once with prompts on, note the commands you approve repeatedly, and then turn exactly those into allow rules.

11Web and Network Permissions

Reaching out to the internet brings in outside content and opens a path for data to leave.

Claude Code can fetch web pages and search the web when allowed. These abilities are useful for reading documentation or checking an error message. But they also raise two worries. First, the content that comes back is not under your control and may contain text designed to mislead an AI. Second, a network connection is a way for information to leave your machine.

Controlling where Claude may go

Permissions for web access can be set per site or domain. A good starting policy allows a short list of trusted documentation sites and asks about anything else. Where company rules are strict, an administrator can restrict network access to an approved list. Commands that use the network, such as downloads or uploads, should be treated with the same care as web tools.

Web actionRiskSuggested policy
Read official documentationLowAllow trusted domains
Read arbitrary pagesHidden instructions, misleading contentAsk, and treat content as information only
Download and run softwareHighAsk, or deny
Upload or post dataLeaksAsk each time
Call internal servicesChanges in company systemsFollow organization policy
Everyday analogy

Letting a trusted assistant read the encyclopedia in your library is one thing. Letting them accept a package from a stranger at the door, open it, and follow the note inside is another. Web permissions separate trusted reading from unknown content.

!
Outside text is not an instruction

Claude is designed to treat web content as information, not commands. Still, limit what it can do after reading untrusted pages, especially sending data or running new software.

12Permissions for MCP and Outside Tools

Connected tools extend Claude Code’s reach, and each one needs its own permission decisions.

Claude Code can connect to outside tools through the Model Context Protocol, known as MCP. These might be an issue tracker, a database, a code host, or a monitoring service. Each connected tool offers its own set of abilities, and they are covered by the same permission ideas: allow, ask, and deny. A tool that reads information is lower risk than one that creates, changes, or deletes things in a real system.

Rules at several levels

Permissions can usually be set for a whole connected server or for individual tools within it. This lets you allow the harmless read tools and keep the write tools behind approval. For example, you might allow searching tickets freely while asking each time before a ticket is closed or a database record is changed.

Kind of connected toolExample abilitySuggested policy
Read-only lookupsSearch issues, read documentationAllow once you trust the server
Drafting or private notesCreate a draftAllow with a glance
Changing shared recordsUpdate a ticket, edit a pageAsk each time
Sending to other peoplePost a message, send an emailAsk each time
Production systemsChange a live database or deployDeny, or require strong approval

Choose servers carefully

An MCP server is software that acts on your behalf. Install only servers from sources you trust, review what they can do, and keep them updated. A shared project can list the servers the team uses, which is helpful, yet each person should understand what they are enabling. Remove connections you do not use.

Everyday analogy

Hiring a helper who can use the office phone, the post room, and the filing cabinet means deciding what each of those lets them do. They may look up numbers freely, but sending a letter in the company’s name is something you want to approve. Each connected tool is another door, and each door gets its own lock decision.

i
Related reading

For a deeper look at how MCP works and how to use it safely, see the guide on MCP in Claude on this site, and the official documentation.

13Subagents, Headless Runs, and Automation

When nobody is there to answer a prompt, permissions must be settled in advance.

Helper agents

Claude Code can start helper agents, often called subagents, that handle part of a task separately. Helpers work under the permission rules of the session, and they may also have their own limits on which tools they can use. Giving a helper only the tools it needs, such as read and search for a reviewer, is a strong way to keep power low where it is not needed.

Running without a person present

Claude Code can also run in a non-interactive way, for example inside an automated pipeline, a scheduled job, or a script. There is no person to answer an approval prompt, so anything that would need approval will either be refused or will stop the run. This is why automated runs need their permissions decided ahead of time through rules and options, and why they should have very narrow rules.

Narrow

Only the tools the job needs

A job that reviews code needs to read, not to edit or run arbitrary commands.

Isolated

A disposable environment

Run automation in a container or a temporary machine with no real secrets.

Limited

Small credentials

Give automation keys that can do only what the job needs and nothing more.

Visible

Logs and results kept

Record what happened so a person can review it after the run.

Everyday analogy

A night security guard works while the manager sleeps, so the manager writes clear standing orders ahead of time: which doors to check, which to leave locked, whom to call. There is no one to ask at three in the morning. Unattended runs need standing orders written in the same spirit.

!
Never combine “no checks” with real credentials

An unattended run that skips permission checks and holds powerful keys is the most dangerous setup. If checks are skipped at all, the environment must be disposable and the keys minimal.

Matching tools to the helper’s job

A good rule for helper agents is that their power should match their job. A reviewer needs to read and search, so it should not be able to edit or run commands. A test runner needs to run the test command, so it does not need web access. A documentation helper may need the web but not your source files. Writing each helper’s job description narrowly makes the whole system easier to reason about and far safer when something misbehaves.

14Hooks: Programmable Guards

Hooks let you attach your own checks to Claude Code’s actions, going beyond fixed rules.

Rules are good at simple decisions. But some policies need more thought: block any command that touches production, require a ticket number before a commit, or run a scanner before a file is saved. A hook is a small program you attach to a moment in Claude Code’s work, such as just before a tool runs or just after it finishes. The hook can inspect what is about to happen and approve it, block it, or add a message for Claude to read.

What hooks are good for

MomentExample use
Before a tool runsBlock dangerous commands, require extra checks, or check that a path is allowed
After a tool runsRun a formatter, a test, or a scanner on the changed files
When a prompt is submittedAdd helpful context, or reject a request that breaks a policy
When a task endsRun a final check, or send a notification

Rules and hooks together

Think of rules as the simple signs on the door and hooks as the guard who can think. Rules are fast, predictable, and easy to read. Hooks can express policies that rules cannot, but they are code that you must write, test, and maintain, and they run with your permissions. A buggy hook can fail to protect you or can block valid work. Keep hooks small, test them on safe examples, and treat them like any other security-relevant software.

Everyday analogy

A building has signs that say “staff only”, and also a receptionist who checks badges and phones upstairs when something looks odd. The signs handle the usual case cheaply. The receptionist handles the unusual one with judgment. Hooks are the receptionist of your coding environment.

i
Practical tip

Begin with a hook that only logs what happens. Once you understand the pattern, add hooks that block specific risky actions.

15Sandboxing: A Wall Behind the Rules

Permissions decide what Claude Code may attempt. A sandbox limits what any command can actually reach.

The difference between a rule and a wall

A permission rule is a decision made by the program: it looks at a request and says yes or no. A sandbox is different. It is a restricted environment enforced by the operating system, in which the commands run. Inside it, a command simply cannot touch files outside allowed folders or connect to forbidden network locations, no matter how it is written. Rules are a guard at the door. A sandbox is the wall around the building.

flowchart TD
  A["Claude proposes a command"] --> B{"Permission rules"}
  B -- "Deny" --> C["Blocked"]
  B -- "Ask" --> D["You decide"]
  B -- "Allow" --> E["Command runs"]
  D -- "Approve" --> E
  D -- "Refuse" --> C
  E --> F{"Sandbox boundary"}
  F -- "Inside allowed folders and network" --> G["Works as normal"]
  F -- "Outside the boundary" --> H["Stopped by the operating system"]
    
Figure 4: Two layers of protection. Rules decide whether a command starts. The sandbox limits what it can reach even after it starts.

The diagram shows defense in depth. A request first meets the permission rules. If it passes, it runs, but inside a sandbox, so a mistake or a cleverly disguised command is still contained. Even an approved command cannot reach the folders or network addresses outside the boundary.

What a sandbox adds

Files

Limited file reach

Commands can write only inside the project and approved folders.

Network

Limited connections

Commands can reach only approved destinations, which makes leaking data much harder.

Fewer prompts

More comfortable approvals

Because the wall limits the damage, commands inside it can often run with fewer interruptions.

Contain

Protection against surprises

Even a command that nobody anticipated is held within the boundary.

Everyday analogy

A playground has a fence as well as a supervisor. The supervisor decides which games are allowed, but the fence stops a ball or a child from running into the road if someone is not looking. Rules are the supervisor, and the sandbox is the fence. Good safety uses both.

i
Availability varies

Sandbox features depend on your operating system and version. Check the documentation for what your setup supports, and use containers or virtual machines for stronger isolation when needed.

16Organization Policies and Managed Settings

Companies can set rules that individual developers cannot loosen.

In a company, the safety of a coding assistant is not only a personal matter. The organization has duties to protect customer data, source code, and its own systems. For this reason, administrators can deploy managed settings that sit above personal and project settings. These can set mandatory deny rules, restrict which tools and servers may be used, and limit which permission modes are allowed.

What organizations usually decide

DecisionTypical reason
Block reading of secrets and sensitive foldersPrevent credentials and customer data from entering conversations
Forbid the mode that skips all checksKeep a human in the loop on real machines
Approve a list of connected toolsControl what outside systems can be reached
Limit network destinationsReduce the chance of data leaving
Require logging and reviewSupport audits and incident response
Standardize project rulesGive every team the same safe starting point

Working well with policy

If you are a developer and a setting is locked, treat it as a boundary set for good reasons. Ask the platform or security team if you need something changed, and explain the task. Often there is an approved path, such as a sandboxed environment where more freedom is allowed. If you are an administrator, keep the policy small, clear, and explained. Rules that people understand are followed. Rules that look random are worked around.

Everyday analogy

Airports have security rules that no passenger can change, and they exist for everyone’s safety. A traveler who understands why the rules exist moves through calmly. A traveler who sees them as random may try to hide things in their bag. Clear reasons make policy easier to live with.

i
For administrators

Test your managed settings on a pilot team first. A rule that blocks routine work will push people toward risky workarounds.

Communicating policy to developers

Policy works best when people understand it. Publish a short page that says what is blocked, what is allowed, and why. Give a clear route for requesting an exception, and answer requests quickly. Share stories of problems that the policy prevented, in general terms, so the rules feel purposeful and not arbitrary. When developers see policy as a partner, they bring concerns early, and the policy improves.

17Security Threats Permissions Help Prevent

Understanding the threats shows why each rule is worth having.

ThreatWhat it meansMain defenses
Prompt injectionText in a file, web page, or tool result tries to give Claude ordersApprovals for risky actions, limited tools, and treating content as information
Malicious repositoryA project you open contains settings or scripts designed to run harmful commandsTrust prompts, careful review of unknown projects, and sandboxing
Data exfiltrationSecrets or code are sent to an outside placeDeny rules on secrets, network limits, and reviewing outbound actions
Over-broad allow ruleA convenience rule permits more than intendedNarrow patterns and regular review
Supply chain riskAn installed package or connected tool is compromisedReview installs, pin versions, and use trusted sources
Destructive mistakesAn honest error deletes or overwrites workVersion control, backups, and approval for destructive commands
Privilege escalationA command gains rights beyond the user’s normal onesDeny administrator commands and run with minimal rights

The risky trio

Security specialists point to a dangerous combination: access to private data, exposure to untrusted content, and the ability to send things out. When all three are present in one session, a hidden instruction in an untrusted file could lead to private information being sent away. Permissions let you break the chain. You can deny access to private data, avoid fetching untrusted pages in sensitive sessions, or require approval for anything that sends data out.

Open unknown projects with care

When you open a project you did not write, such as one downloaded from the internet, remember that it may carry its own settings and scripts. Claude Code usually asks whether you trust a folder before applying its configuration. Read that question seriously. Review unfamiliar projects first, and for anything doubtful, work inside a disposable environment.

Everyday analogy

Before you run an unknown program that someone handed you on a memory stick, you check where it came from. You do not plug an unlabeled stick into your work laptop. Opening an untrusted project with a powerful assistant deserves the same caution.

!
No setup is risk-free

Permissions reduce risk, but they do not remove it. Keep backups, use version control, and review what Claude changes before you rely on it.

18Monitoring, Logging, and Audit

Good permissions are visible permissions. You should be able to see what was allowed, what was refused, and what actually ran.

Without records, nobody can answer simple questions after an incident: what did Claude run, which files did it change, which approvals were given, and by whom? Records also reveal where permissions are too tight, causing constant prompts, or too loose, allowing risky actions without anyone noticing.

What to keep track of

Commands

What ran

A record of commands executed, with time and the project in which they ran.

Changes

What changed

File edits tracked through version control, so every change can be inspected and undone.

Decisions

Approvals and denials

Which actions were allowed or refused, and which rule or person decided.

Settings

Rule changes

When rules were added or removed, so permission drift can be spotted.

Useful measures

MeasureWhat it showsWarning sign
Prompts per sessionHow much friction the rules causeVery high numbers lead to approval fatigue
Share of actions auto-allowedHow much runs without a personA sudden rise after a rule change
Denials triggeredHow often protections are testedRepeated denials for the same file may signal injection or confusion
Use of the no-checks modeRisky sessionsAny use outside disposable environments
Age of allow rulesStalenessOld rules nobody remembers

Version control is the most important log of all. If Claude’s changes are always committed in small steps with clear messages, you can see exactly what happened and roll back any step. Teams can also use hooks to write their own audit logs of commands and approvals. Protect those logs, because commands and paths can themselves contain sensitive information.

Everyday analogy

A shop has a till roll and a security camera. The till roll lists what was sold, and the camera shows what happened if something goes missing. Neither slows the customers, and together they make problems solvable. Version history and logs play that role for a coding assistant.

i
Practical tip

Commit before a big Claude session and review the differences afterward. A clean starting point makes every change easy to see.

Reviewing after an incident

If something goes wrong, use your records to reconstruct the order of events. Which prompt appeared, who approved it, which rule allowed it, and what ran afterward? Then ask what single change would have prevented it: a deny rule, a narrower allow, a sandbox setting, or a hook. Make that change, and write a short note about it. Treat each incident as a free lesson that makes the next session safer.

19Designing Your Own Permission Policy

A good policy is a few clear decisions, matched to your risk, and reviewed regularly.

A step-by-step method

1

List what is valuable

Secrets, customer data, production systems, and unsaved work. These are what the policy protects.

2

Write the deny rules first

Block secret files, dangerous commands, and production access.

3

Choose a default mode

Pick the mode that matches how reversible your work is.

4

Allow the routine

Add narrow allow rules for the commands you approve every day.

5

Add a wall and guards

Use sandboxing and hooks for what rules alone cannot handle.

6

Test and review

Try the policy on a safe project, then review it every few months.

Starter policies by situation

SituationModeRulesExtra protection
Learning on a personal projectDefault, ask as neededFew allows; deny secretsVersion control
Daily work on a trusted team projectAccept editsAllow test, lint, and build commands; ask for installs and pushesSandbox, code review
Exploring an unfamiliar codebasePlan onlyRead and search onlyDisposable copy of the project
Automation in a pipelineNarrow, set in advanceOnly the exact tools neededDisposable environment, minimal credentials
Regulated or sensitive company workDefault, with managed policyStrict denies; approved tools onlyLogging, audit, and review
Everyday analogy

Setting a household routine for a new babysitter, you start with the essentials: emergency numbers, rooms that are off-limits, and bedtime. Only then do you add the small conveniences, such as which snacks are fine. Safety first and comfort second makes a routine that works at midnight.

i
Keep it small

A policy of a dozen well-chosen rules is easier to understand, test, and maintain than one with hundreds of lines nobody reads.

20Best Practices and Anti-Patterns

A few habits produce safe and pleasant sessions, and a few mistakes cause most of the trouble.

PRACTICE 01 Adopt
What to do

Apply least privilege: give Claude Code only the access the task needs.

Why it helps

If anything goes wrong, whether by mistake or by a hidden instruction, the damage is limited to a small area.

PRACTICE 02 Adopt
What to do

Layer your defenses: deny rules, a sensible mode, a sandbox, version control, and review.

Why it helps

No single layer is perfect, but together they catch what any one would miss.

PRACTICE 03 Adopt
What to do

Share a project policy with the team through the project settings, and review it together.

Why it helps

Everyone starts from the same safe baseline, and new members are protected from day one.

ANTI-PATTERN 01 Avoid
Skipping all checks on a real machine

Turning off every permission check to avoid interruptions.

Why it hurts

A mistake or hidden instruction can run unchecked commands with your real access and credentials.

Do this instead

Use narrow allow rules and the accept-edits mode, and keep the no-checks mode for disposable environments only.

ANTI-PATTERN 02 Avoid
Clicking “always allow” without thinking

Building up broad allow rules from approval prompts.

Why it hurts

Rules accumulate, outlive their purpose, and permit more than you remember.

Do this instead

Approve once when unsure, create allow rules deliberately, and review them regularly.

ANTI-PATTERN 03 Avoid
Starting in a huge folder

Launching Claude Code from the home folder or a drive root.

Why it hurts

Everything beneath becomes reachable, including unrelated projects and private files.

Do this instead

Start in the project folder, and add extra directories only when needed.

ANTI-PATTERN 04 Avoid
Trusting any project you open

Accepting the trust prompt for an unknown repository without looking.

Why it hurts

A project can carry settings or scripts that act in your name.

Do this instead

Review unfamiliar projects first, and use a disposable environment for anything doubtful.

21Troubleshooting Permission Problems

Most surprises come from rules clashing, a wrong scope, or an unexpected mode.

ProblemLikely causeWhat to try
I keep being asked the same thingNo allow rule exists, or a more specific ask rule overrides itAdd a narrow allow rule, and check for ask rules
An action is blocked and I do not know whyA deny rule from another scope, or managed policyList all rules, and check each scope
My allow rule is ignoredA deny or ask rule matches too, or the pattern does not match the command exactlyCheck precedence, and test the pattern on the exact command
A teammate sees different behaviorPersonal settings differ, or a local file overrides the shared oneCompare scopes, and keep shared rules in project settings
Automation fails on a permissionNo person to approve itDecide the permission in advance with narrow rules
Rules seem not to loadA mistake in the settings file, or the file is in the wrong placeCheck the file’s format and location against the documentation
A command works in the terminal but not in ClaudeSandbox or network limitsRead the error, and adjust the sandbox settings deliberately

A calm approach

Start by asking which scope each rule lives in, since the answer often explains a surprise. Then recall the order of strength: deny, then ask, then allow. Finally, test on a safe project with a very simple action. Change one thing at a time and write down what you changed, so you can undo it. If you are in a company environment, remember that managed policy may be the cause, and ask your administrator.

Everyday analogy

When a door will not open, you check the key, the lock, and whether someone has bolted it from inside. You do not start by taking the door off its hinges. Permission problems yield to the same patient order of checks.

i
Practical tip

Keep your permission settings in a tidy, commented form where the format allows it, and note why each rule exists. Future you will be grateful.

22Real-World Scenarios

Six examples show permissions chosen well.

A solo developer on a side project

A developer works alone on a small web app kept under version control. She uses the accept-edits mode so changes flow, allows the test and build commands, asks before installs, and denies reading the environment file. At the end of each session she reviews the differences and commits.

A team sharing a baseline

A team stores a short policy in the shared project settings: allow the lint and test commands, deny reading secret files, and ask before pushing. New teammates get the same safe defaults the moment they open the project. Personal tweaks stay in each person’s own files.

A new codebase to study

An engineer joins a company and needs to understand a large unfamiliar system. He uses the plan-only mode, so Claude reads and explains without changing anything. Once he understands the structure, he switches to a careful mode to make a small, reviewed change.

Safety first, convenience second, and a wall behind both.

A review bot in the pipeline

A company runs Claude Code in its automation to review pull requests. The job can read the code and write comments, but cannot edit files, run arbitrary commands, or reach the network beyond the code host. It runs in a throwaway container with a minimal token, and logs are kept for audit.

An unknown repository from the internet

A developer wants to try a sample project found online. She opens it inside a disposable container, reads its configuration before trusting it, and keeps the plan-only mode at first. Nothing on her main machine is reachable, so any surprise stays inside the container.

A regulated company’s policy

A financial company deploys managed settings that deny access to customer data folders, forbid the no-checks mode, and allow only approved connected tools. Developers can still be productive, because the project rules allow the routine build and test commands. Security staff review logs weekly.

23Frequently Asked Questions

Q1Why does Claude Code ask me before it edits files or runs commands?
Because these actions can change your project or your machine. The default is cautious: reading is easy, while editing and running need your decision unless you have set a rule or a mode that allows them.
Q2What is the difference between a mode and a rule?
A mode is a broad setting for the whole session, such as ask as needed, accept edits, or plan only. A rule is a precise decision about one tool and pattern, such as allowing one specific command. Rules are checked first, and the mode decides what is left.
Q3Which wins, an allow rule or a deny rule?
A deny rule wins over an ask rule, and an ask rule wins over an allow rule. This means a specific refusal always holds, even if another rule is generous.
Q4Where should I put rules for my team?
In the shared project settings, which are kept with the code, so everyone gets them. Personal preferences belong in your user or local settings, and company-wide requirements belong in managed policy.
Q5Is it safe to skip all permission checks?
Only in an isolated, disposable environment with no valuable data or credentials. On your everyday machine, it removes the safety net that protects you from mistakes and hidden instructions.
Q6How do I keep Claude from reading my secrets?
Add deny rules for the files and folders that hold them, pair that with careful command rules and sandboxing, keep secrets out of the repository, and never paste them into a conversation.
Q7Do permissions protect me from prompt injection?
They reduce the damage. Claude is designed to treat outside content as information, and approvals, narrow rules, and sandboxes limit what a hidden instruction could do. They are not a complete guarantee, so stay careful with untrusted content.
Q8What is a sandbox, and do I need one?
A sandbox is an operating-system-level wall that limits which files and network locations commands can reach. It adds a layer behind the rules and is especially valuable for automation and unfamiliar projects. Availability depends on your system, so check the documentation.
Q9Can my company force certain permissions?
Yes. Administrators can deploy managed settings that sit above personal and project settings and cannot be overridden by individuals. If a setting is locked, ask your platform or security team.
Q10Where can I find the current commands and settings?
Names and options change as Claude Code is updated. The official documentation at docs.claude.com is the best source for the current list of modes, rule formats, settings files, hooks, and sandbox options.

24Summary and Key Takeaways

Key Takeaways

  • Permissions guard actions, not intentions. Claude Code works through tools, and each tool use is allowed, asked about, or denied according to risk, even when Claude means well.
  • The default is careful. Reading is easy, while edits and commands need your approval unless a rule or mode allows them. Read each prompt, because it is the moment when you check what will happen.
  • Modes are gears, rules are precision. Choose a mode to match how reversible your work is, and use narrow allow, ask, and deny rules for the details. Deny beats ask, and ask beats allow.
  • Scope decides reach. User, project, local, and managed settings apply to different people. Put team rules in shared project settings and personal choices in personal ones.
  • Protect secrets in layers. Deny rules on sensitive files, careful command rules, sandboxing, and good habits work together because no single layer is perfect.
  • Add a wall and guards. A sandbox limits what any command can reach, and hooks add custom checks that rules cannot express. Never skip all checks outside a disposable environment.
  • Start small, review often. Write deny rules first, add narrow allows for routine commands, keep work under version control, and review your rules regularly. For current names and options, see docs.claude.com.