Skillforge Field notes on shipping with AI tools

Claude Code Bash Allow Rule Warning: * in a Variable's Value

claude-codepermissions

If Claude Code starts printing "has a * in a variable's value" about one of your allow rules, the rule is wider than you meant. A rule such as Bash(PORT=* npm run dev) looks like "allow npm run dev with any port", but the * also matches spaces, so it can approve other commands that merely contain npm later in the line. The fix is to give the variable an exact value, for example Bash(PORT=3000 npm run dev).

Verified against: Claude Code 2.1.325 on 2026-11-16, and the permissions page on code.claude.com fetched the same day. We ran claude doctor against several settings files and quote its output below. We did not run a live permission prompt, so how a rule actually matches a given command is as documented, not observed.

What the warning says

The warning arrived in 2.1.323. The changelog entry reads: "Added a start-up warning for Bash allow rules with a * in a variable's value, such as Bash(PORT=* npm run dev)."

We put that exact rule in a user settings file and ran claude doctor. It printed this, under the heading "Permission rules that may not work as written":

Permission allow rule (../home/.claude/settings.json): Bash(PORT=* npm run dev) has a * in a variable's value. A * also matches spaces, so this rule can also approve a different command that has npm later in the line, without a prompt. Give the variable an exact value instead.

The same message appeared when we started a claude -p session with the rule in a settings file, so you see it at startup, not only in claude doctor.

Why a * in a value is risky

The permissions page says Bash rules match the whole command text, with * standing in for any text. It does not stop at a space. In PORT=* npm run dev, the * is not limited to a port number. Per the warning text, it can swallow whole words, so a command that has npm somewhere after the wildcard can match the rule and run without a prompt.

We did not construct such a command and watch it run, so treat the exact bypass shapes as the warning describes them, not as something we reproduced. The takeaway needs no reproduction: a wildcard inside a variable assignment is a wildcard over a command line.

What triggers it, and what does not

We tried these allow rules in claude doctor on 2.1.325:

| Rule | Warned? | | :- | :- | | Bash(PORT=* npm run dev) | Yes | | Bash(NODE_ENV=* npm test) | Yes | | Bash(FOO=a* npm run dev) | Yes, a partial wildcard in the value counts | | Bash(PORT=*:* npm run dev) | Yes | | Bash(HOST=* node *) | Yes | | Bash(PORT=3000 npm run dev) | No | | Bash(PORT=3000 *) | No | | Bash(npm run dev *) | No |

The pattern is simple: the warning fires when the * sits inside the value of a leading variable assignment. A trailing * after the command, which is the normal way to allow arguments, does not trigger it.

We also tried the same shape in deny and ask rules (Bash(PORT=* rm *) and Bash(X=* git push *)) and got no warning. That fits the documentation, which says a deny or ask rule matches past any leading assignment, so a wide match there errs toward prompting or blocking. The warning is about allow rules, where a wide match approves more.

How to fix the rule

Pick the variant that matches what you actually want to allow:

  1. One known value. Write the value out: Bash(PORT=3000 npm run dev).
  2. A few known values. Add one rule per value. It is more lines, and each one says exactly what it allows.
  3. Any value, same command. Drop the assignment from the rule and write Bash(npm run dev *) or Bash(npm run dev). Whether that covers a command with the variable in front depends on the next section.

Leading assignments and allow rules

The permissions page says Claude Code strips a leading assignment of "certain known-safe environment variables" before matching, so Bash(npm test *) matches NODE_ENV=test npm test. It then says an allow rule "won't match past an assignment of any other variable." In other words, Bash(npm run dev) should not approve PORT=3000 npm run dev unless PORT is one of the known-safe variables, and the page does not publish that list.

That is the reason people reach for PORT=* in the first place: the plain rule did not match, so they widened it. We have not tested which variables count as known-safe, and we would not guess. If you depend on a variable being stripped, write the exact-value rule above, which works whether or not the variable is on the list.

The same page says a deny or ask rule does match past any leading assignment, so Bash(rm *) in deny still matches FOO=bar rm -rf tmp/.

Find and clean up existing rules

Rules like this tend to come from the "Yes, and don't ask again" prompt or from copied settings. To find them, search your settings files for an = followed by * inside a Bash( rule:

grep -nE 'Bash\([A-Za-z_][A-Za-z0-9_]*=[^ )]*\*' \
  ~/.claude/settings.json .claude/settings.json .claude/settings.local.json 2>/dev/null

Then run claude doctor once. It lists each flagged rule with the file it came from, which is quicker than reading the files by eye.

FAQ

What does "has a * in a variable's value" mean in Claude Code?

One of your Bash allow rules starts with a variable assignment, such as PORT=*, and the * is inside the value. Because * matches any text including spaces, the rule is broader than "any port". Replace the * with an exact value.

Which Claude Code version added this warning?

2.1.323, according to the changelog. We confirmed it prints on 2.1.325.

Does the warning block the rule from working?

The heading says the rules "may not work as written", and the text says the rule can approve more than you intended. We did not test whether the rule still matches, only that the warning prints.

Is it a problem in deny or ask rules?

We saw no warning for a wildcard assignment in deny or ask rules. Per the permissions page, those rules match past any leading assignment anyway.

How do I allow a command that needs an environment variable?

Write the exact assignment into the rule, as in Bash(PORT=3000 npm run dev). Alternatively set the variable through the env key in settings, so the command itself carries no assignment and a plain command rule applies.