Skip to content

Directory rules and access grants

Hide folders from people and agents, or limit a person to named paths and regions of a file, and what a limited reader sees in browse, search, the API, MCP, caissons, git and CI.

Directory rules and access grants decide who reads which paths in a repository. The server enforces them on every surface, so a hidden folder is not in the file tree, in search, in the API, in an MCP tool or in a caisson. Both are set by a repository admin, per repository, and apply on every branch and at every commit.

There are two tools, and they work in opposite directions.

Directory ruleAccess grant
What it doesHides a path from everyone except the people and teams it namesLimits the people and teams it names to the paths its grants give
Who it limitsEveryone with access, except its readersOnly the people and teams it names
GranularityA folder or fileA folder, a file, or named regions of a file
Use it for"Nobody reads finance/ except these three people""This agent reads docs/ and one section of config/app.toml, and nothing else"

Both can apply to one person. A rule that hides a path wins over a grant that names it.

Who is limited

Admins are never limited. A repository admin reads everything, and so does an organization owner, who is an admin on every repository in the organization. A token acts as its owner, so an admin's token reads everything too.

To limit an agent, give it its own account without admin access and name that account in a rule or a grant. Do not run it on an admin's token, because the token has the admin's access. See Roles and permissions for how access levels work.

What else to know about who a rule or grant reaches:

  • People are named by handle. Handles are lowercased and are not checked against existing accounts when you save.
  • Teams are named by slug and only count in an organization's repositories. On a personal repository, name people.
  • Signed-out visitors meet rules. A path hidden by a rule is hidden from a signed-out visitor of a public repository too, because no rule can name them. Grants limit only the signed-in people and teams they name.

A directory rule

A rule has a path and the readers who may read it.

FieldMeaning
pathA glob relative to the repository root, such as secrets, finance/** or **/private. It covers the folder and everything under it.
peopleHandles of the people who may read it.
teamsSlugs of the organization teams whose members may read it.

Everyone else, admins aside, meets a repository in which the path does not exist. A rule that names nobody hides the path from everyone but admins.

Paths use the same glob syntax as branch rules and caisson path rules. * matches within one folder name, ** crosses folders, ? matches one character and [ab] a set. The pattern is matched against the whole path, so *.env matches only at the top level and **/*.env matches in every folder.

An access grant

A grant has a path, optional regions, and the people and teams it limits.

FieldMeaning
pathWhat it gives, as a glob: a folder and everything under it, or one file.
regionsThe regions of the file it gives. Empty gives the whole path.
peopleHandles of the people it limits to their grants.
teamsSlugs of the organization teams whose members it limits to their grants.

A grant names at least one person or team. Once a person is named in any grant, they read only what their grants give, plus the folders on the way to it. A grant on config/app.toml lets the person see config/ listed, with app.toml in it and nothing else.

If a person is named in two grants, they get both. A team member who is also named personally gets the grants of both.

Regions

A region is the lines between a line that holds sailfork:region NAME and the next line that holds sailfork:endregion. Write the markers in whatever comment syntax the file uses.

config/app.toml

# sailfork:region public
name = "shop"
port = 8080
# sailfork:endregion
# sailfork:region secrets
api_key = "..."
# sailfork:endregion

A grant for config/app.toml with the region public shows that person this file:

# sailfork:region public
name = "shop"
port = 8080
# sailfork:endregion
--- sailfork:hidden ---

Each run of hidden lines becomes one --- sailfork:hidden --- line, so the view does not reveal the hidden text or how long it is. Rules for regions:

  • A region name is 1 to 100 letters, digits, _, - or ..
  • Regions do not nest.
  • A file that is not UTF-8, or whose markers are out of place (an end with no start, a region left open), shows as a single hidden line.
  • A grant with regions on a file hides the file from every surface that does not redact. A surface that does redact shows the redacted view.

What a limited reader sees

SurfaceHidden pathRegion-limited file
File tree and file pagesNot listed, and a request for it by address does not return itListed, and opens as the redacted view
Commits, diffs and history of a pathHidden files drop out of diffs and file historyDiffs and history show the redacted view
Code search and symbol searchHits in hidden files are droppedHits come from the redacted view
REST APIThe same answers as the browser, from the same checksRedacted
MCP toolsThe tools call the API as the account, so they get the same answersRedacted
CaissonsSee belowRedacted

A rule or a grant is checked at every commit, not only on the default branch. A commit opened by id shows the same paths as the branch that holds it.

Caissons

A caisson reads and edits as its opener.

  • Reads, listings, globs, greps and diffs include only paths the person may read. A file they read in regions is redacted.
  • A write to a path in a hidden folder is refused with a 403 that says the path is in a directory they may not read. A write to a region-limited file may change only the granted regions.
  • The caisson's bash sees only the files the person may read.
  • A run's output and a search's samples can quote any path, so a limited reader does not see them in the caisson's session log.
  • The caisson's whole tree cannot go to a sandbox, a review packet or a language server for a limited reader. Those answer 403: this repository hides directories from you, so the whole tree of a caisson cannot be handed to a sandbox, script or language server for you. caisson test is a sandbox, so it is refused too.

See Caissons and Caisson isolation.

Pull requests, merges and CI

  • A limited reader's pull request views list only paths they may read.
  • A merge, or an undone merge, by a limited reader is refused when it changes a path they may not read. The error says this merge changes <path>, which you may not read: ask someone who reads the whole repository to merge it. A change that touches a region-limited file only inside the granted regions is allowed.
  • A limited reader cannot read the logs or artifacts of CI runs, because a run checks out the whole tree and its output can quote any file. The answer is 403 this repository has restricted directories, and run logs and artifacts can quote any of them.
  • A CI run reads what the person who started it may read. A run started by a limited person cannot check the code out. A scheduled run uses the repository owner.

Clone, fetch and push

Git cannot serve part of a tree, so a limited reader gets no clone, fetch or push over HTTPS or SSH. A limited person who tries gets a 403, or an SSH refusal, with this message:

this repository has restricted directories; read and change it through a caisson or the API

A signed-out visitor to a public repository with rules is asked to sign in first. LFS downloads and forks are refused for a limited reader too. Admins, and people no rule or grant limits, clone and push as usual.

A limited reader works through the browser, the API, MCP or a caisson. This is why an agent that must not see a folder gets its own account: it reads and edits through a caisson, and git itself is closed to it.

Where to set them

In the repository's settings, open the Access tab, which is the Directory access section at /{owner}/{repo}/settings#access. It has one list for rules and one for grants. Each entry has a path, and for grants a list of regions, and the people and teams it names. Each list saves on its own with its Save button, not with the rest of the settings page.

Only a repository admin can read or change them, and a token needs the repo:admin scope. A repository with neither rules nor grants costs nothing extra on any request.

Limits: at most 50 rules and 50 grants per repository. A rule names at most 200 readers (people and teams together). A grant names at most 200 people and teams and 50 regions. A path is 1 to 200 characters, has no . or .. parts, and must be a valid glob.

From the command line

sailfork repo access lists and changes both lists. Use -R owner/repo or run it in a clone.

sailfork repo access show -R acme/site
sailfork repo access show --json > access.json
sailfork repo access rules set -R acme/site --file rules.json
sailfork repo access grants add --path docs/** --person ada
sailfork repo access grants add -R acme/site --path config/app.toml --region public --team contractors
sailfork repo access grants remove -R acme/site --path docs/** --yes

rules set and grants set replace the whole list with the contents of a JSON file, either the array or an object with a rules or grants key. grants add adds people or teams to the grant for that path and regions, or creates it. grants remove removes every grant on a path. See the CLI repository commands for every flag.

API

Both routes replace the whole list on PUT, so send every rule or grant you want to keep. GET and PUT need repo:admin and admin access to the repository.

Method and pathPurpose
GET /api/repos/{owner}/{repo}/directory-permissionsList the rules, as { "rules": [...] }
PUT /api/repos/{owner}/{repo}/directory-permissionsReplace the rules
GET /api/repos/{owner}/{repo}/access-grantsList the grants, as { "grants": [...] }
PUT /api/repos/{owner}/{repo}/access-grantsReplace the grants

Hide finance/ from everyone except one person and one team:

curl -X PUT -H "Authorization: Bearer $SAILFORK_TOKEN" -H "Content-Type: application/json" \
  -d '{"rules":[{"path":"finance/**","people":["priya"],"teams":["finance"]}]}' \
  https://sailfork.com/api/repos/acme/shop/directory-permissions

Limit an agent's account to docs/ and the public region of one file:

curl -X PUT -H "Authorization: Bearer $SAILFORK_TOKEN" -H "Content-Type: application/json" \
  -d '{"grants":[{"path":"docs/**","people":["docs-agent"]},{"path":"config/app.toml","regions":["public"],"people":["docs-agent"]}]}' \
  https://sailfork.com/api/repos/acme/shop/access-grants

Both answer 200 with the saved list. A body that breaks a limit above, a path that is not a valid glob, or a grant that names nobody is refused and nothing changes.

Loading Sailfork