Protection
self-protection and hook-bypass keep the agent from switching its own guardrails off. Both run in every configuration.
Keep the agent from removing its own guardrails: editing the hook settings, rewriting the configuration or committing with --no-verify. Both Policies run without an entry, so you get this protection with no setup.
self-protectionrefuses writes to the harness's own files. denyhook-bypassrefuses git commands that skip the repository's git hooks. deny
API reference
self-protection, hook-bypass.Change the defaults
You need an entry only to change a default. This one lets the agent write Claude Code's settings:
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* The two Policies every configuration runs, written out to change them: the agent may edit the project's Claude Code
* settings (a person keeps the hooks in `harness.config.ts` instead), and the hook bypass also refuses `SKIP_HOOKS=1`.
* Without these entries both run with every area protected.
*/
export default defineConfig({
policies: [
{
id: 'self-protection',
options: {
settings: false,
},
use: 'self-protection',
},
{
id: 'hook-bypass',
options: {
disableEnvs: [
{
name: 'HUSKY',
onlyIfExists: '.husky',
value: '0',
},
{
name: 'SKIP_HOOKS',
value: '1',
},
],
},
use: 'hook-bypass',
},
],
});An entry of your own replaces the default one. In a configuration that extends another, turning off a switch the central one has on fails the configuration; a person uses an override instead.
self-protection
Refuses writes, by an editing tool or a shell command, to four areas of the harness's own files. Reading stays free.
It reads a shell command the way the shell would: redirections, tee, cp, mv, rm, sed -i, chmod, and what sh -c, eval or a heredoc run. Wrapping a write does not get around it.
a > redirection would write /work/repository/.claude/settings.json, Claude Code's settings, which register the hooks, which harness-kit protects from the agent.
Fix: Leave /work/repository/.claude/settings.json as it is and hand the change to the person running the session; reading it is unaffected. Only they may let the agent write Claude Code's settings, which register the hooks: with `settings: false` in the options of the `self-protection` entry of the harness configuration, or through an override that entry declares.API reference
self-protection, with its type and default.Turn an area off by writing the entry with that switch false, as the example does for settings.
hook-bypass
Refuses a git command that runs hooks (commit, push, merge, rebase, am) around those hooks, such as --no-verify.
Blocked: git commit --no-verify skips the hooks, which the repository's git hooks exist to run.
Fix: Commit with the hooks on: git commit -m "<message>", and fix what the hooks report.API reference
hook-bypass, with its type and default.Turn a check off by writing the entry with noVerify: false or hooksPath: false, or with the disableEnvs you want refused. A disableEnvs item is { name, value, onlyIfExists? }: the variable is refused only where onlyIfExists, a path in the working copy, exists.
How the path Policies read a shell command
self-protection and protected-paths are built for an agent that might try to get around them. They let a Bash call through only when they can prove it harmless:
| Answer | When |
|---|---|
| allow | every write resolves to a literal path outside the guarded files, and no data runs as code |
| deny | a write resolves into a guarded file, from any folder it may land in, or removes a folder that holds one |
| ask | the Policies cannot resolve a write or tell what runs: Claude Code's permission prompt, so the person decides |
When a call is asked about, the person reads:
harness-kit cannot tell what this command writes or runs: `> $d/a` (`$d` has no value the line gives). It lets a Bash call through on its own only when every write resolves to a literal path outside a file of the harness configuration, Claude Code's settings, which register the hooks, a plugin's hook registration, the harness's session state and the command runs no data as code, so it asks you: allow it only if none of this touches a file of the harness configuration, Claude Code's settings, which register the hooks, a plugin's hook registration, the harness's session state.Allow the call only if nothing it writes is one of those files. To see how a line is judged before it runs, use harness-kit explain (debugging).
Related
- Paths and new files: protect your own files the same way.
- Troubleshooting: the common messages and how to clear them.