OmniscioGuidesClaude Code permissions for npm and tests
Claude Code permissions: allow npm, test and build commands
The most common Claude Code permission question is also the smallest one: how do I stop it asking before every npm run test?
Here is the block, what each rule does and does not match, where it belongs, and the way to prove it took effect.
Checked against Anthropic’s Claude Code permission documentation. By the Omniscio team. Updated .
The block
Paste this into a settings.json file. It is valid JSON with no comments, so you can copy it as it is. If the file already has a permissions block, merge these entries into its three arrays rather than replacing it.
{
"permissions": {
"allow": [
"Bash(npm run *)",
"Bash(npm test *)",
"Bash(npm install *)",
"Bash(npx vitest *)",
"Bash(pnpm run *)",
"Bash(yarn run *)"
],
"ask": [
"Bash(npm publish *)"
],
"deny": [
"Bash(npm install -g *)",
"Bash(npm unpublish *)"
]
}
}Three arrays, three jobs. allow runs without asking. ask prompts even when a mode would otherwise approve it. deny refuses, and cannot be overridden by any allow rule.
The deny rule for a global install shows why the order matters. Bash(npm install *) would otherwise approve npm install -g some-cli, because it starts with that prefix. The deny rule is evaluated first, so the global install is refused.
What each rule matches
| Rule | Matches | Does not match |
|---|---|---|
Bash(npm run *) | npm run build, npm run test --watch, npm run | npm install, npm test, npx vitest |
Bash(npm test *) | npm test, npm test -- --watch | npm run test, which the first rule covers |
Bash(npm install *) | npm install, npm install lodash, npm install --save-dev vite | pnpm install, yarn add |
Bash(npx vitest *) | npx vitest, npx vitest run | npx jest, npx with another package |
Bash(pnpm run *) | pnpm run build, pnpm run | pnpm install |
Bash(yarn run *) | yarn run build, yarn run | yarn add |
Four details explain the table:
- A
*stands in for any text, including spaces.Bash(npm run *)matches every script name and every flag after it. A rule with no*matches one exact command and nothing after it, soBash(npm run build)does not matchnpm run build --watch. - A trailing
*with a space before it also matches the bare command. That is whyBash(npm run *)covers plainnpm run, andBash(npm install *)covers plainnpm install. - The space is part of the rule.
Bash(npm run*)is a different rule fromBash(npm run *), and the permission dialog writes the space-separated form when you save a prefix from a prompt. npxruns whatever package name comes after it. It is not one of the wrappers Claude Code strips before matching, so a rule such asBash(npx *)would approve every package name, not only your test runner. Name the package.
Two shapes are worth knowing even though this block does not use them. A wildcard before the subcommand, such as Bash(npm * install), is a wildcard pattern rather than a prefix rule: the text after the * still has to appear, so it does not cover plain npm install, and an allow rule shaped that way earns a startup warning. Put the * after the subcommand instead. And a compound command runs without a prompt only when every part is allowed: npm run build && rm -rf dist still prompts, because rm is not in the list.
Where the block goes
| File | Who it reaches | Use it when |
|---|---|---|
.claude/settings.json | Everyone who works in the folder, once the file is committed | The whole team should stop being asked for the same commands |
.claude/settings.local.json | You, in this project only | You want the rules now, without a commit |
~/.claude/settings.json | You, in every project on this machine | You want npm scripts approved everywhere |
Two behaviours surprise people here:
- A project’s allow rules wait for trust. Rules in a committed
.claude/settings.jsontake effect only after you accept the workspace trust dialog for that folder. Deny and ask rules are not affected, because they only restrict. - Lists merge across files. If your user file allows
Bash(git status)and the project file allowsBash(npm run *), both apply. Writing a new list does not remove another file’s entries.
A rule that came from approving a prompt is saved to .claude/settings.local.json at the root of the git repository, and applies to future sessions anywhere in that repository. Outside a git repository, or on Windows, Claude Code saves it somewhere else, and /permissions is where you see where it landed. That is why a one-off “yes, don’t ask again” can look like it came from nowhere later.
The settings files and their precedence in full are on the settings.json locations page.
Confirm it took effect
- Run
/permissions. It lists every rule Claude Code loaded and thesettings.jsonfile each rule came from. Your six allow rules should be there. - Ask Claude to run
npm run build. It should run with no prompt. Then ask fornpm install -g some-cli: it should be refused. - If a rule is missing, check
/statusfor which settings files loaded, and runclaude doctorto list entries Claude Code rejected.
Most settings edits reach a running session without a restart, permissions included. A rule you add or remove in the /permissions dialog applies starting with Claude’s next tool call in the same turn.
For a single session, --allowedTools adds the same allow rules from the command line, and --disallowedTools adds deny rules. A deny from any settings file still blocks a tool the flag names as allowed.
The common mistake
Writing "allowedTools" into settings.json. That name is the one-session command-line flag, not a key a settings file reads. A settings file takes the rules under permissions.allow; --allowedTools adds the same rules for one run.
Approving one command instead of a family. Bash(npm run build) looks like it should cover builds, but it matches that exact string and nothing else, so npm run build --watch prompts again. Write Bash(npm run *) for the family, and keep exact rules for the commands you want pinned.
The mirror mistake is the broad one: Bash(npm *) approves npm publish too. If you want the scripts but not the publish, allow Bash(npm run *) and put Bash(npm publish *) in ask or deny.
A third: expecting the allow list to survive a wrapper it does not strip. Bash(npm run *) matches timeout 30 npm run build, because timeout is one of the wrappers Claude Code strips before matching. It does not match sudo npm run build: sudo is not on that list, so the command no longer starts with npm run.
Variations worth having
- Lock installs out entirely. Move
Bash(npm install *)todenyand keep only the run rules. Claude can still run the scripts; adding a dependency becomes your job. - Allow one test runner instead of the workspace. Replace
Bash(npm test *)withBash(npx vitest *), which leavesnpx jestprompting. Watch out:npm testnow prompts again too. - Read-only CI. For a session that should only verify, allow
Bash(npm run lint),Bash(npm run test)andBash(npm run build)exactly, and deny an install. Exact rules make a reviewable list.
If you would rather assemble the block than type it, the permissions builder takes a tool and a specifier and writes the rule. The full format, including the evaluation order and the wildcard rules, is on the permission rules examples page.
Where these answers come from
- Wildcards, the trailing-
*rule, compound commands and the stripped wrappers: Configure permissions, read November 25, 2026. - The three arrays and their keys: Settings reference.
- Where each settings file lives and which wins: Settings files and precedence.
- The one-session flags: CLI reference.
Common questions
Does Bash(npm run *) also allow npm install?
No. The rule matches commands that begin with npm run, so npm install does not match. Add a separate Bash(npm install *) rule if you want installs approved.
Why does npm test still prompt when I allowed npm run *?
Because npm test is its own command, not an npm run invocation. Allow Bash(npm test *) as well, or call the script through npm run.
Can I allow npm scripts but block publishing?
Yes. Allow Bash(npm run *) and put Bash(npm publish *) in ask or deny. Deny and ask rules are evaluated before allow rules, so the refusal wins even though the allow rule also matches.
Does the rule survive a compound command?
Only while every part is allowed. npm run build && npm run test runs when both rules exist; npm run build && rm -rf dist prompts, because nothing allows the rm.