Protect secrets and the harness itself
Refuse every write the agent makes to secrets/ and .env files, and keep it from editing the hooks that guard it.
You'll: refuse writes to secrets/ and .env files, by an editing tool or the shell. The harness's own files are protected already, without an entry.
Reading stays free
These Policies guard writes only. To keep a secret from the agent's eyes, keep it out of the repository, or deny reads with Claude Code's own permission rules.
You also need the kit installed and your hooks synced; see Quick start.
Add the configuration
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* The secrets of the repository kept from the agent's writes, by an editing tool or the shell; the harness's own files
* are protected without an entry, by `self-protection`.
*/
export default defineConfig({
policies: [
{
id: 'secrets',
options: {
hint: 'Secrets are rotated by a person: ask for the change instead.',
paths: ['secrets/**', '**/.env', '**/.env.*'],
},
use: 'protected-paths',
},
],
});hint is the fix the agent reads, so say what a person should do instead. Then run npx harness-kit settings sync.
Try it
Ask the agent to "store the new API key". It runs echo token > secrets/api.key:
a > redirection would write /work/repository/secrets/api.key, which this configuration protects from shell writes (secrets/**, **/.env, **/.env.*).
Fix: Secrets are rotated by a person: ask for the change instead.Editing the hook settings is refused by self-protection, which every configuration runs:
a > redirection would write /work/repository/.claude/settings.json, Claude Code's settings, which register the hooks, which harness-kit protects from the agent.What it catches
| The agent runs | Answer |
|---|---|
echo token > secrets/api.key | deny |
rm .env | deny |
cat secrets/api.key | allow |
echo {} > .claude/settings.json | deny |
If it does not work
- A write to a protected path goes through. Run
npx harness-kit config checkandnpx harness-kit settings sync, then try again. - Claude Code asks about a command. The path Policies could not resolve a write to a literal path, so the call falls to Claude Code's permission prompt (see the last accordion). Claude Code asks about a harmless command explains the common causes.
- You need to change a protected file. Make the change yourself, outside the agent.
Related
- Paths and new files: lockfiles, generated folders and allow-lists.
- Protection: the Policies that keep the guardrails on.