# serialexp/agent-fs-policy

> Which paths a coding agent may read and write: .agent-deny plus Claude Code settings file permissions

- **Default branch:** `main`
- **Stars:** 0 · **Open issues:** 0 · **Open pull requests:** 0
- **License:** MIT License
- **Clone:** `https://gothab.io/serialexp/agent-fs-policy.git`

## README.md

# agent-fs-policy

Which paths a coding agent may read and write, decided the same way by every
harness that runs one: Gothab's `gt agent`, agent-ui's script tool, and
anything else that loads it.

## `.agent-deny`

The repository's own policy, at the root of the working directory. One rule
per line:

```
# mode | repository-relative glob | reason shown to the agent
write | .agent-deny       | Repository access policy is owner-controlled.
write | migrations/**     | Promoted migrations are immutable.
read  | **/.env*          | secrets
read  | !.env.example     | a template, no secrets
all   | generated/**      | generated externally
```

- `mode` is `read`, `write` or `all`.
- The glob is gitignore-style and relative to the repository; `dir/**` covers
  `dir` itself too. A leading `!` takes paths back out of the rules above.
- The reason is what a refused agent is told.
- A line that doesn't parse denies every path, so a typo can't quietly weaken
  the policy.

## Claude Code settings

`FsPolicy::load` also reads the `Read(…)`, `Edit(…)` and `Write(…)` rules and
`additionalDirectories` of `~/.claude/settings.json` (or the one under
`CLAUDE_CONFIG_DIR`), `.claude/settings.json` and `.claude/settings.local.json`.
`FsPolicy::empty` reads `.agent-deny` alone.

## Use

```rust
use agent_fs_policy::{Access, FsPolicy};

let policy = FsPolicy::load(&cwd);
policy.check(Access::Read, &cwd.join(".env"))?;            // a typed file operation
policy.authorize_argv(&cwd, &["cat", ".env"], false)?;      // a program, before it starts
policy.authorize_shell_command(&cwd, "cat .env", false)?;   // a shell command line
let show = policy.permits_scan(&path);                      // a search or listing
```

Every check follows symlinks, so a link can't launder a denied target. A
repository-relative rule says nothing about paths outside the repository; an
explicitly rooted Claude rule (`Read(~/.ssh/**)`, `Read(//etc/shadow)`) does.

Checking a command by the paths it names is a guard at the call boundary, not
a sandbox: a program that opens a denied file without naming it is not caught.

## License

MIT
