Paths and new files
protected-paths, generated-paths, allowed-paths and new-file keep files where they belong and out of the agent's reach.
Keep the agent away from files it should leave alone, inside the folders code belongs in, and honest about file names. These four Policies judge the files a tool call would write, by an editing tool or the shell:
| Policy | Refuses |
|---|---|
protected-paths | a shell write to a path you list, such as a lockfile |
generated-paths | any write into a folder generated from another source |
allowed-paths | a change outside the folders you allow |
new-file | a new file, such as a migration, named with a made-up timestamp |
API reference
The defaults and every option, with its type: protected-paths, generated-paths, allowed-paths,
new-file.
Configure the four Policies
Each Policy has an entry of its own; none is on by default.
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* The four path Policies: lockfiles changed only by the package manager, a generated docs mirror edited at its source,
* changes kept to the folders a repository's code lives in, and migrations named with a current timestamp.
*/
export default defineConfig({
policies: [
{
id: 'lockfiles',
options: {
hint: 'Change package.json and run npm install, which rewrites the lockfile.',
paths: ['**/package-lock.json'],
},
use: 'protected-paths',
},
{
id: 'generated-docs',
options: {
mirrors: [
{
hint: 'Edit {source} and run npm run docs:sync.',
path: 'docs/generated',
stamp: '.generated',
},
],
},
use: 'generated-paths',
},
{
id: 'allowed-paths',
options: {
allowOnly: ['src/**', 'tests/**', 'docs/**', 'db/**', '*.md', '*.txt', 'package.json', 'package-lock.json'],
hint: 'Code goes below src/ and tests/, prose below docs/.',
},
use: 'allowed-paths',
},
{
id: 'migrations',
options: {
glob: 'db/migrate/*.rb',
hint: 'Generate it with bin/rails generate migration <name>.',
nameRegex: '^(\\d{14})_',
},
use: 'new-file',
},
],
});Globs are relative to the folder the Policy works in (the repository root, or a stack's folder). They match dot folders such as .github, and may not start with / or contain . or ...
protected-paths
Refuses a shell command that would write a path your globs match, or remove a folder that holds one. Edits by the editing tools are left to Claude Code's own permission prompt. Options: { paths, hint? }.
rm would write /work/repository/package-lock.json, which this configuration protects from shell writes (**/package-lock.json).
Fix: Change package.json and run npm install, which rewrites the lockfile.A write it cannot resolve is asked about, following the path Policies' rules.
Turn it off by removing the entry.
generated-paths
Refuses every write, by an editing tool or the shell, into a folder generated from another source. Options: { mirrors: [{ path, stamp?, sourceField?, hint? }] }.
the Edit tool would write /work/repository/docs/generated/users.md, inside the generated mirror docs/generated/, which is generated from its source and never edited by hand.
Fix: Edit content/users.md and run npm run docs:sync.- With a
stamp, the folder counts as generated only while that file is in it, so another repository's folder of the same name is left alone. {source}in thehintis replaced by thesource:line of the edited file's front matter.
Turn it off by removing the entry.
allowed-paths
Refuses a change inside the Policy's folder that no glob of allowOnly matches. Options: { allowOnly, outsideRoot?, resolveSymlinks?, hint? }.
touch would write lib/x.rb, outside the paths this configuration allows in /work/repository (src/**, tests/**, docs/**, db/**, *.md, *.txt, package.json, package-lock.json).
Fix: Code goes below src/ and tests/, prose below docs/.- A path is judged where the file system puts it, following symbolic links and
.., unlessresolveSymlinksisfalse. - A change outside the folder passes unless
outsideRootisdeny. - An empty
allowOnlyis refused, so a missing list never lets everything through.
Turn it off by removing the entry.
new-file
Refuses a new file whose name carries a timestamp that is no real UTC time, or lies more than timestampWithinMinutes (15) from now. It is built for migrations an agent might name by hand. Options: { glob, nameRegex, timestampWithinMinutes?, exemptTrackedByGit?, hint? }.
The new file db/migrate/20200101000000_add_users.rb carries the timestamp 20200101000000, which is not within 15 minutes of the current UTC time, 20261201100914.
Fix: Generate it with bin/rails generate migration <name>.- The timestamp is the first capture group of
nameRegex, writtenYYYYMMDDHHMMSS. - Rewriting an existing file passes, and so does a name git already knows (a move or a restore) unless
exemptTrackedByGitisfalse. - When git cannot answer, the file is let through and the problem logged.
Turn it off by removing the entry.
If a central configuration sets them
A repository that extends a central configuration may add protected paths and mirrors, and narrow allowOnly, but not drop or widen what the central one set. A person who needs a different rule for one session uses an override.
Related
- Protection: the harness's own files, protected by default.
- Troubleshooting: the common messages and how to clear them.