Skip to content

fix(claude-config): permission-rule-check flags rule forms its own criteria exempt, prints a fragment, and has no inert-grant check #2282

Closed

Description

@kyle-sexton

permission-rule-check.sh fires an error on two rule forms its own criteria.md declares exempt and
the official docs present as correct, prints an eight-character fragment instead of the rule at fault,
misses the one non-portable form on this platform that genuinely violates the convention, and has no
check at all for the inert-grant shape that is the most common real defect in this fleet. All five sit
in one file and its test suite, and the suite passes 72/72 today because none of these cases is in it.

Rows

  • A2 — scripts/permission-rule-check.sh:153-159 vs reference/criteria.md:64-65 — criteria.md says //… forms are not flagged; P2_ERE has no // exemption, so Read(//Users/alice/secrets/**) — the docs' own literal example — produces a P2 error.
  • A3 — scripts/permission-rule-check.sh:174-175 — P2 feeds grep -oE "$P2_ERE" straight into the finding, so it prints an eight-character fragment (/Users/k) rather than the offending rule, violating the intent stated for P1 six lines earlier.
  • A19 — scripts/permission-rule-check.sh:138, :144 — P1_ERE alternative 3 lets the required * sit arbitrarily far past the manager name, so Bash(npm view ctx7 version*) is flagged as a bare package-manager wildcard although every meaningful token is pinned.
  • A12 — scripts/permission-rule-check.sh:156 — Bash(~kyle/scripts/x.sh:*) leaks a username and is not flagged. %USERPROFILE% / $env:USERPROFILE forms are also missed, but those are a different defect and must not be filed under P2 — see below.
  • A7b — scripts/permission-rule-check.sh (no such check exists) — nothing detects the inert ${CLAUDE_PLUGIN_ROOT}-in-allowed-tools shape, which is the check that would have caught every one of the seven grants fix(plugins): paired body+rule rewrite for seven interpreter-led allowed-tools grants #2221/fix(plugins): pair seven allowed-tools grants with the invocations they must match #2225 had to fix by hand.

Evidence

A2 — the // exemption is claimed and does not exist

reference/criteria.md:64-65 at HEAD:

**How to check**: run the detector. `${CLAUDE_PROJECT_DIR}/…`, `~/…`, and `//…` forms are not flagged
(they expand or are portable anchors); only concrete usernames match.

scripts/permission-rule-check.sh:153-159 — the pattern, unchanged at HEAD:

_sl='/'
_bs='\'
_seg="[^${_sl}${_bs}*<>\${}~ ]"
P2_ERE="${_sl}Users${_sl}${_seg}"                                    # macOS + POSIX-normalized Windows (/c/Users/…)
P2_ERE="${P2_ERE}|${_sl}home${_sl}${_seg}"                           # Linux
P2_ERE="${P2_ERE}|[A-Za-z]:[${_sl}${_bs}]Users[${_sl}${_bs}]${_seg}" # raw Windows drive

Reproduced by assembling the shipped fragments verbatim and piping through grep -oE:

$ printf '%s\n' 'Read(//Users/alice/secrets/**)' | grep -oE "$P2_ERE"
/Users/a
$ printf '%s\n' 'Read(~/Documents/*.pdf)' | grep -oE "$P2_ERE"     # (no output — correctly exempt)

Mechanism: _seg excludes ~, $, {, < but not /, and the ERE is unanchored, so a leading
extra / is simply skipped over. The ~/ exemption works; the // exemption claimed on the same
criteria.md line does not exist.

https://code.claude.com/docs/en/permissions § Read and Edit, fetched 2026-08-11 — table row:
`//path` | Absolute path from filesystem root | `Read(//Users/alice/secrets/**)` | `/Users/alice/secrets/**`. The false positive fires on the documentation's own literal example, in
the check graded highest, and the two shipped files disagree with each other so a maintainer reading
criteria.md cannot predict the detector.

This row was recorded as corroborating evidence inside #2248 and was not fixed by it. #2248's fix
(merged as #2259) rewrote P2's rationale; P2_ERE is byte-identical to what it was before. Filing it
here so it does not stay parked inside a closed issue.

A3 — the finding prints a fragment, not the rule

scripts/permission-rule-check.sh:174-175 feeds grep -oE "$P2_ERE" straight into $m. Reproduced:

$ printf '%s\n' 'Bash(/c/Users/kyle/x.sh:*)' | grep -oE "$P2_ERE"
/Users/k

The stated intent is in the same file, scripts/permission-rule-check.sh:140-141, attached to P1_ERE
only:

# Each alternative captures the whole Tool(...) spec (trailing [^)]*\) ) so a
# finding reports the full offending rule, not a substring truncated at the *.

P2_ERE has no such trailing capture, so the error-tier finding is unactionable as printed: an
operator cannot tell which of several rules is at fault. Same-file fix as A2.

A19 — a fully-pinned package-manager rule is flagged

scripts/permission-rule-check.sh:138 and :144:

_runner='npx|bunx|uvx|pnpm dlx|yarn dlx|pipx run|uv run|npm|pnpm|yarn'
P1_ERE="${P1_ERE}|(Bash|PowerShell)\\([\"' ]*(${_runner})([\"' :][^)]*)?\\*[^)]*\\)"

The ([\"' :][^)]*)? group accepts a separator followed by any run of non-) characters, so the
required \* may sit arbitrarily far past the manager name. Bash(npm view ctx7 version*) therefore
matches even though every meaningful token is pinned. The script's own comment states the contract the
regex does not deliver — "A fixed subcommand (Bash(npm test), Bash(npm run build)) carries no *
and is not matched" — and reference/criteria.md:44-46 now restates it: "Each P1 alternative requires a
wildcard, so an exact narrow rule … is not flagged". A trailing * after a fully-pinned subcommand is
not the bare-wildcard shape the check aims at.

The rule being violated: docs/conventions/permission-rule-hygiene/README.md:99-100 — "A fixed
package-manager subcommand … carries no wildcard, carries over into auto mode, and is not flagged."
https://code.claude.com/docs/en/permission-modes, fetched 2026-08-11: "Narrow rules like
Bash(npm test) carry over." npm view is not a run command and grants no arbitrary execution.

Why this row exists at all: the originating item filed a defect against a live plugin
(context7/setup, Bash(npm view ctx7 version*)) that turned out to be a non-defect — the flag was
this regex over-reach, not the rule. Its real cost is auditor credibility, and without this row nothing
in the ledger carries the fix.

Fix shape: bound the intervening span so Bash(npm *), Bash(npm:*), and Bash(npx *) still match
while Bash(npm view ctx7 version*) does not, and add both a positive and a negative case — the suite
has neither, which is why 72/72 passes today.

A12 — one real miss, and two that need a convention change first

Reproduced against the shipped P2_ERE; all three produce no output:

$ printf '%s\n' 'Bash(%USERPROFILE%/scripts/x.sh:*)' 'Bash($env:USERPROFILE\scripts\x.sh:*)' 'Bash(~kyle/scripts/x.sh:*)' | grep -oE "$P2_ERE"
(no output)

The detector does scan PowerShell(...) (P1_ERE at :142-145, scan_bare_tool at :191), so the
Windows surface is in scope.

Split the row, and do not file the whole of it under P2. Checked against
docs/conventions/permission-rule-hygiene/README.md:106-118, whose anti-pattern 2 is scoped to
"hardcoded absolute machine/user paths" that "leak a username into version control":

  • Bash(~kyle/scripts/x.sh:*) — does violate it. It leaks a username and ~user is not expanded in a Bash rule. This is the P2 miss.
  • %USERPROFILE% / $env:USERPROFILE — leak no username and are not absolute. They are a different defect (an unexpandable token making the rule inert, the same class as A7b), which no convention rule currently names. Filing them under P2 would be inventing a rule. Fold them into A7b's new inert-grant check instead.

https://code.claude.com/docs/en/permissions, fetched 2026-08-11 — the § Wrappers paragraph confirms
the only env handling in Bash rules is stripping a leading assignment of known-safe variables;
nothing expands %VAR% or $env:VAR mid-string, so those rules cannot match.

A7b — no check for the inert-grant shape

The detector has no such check by construction. _seg at scripts/permission-rule-check.sh:156
explicitly excludes $ and {:

_seg="[^${_sl}${_bs}*<>\${}~ ]"

so every ${…} form — correct or inert — is exempted from P2. P1_ERE matches the bash prefix but
says nothing about the variable. Confirmed empirically: the fleet's inert grants were flagged only as
P1.

The question the originating item left open is settled, and the fix should not carry the ambiguity.
https://code.claude.com/docs/en/skills, fetched 2026-08-11: "Claude Code substitutes
${CLAUDE_SKILL_DIR} and ${CLAUDE_PROJECT_DIR} in two places: the skill's markdown content, and Bash
rules in the allowed-tools frontmatter." ${CLAUDE_PLUGIN_ROOT} does not appear anywhere on that
page. https://code.claude.com/docs/en/plugins-reference § Environment variables scopes its broad row
to content, not frontmatter ("| Skill and agent content | Anywhere the placeholder appears |"), and
frontmatter is not content. This repo's own convention already ruled on it at
docs/conventions/permission-rule-hygiene/README.md:125-126: "${CLAUDE_PLUGIN_ROOT} is not among
them … so a rule written with it stays a literal string, never matches, and the grant is inert." The
item's contrary "working reading" rests on a third-party comment in anthropics/claude-code#55382 and
is not doc-supported.

Design constraint (from the packet's own correction, verified): the new check must branch, not
emit a flat remedy. If the referenced path resolves inside the scanned file's own skill directory →
recommend the ${CLAUDE_SKILL_DIR} form. Otherwise → recommend relocation, and not plugin bin/
(see the sibling issue in this batch on the remediation surface, and the Known gap at
docs/conventions/permission-rule-hygiene/README.md:177-179). The detector already knows which file it
is scanning, so the branch is computable.

Adjacent, deliberately not duplicated

Provenance

Severity: MED · Provenance: AUDITOR_VERIFIED for A2, A3, A7b, A12. A19 is SELF_REPORTED — it was produced by the validation pass in the consuming session while disproving the item's context7 row, with no independent audit behind it; its mechanism was verified by reading the assembled ERE and by reproduction. Every reproduction above was re-run against the shipped fragments at HEAD.
Origin: handoff-inbox item 20260811-024628-claude-config-audit-permission-grants-defects-and-fleet-grant-hygiene
Ledger: .work/handoff-inbox-batch-4/ledgers/I10-permission-grants-fleet.md § A2, A3, A7b, A12, A19
Verified against repo HEAD 9b34a82a. Line anchors re-derived at that commit — #2259 added 52 lines to the detector, so every ledger anchor past line 76 has moved.

Activity

  1. added
    needs-triage
    on Aug 12, 2026
  2. kyle-sexton commented on Aug 12, 2026

    @kyle-sexton
    MemberAuthor

    Re-verification at origin/main — all five rows reproduce, but A19's anchors moved

    Anchors here were taken at 9b34a82a. e48b141a (#2260) has since extracted the P1 rule vocabulary out of the detector into a new define-only library, so two of this issue's file:line anchors are stale. The defects themselves are unchanged. Everything below is a command I ran at origin/main, with its output.

    A19 — anchors moved to plugins/claude-config/lib/permission-patterns.sh:59-61

    P1_ERE is no longer built in the detector. It is assigned from the library:

    $ grep -rn 'P1_ERE=\|_runner=\|CCPERM_RUNNER_BODY' plugins/claude-config/skills/audit-permission-grants/ plugins/claude-config/lib/
    .../scripts/permission-rule-check.sh:141:P1_ERE="$CCPERM_P1_ERE"
    plugins/claude-config/lib/permission-patterns.sh:58:CCPERM_P1_ERE="(Bash|PowerShell)\\(\\*\\)"
    plugins/claude-config/lib/permission-patterns.sh:59:CCPERM_P1_ERE="${CCPERM_P1_ERE}|(Bash|PowerShell)\\([\"' ]*([^)\"' ]*[/\\\\])?(${CCPERM_INTERP_BODY})([\"' :][^)]*)?\\*[^)]*\\)"
    plugins/claude-config/lib/permission-patterns.sh:60:CCPERM_P1_ERE="${CCPERM_P1_ERE}|(Bash|PowerShell)\\([\"' ]*(${CCPERM_RUNNER_BODY})([\"' :][^)]*)?\\*[^)]*\\)"
    plugins/claude-config/lib/permission-patterns.sh:61:CCPERM_P1_ERE="${CCPERM_P1_ERE}|(Bash|PowerShell)\\([\"' ]*\\*[^)]*\\.(${CCPERM_SCRIPT_BODY})[^)]*\\)"
    

    The over-reaching group the row names — ([\"' :][^)]*)? before the required \* — is intact on both the interpreter alternative (:59) and the runner alternative (:60). Fix it at the new location, and note the blast radius grew: lib/permission-patterns.sh is now a shared library with a second consumer (audit-permission-state), so a change there is no longer scoped to one detector. It has its own lib/permission-patterns.test.sh, which is where the positive/negative pair belongs.

    Reproduced against the shipped library, sourced verbatim:

    $ . plugins/claude-config/lib/permission-patterns.sh
    $ printf '%s\n' 'Bash(npm view ctx7 version*)' | grep -oE "$CCPERM_P1_ERE"
    Bash(npm view ctx7 version*)          # flagged — the false positive
    $ printf '%s\n' 'Bash(npm test)' | grep -oE "$CCPERM_P1_ERE"
                                          # (no output — correctly not flagged)
    

    So the contract the script's own comment states — "A fixed subcommand … carries no * and is not matched" — holds for the no-wildcard case and fails for a trailing * after a fully-pinned subcommand, which is the shape the row is about.

    A2, A3, A12 — reproduce unchanged; P2_ERE is still built in the detector

    P2_ERE was not extracted; it is still assembled at scripts/permission-rule-check.sh:152-155, so those anchors are only slightly shifted. Reproduced by assembling the shipped fragments verbatim:

    $ _sl='/'; _bs='\'; _seg="[^${_sl}${_bs}*<>\${}~ ]"
    $ P2="${_sl}Users${_sl}${_seg}|${_sl}home${_sl}${_seg}|[A-Za-z]:[${_sl}${_bs}]Users[${_sl}${_bs}]${_seg}"
    
    $ printf '%s\n' 'Read(//Users/alice/secrets/**)' | grep -oE "$P2"
    /Users/a            # A2 — the `//` exemption criteria.md claims does not exist,
                        #      and this is the permissions page's own literal example
    
    $ printf '%s\n' 'Bash(/c/Users/kyle/x.sh:*)' | grep -oE "$P2"
    /Users/k            # A3 — an 8-character fragment, not the offending rule
    
    $ printf '%s\n' 'Bash(~kyle/scripts/x.sh:*)' | grep -oE "$P2"
                        # A12 — (no output) the real miss: leaks a username, not flagged
    

    All three land exactly as filed.

    A7b — no change

    Still no inert-grant check by construction: _seg excludes $ and {, so every ${…} form is exempt from P2.


    One sequencing consequence. Because P1_ERE now lives in a shared lib/ with two consumers, A19's fix touches a file outside skills/audit-permission-grants/. That is still inside claude-config, so it stays in this lane, but it is worth knowing before the diff is written.

    Verified at origin/main (post-#2301). Lane CC, handoff-inbox batch 4 wave 2.

  3. kyle-sexton commented on Aug 12, 2026

    @kyle-sexton
    MemberAuthor

    Correction to my own comment above — A2's premise does not survive the docs

    In my re-verification comment I reproduced A2 and reported it as confirmed:

    /Users/a   # A2 — the ``//`` exemption criteria.md claims does not exist, and this is the permissions page's own literal example

    The reproduction is correct — Read(//Users/alice/secrets/**) does produce a P2 error, and criteria.md:64-65 does claim //… forms are exempt. What I did not do is check whether criteria.md's claim is true. It is not, and that changes which side of the inconsistency should move.

    criteria.md:64-65 groups three forms together and gives one shared rationale:

    ${CLAUDE_PROJECT_DIR}/…, ~/…, and //… forms are not flagged (they expand or are portable anchors)

    That rationale holds for the first two and fails for the third. https://code.claude.com/docs/en/permissions, raw markdown fetched 2026-08-12, line 279:

    Pattern Meaning Example Matches
    //path Absolute path from filesystem root Read(//Users/alice/secrets/**) /Users/alice/secrets/**
    ~/path Path from home directory Read(~/Documents/*.pdf) /Users/alice/Documents/*.pdf

    ~/ expands per user — portable. // is the absolute anchor: it resolves to /Users/alice/secrets/**, hardcoding the username. Line 285 of the same page is explicit that this is //'s whole purpose:

    A pattern like /Users/alice/file isn't an absolute path. The single leading slash anchors at the settings source, not the filesystem root. Use //Users/alice/file for absolute paths.

    So //Users/alice/… is not an exception to "hardcoded machine path" — it is the canonical spelling of one. P2's own finding text says the rule "names a concrete user home, so it breaks on other machines and usernames and leaks a username into source control", and the documentation's example leaks alice.

    What this means for A2

    The inconsistency A2 reports is real: criteria.md and the detector disagree, and a maintainer reading criteria.md cannot predict the detector. That part stands and is worth fixing.

    The direction the row implies is, I now think, backwards. A2 is written as "the // exemption is claimed and does not exist", which reads as make the exemption real. Doing that makes P2 blind to the docs' own canonical hardcoded-path spelling — a false negative on an error-tier check whose entire purpose is catching a leaked username. The alternative resolution is to drop // from criteria.md's exemption list, leaving the detector's current behavior correct and fixing the document instead. That lands naturally in #2284, which owns criteria.md's staleness.

    I am not editing the row unilaterally; this is a maintainer call, and it is now raised on the PR that implements it.

    Where this is live

    #2382 implements A2 in the make-the-exemption-real direction. I have left it a COMMENT review with two unresolved inline threads (GitHub refuses REQUEST_CHANGES on a same-account PR), covering this premise plus two things I measured on that branch:

    • A coverage regression. The new P2_RULE_ERE anchors on (Read|Edit|Write|Bash|PowerShell)\(, so a hardcoded machine path in a WebFetch(...), Agent(...), Glob, Grep, NotebookEdit, or mcp__* rule is no longer flagged at all. The pattern it replaces matched the path regardless of tool, and this file has a dedicated scan_agent(), so Agent is unambiguously in scope. Not requested by A2 or A3.
    • An over-broad exemption. The skip is [[ "$m" == *"(//"* ]], a substring test on the whole rule, so Read(//opt/data/../Users/kyle/secrets) is silently clean despite naming a concrete user home.

    A3 and A19 on that PR I verified by execution and they are correct.

    Recording the class, since this batch has been counting them: this is a fourth instance of a real symptom paired with a false stated mechanism — and the first one I introduced myself, by re-verifying a reproduction without re-verifying its rationale. Reproducing the symptom is not the same as checking the mechanism.


    Lane CC, handoff-inbox batch 4.

  4. added a commit that references this issue on Aug 12, 2026
    0a83e26
  5. added a commit that references this issue on Aug 12, 2026
    3bd8238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions