Skip to Content
harness-kit

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

harness.config.ts
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:

What the agent reads
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:

What the agent reads
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 runsAnswer
echo token > secrets/api.keydeny
rm .envdeny
cat secrets/api.keyallow
echo {} > .claude/settings.jsondeny

If it does not work

  • A write to a protected path goes through. Run npx harness-kit config check and npx 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.

On this page