skip to content

In Claude Code Read and Edit permission rules, what do the `//`, `~/`, `/` and `./` path prefixes each anchor to?

level: seniorimportance: nice to knowfreq 7%

answer

  1. four prefixes, four anchors
  2. one slash is not absolute
  3. depends on which file holds it
  4. allow and deny differ in depth

basics

~20 s

//path is absolute from the filesystem root, ~/path starts at your home directory, /path is relative to the settings source (the project for project settings, ~/.claude for user settings), and path or ./path is relative to the current directory.

solid answer

~40 s

Read and Edit rules use gitignore patterns with four anchors. `//path` is absolute, so `Read(//etc/**)` means `/etc`. `~/path` starts at your home directory. A single leading `/path` is **relative to the settings source**: the primary working directory for project and local settings and for CLI or session rules, `~/.claude` for user settings, and the file's own directory for `--settings <file>`. `path` or `./path` is relative to the current directory. The classic trap is writing `Read(/secrets/**)` in `~/.claude/settings.json` and blocking `~/.claude/secrets` instead of anything in your projects; use `//` or `~/` there. Depth also differs by rule type: as an allow rule `Edit(src/**)` covers only `<cwd>/src`, while as a deny or ask rule it matches a `src` directory at any depth; `**/src/**` matches at any depth in every list.

go deeper

for a junior

Recall the four prefixes: double slash for absolute, tilde for home, single slash for the settings source, and none or ./ for the current directory.

for a middle

Explain how a single-slash rule resolves differently in project, user and --settings files, and why the allow and deny depths differ.

for a senior

Catch the user-settings trap and rewrite it with // or ~/, and know that only Read and Edit path rules are ever consulted.

for a principal

Choose anchors for an organisation-wide baseline so rules mean the same thing on every machine and in every checkout and worktree.

## Why path rules need anchors Claude Code checks file access against `Read(path)` and `Edit(path)` rules. `Edit` rules apply to every built-in tool that edits files; `Read` rules apply to the Read tool and, best-effort, to Grep, Glob and `@` file mentions. The patterns use **gitignore syntax**, where `*` matches within one path segment and `**` across directories. What makes them tricky is the **prefix**, which decides where the pattern starts. ## The four anchors | Pattern | Anchored at | Example | Matches | | :- | :- | :- | :- | | `//path` | filesystem root | `Read(//Users/alice/secrets/**)` | `/Users/alice/secrets/**` | | `~/path` | home directory | `Read(~/Documents/*.pdf)` | `/Users/alice/Documents/*.pdf` | | `/path` | the settings source | `Edit(/src/**/*.ts)` | `<primary working directory>/src/**/*.ts` in project settings | | `path` or `./path` | current directory | `Read(*.env)` | `<cwd>/*.env` | The documentation warns about the third row directly: **a pattern like `/Users/alice/file` is not an absolute path**. One leading slash anchors at the settings source; two slashes mean the filesystem root. ## What "the settings source" means The same `/path` rule resolves differently depending on the file that holds it: | Rule defined in | `/path` resolves to | | :- | :- | | `.claude/settings.json` (project) | `<primary working directory>/path` | | `.claude/settings.local.json` (local) | `<primary working directory>/path` | | `~/.claude/settings.json` (user) | `~/.claude/path` | | a file passed with `--settings <file>` | `<directory of that file>/path` | | CLI flags or session rules | `<primary working directory>/path` | A rule added through `/permissions` follows the row of the file it is saved to. In a worktree session, a shared rule such as `Edit(/src/**)` matches that worktree's own `src/`. The consequence: a platform engineer who adds `Read(/secrets/**)` to user settings, meaning "never read a secrets folder in any project", has actually blocked `~/.claude/secrets/**`. For a user-level rule that applies inside every project, use `//` or `~/`, for example `Read(//**/.env)` or `Read(~/.aws/**)`. ## Depth: allow rules and deny rules differ Within its anchor, how deep a pattern reaches depends on its shape, and for a **relative pattern with one directory segment** also on the list it sits in: - **Allow**: `Edit(src/**)` matches only `<cwd>/src` and below. Write `Edit(**/src/**)` to allow a `src` at any depth. - **Deny and ask**: `Read(secrets/**)` matches a `secrets` directory **at any depth** under the current directory, so nested copies are covered too. - **Every other shape** behaves the same in all lists: `Edit(/src/**)` and `Edit(src/components/**)` are fixed to their location, `Edit(**/src/**)` matches anywhere. - **Bare filenames** follow gitignore semantics and match at any depth: `Read(.env)` equals `Read(**/.env)`. The asymmetry is protective: a deny generalises to nested copies, an allow does not accidentally grant them. ## Other details worth knowing 1. **Only `Read` and `Edit` paths are consulted.** A path rule on `Write`, `NotebookEdit`, `Glob` or the legacy `MultiEdit` is accepted but never checked, and Claude Code warns at startup; use `Edit(docs/**)` instead of `Write(docs/**)`. 2. **Symlinks** are checked on both ends: an allow needs both the requested path and its target to match, while a deny applies when either does. 3. **Windows paths** are normalised to POSIX form, so `C:\Users\alice` becomes `/c/Users/alice`; `//c/**/.env` matches `.env` files anywhere on that drive. 4. **Parentheses need no escaping**: `Edit(./Finance (2024)/**)` matches the folder as spelled. ## Working directories are a separate scope Path rules decide what a matching access does; the **working directories** decide where Claude may read without asking at all. `--add-dir <path>` at launch, `/add-dir` during a session, or `permissions.additionalDirectories` in settings extend that set: files there become readable without prompts and edits follow the permission mode. They grant file access, not configuration, and a project's `additionalDirectories` apply only after workspace trust. ## A quick resolution checklist 1. Which file holds the rule? That fixes what a single leading `/` means. 2. Which list is it in? That decides how deep a one-segment relative pattern reaches. 3. Is the tool `Read` or `Edit`? Any other tool name with a path is never consulted. ## Why it is asked Path anchors are where a well-intended rule most often protects the wrong directory. A candidate who can resolve a rule against the file that holds it, and knows that allow and deny reach different depths, writes rules that block what they meant to block.

  • How do `--add-dir` and `permissions.additionalDirectories` relate to Read and Edit rules?
    They widen the working directories rather than adding rules. Files in an added directory become readable without prompts and edits follow the permission mode, while deny rules still apply. `--add-dir` and `/add-dir` last for the session; `permissions.additionalDirectories` persists. Both grant file access, not configuration: most `.claude/` content there is not loaded, and the settings key loads none of it.
  • Why does a `Write(docs/**)` deny rule fail to protect `docs/`?
    Claude Code checks file paths only against `Read(...)` and `Edit(...)` rules. A path rule written for `Write`, `NotebookEdit`, `Glob` or `MultiEdit` is accepted but never consulted, and Claude Code warns at startup. `Edit(docs/**)` covers every built-in tool that edits files, Write included. A bare `Write` with no path is different: it matches at the tool level.

  • Read(/Users/alice/secrets/**) is an absolute path rule
  • /path in user settings anchors at the current project
  • Edit(src/**) as an allow rule also covers nested src folders
  • Write(docs/**) in deny stops Claude from writing to docs
  • --add-dir makes the added folder's settings and hooks load too