harnessctl
All setups
harnessctl guards a Claude Code installation on your workstation. It covers three areas:
- Edits to the harness (the files that steer the agent: rules, skills, hooks, settings and instructions) after you allow them in a confirmation window.
- Two
PreToolUsehooks that Claude Code runs before each tool call:sandboxkeeps the agent inside the project folder,nexuskeeps it onnexusctl,nexushelmandnexusadmfor the cluster of the homelab setup and protects the harness. - A registry of exceptions: folders outside the project that you open to the agent for 30 days at most.
It applies to every setup, the workstation one included. Messages and confirmation windows are written in French.
Install
From the root of a clone of the repository:
make install
The target builds and tests the commands, links nexusctl, nexusadm, nexushelm and harnessctl into ~/.local/bin (PREFIX chooses another prefix), then runs harnessctl hook install sandbox and harnessctl hook install nexus. Each registration opens a confirmation window. The links point to the clone, so a git pull updates the commands.
make uninstall removes the links and the nexus hook. It keeps harnessctl and the sandbox hook: a registered hook whose command is missing blocks every tool call. To remove them, run harnessctl hook install sandbox --remove, then delete the harnessctl link.
The confirmation windows use zenity on your graphical session.
Synopsis
harnessctl edit <path> --old <text> --new <text> [--replace-all] [--reason <text>]
harnessctl hook sandbox
harnessctl hook nexus
harnessctl hook install sandbox|nexus [--remove]
harnessctl allow <folder> --reason <text> [--days 1..30] [--project <name>]
harnessctl revoke <folder>
harnessctl list [--json]
harnessctl import
Without arguments, or with an unknown subcommand, harnessctl prints this usage on standard error and exits with code 2.
Confirmation window
edit, allow, import and hook install show what they are about to do in a window with two buttons, Autoriser (allow) and Refuser (deny). Only a click on Autoriser lets the command write. Clicking Refuser or closing the window exits with code 3. When zenity is missing, no display is reachable, or two minutes pass without an answer, the command exits with code 4; no decision is recorded as an approval. Every request and its decision go to the journal of the clone (see the last section). When the journal cannot be written, the command exits with code 1 before doing anything.
edit
harnessctl edit <path> --old <text> --new <text> [--replace-all] [--reason <text>]
Replaces text in a harness file, the same way as the Edit tool of Claude Code, after confirmation.
| Option | Description |
|---|---|
--old <text> | Text to replace. It must appear exactly once, unless --replace-all is given. An empty value on a missing file creates the file with the --new text. |
--new <text> | Replacement text. It must differ from --old. |
--replace-all | Replaces every occurrence. |
--reason <text> | Reason shown in the window. |
A value that starts with @ is read from a file of the project: --new @draft.md reads draft.md. A file outside the project exits with code 1. Start the value with @@ to pass a text that begins with a single @.
The window shows the file, the working folder, the reason, the number of occurrences, the removed lines (prefixed with -) and the added lines (prefixed with +). After you allow it, harnessctl reads the file again: if the file changed in the meantime, nothing is written and the command exits with code 1. The write goes through a temporary file and a rename, and keeps the file mode.
The harness files are:
| Path | Content |
|---|---|
~/.claude/rules/, ~/.claude/skills/, ~/.claude/hooks/, ~/.claude/commands/ | Folders, with all they contain. |
~/.claude/CLAUDE.md, ~/.claude/settings.json, ~/.claude/settings.local.json | Account-wide instructions and settings. |
CLAUDE.md, openspec/config.yaml | Files at the root of the project. |
.claude/, .agents/, .vibe/ | Folders at the root of the project, with all they contain. |
Symbolic links are followed before the check. Any other path exits with code 1: edit it directly. The project is the clone that harnessctl runs from.
harnessctl edit CLAUDE.md --old "Node 20" --new "Node 22" --reason "Runtime upgrade"
hook sandbox
harnessctl hook sandbox
Guard for Claude Code that keeps tool calls inside the project folder. Claude Code runs it before Bash, Read, Write, Edit, MultiEdit, NotebookEdit, Glob, Grep, EnterWorktree, Agent and Task. The command reads the tool call as JSON on standard input.
A path is allowed when it falls in one of these places:
- the project:
CLAUDE_PROJECT_DIR, and the main repository of the working folder, worktrees included; ~/.claude/;/tmp/claude-*;- a folder of the exceptions registry whose grant has not expired;
- anywhere outside your home folder and outside
/mnt,/media,/srv,/opt,/dataand/root. System paths such as/usr,/etcor/tmpare not guarded.
For file tools, the guard checks the file_path, path, notebook_path and directory fields. For Bash, it reads the text of the command: absolute paths, paths starting with ~ or $HOME, and the targets of cd and pushd, relative ones included. A guarded path quoted in a string or a comment is blocked too.
The guard also blocks the creation of a worktree under .claude/worktrees/: EnterWorktree with a name or without a path, a sub-agent with isolation: "worktree", and a git worktree add command that targets .claude/worktrees. Worktrees go under <project>/.worktrees/<name>.
Each block, and each use of an exception, adds a line to the audit log, sandbox-audit.log next to the exceptions registry ($XDG_CONFIG_HOME/harnessctl/, mode 600); the former ~/.claude/sandbox-audit.log is no longer written and stays as the archive: date, kind (DENIED, DENIED-WORKTREE or exception-used), working folder, tool, path and details.
hook nexus
harnessctl hook nexus
Guard for Claude Code that keeps cluster commands on nexusctl, nexushelm and nexusadm, which log every call, mask Secret values and ask for confirmation. Claude Code runs it before Bash, Read, Write, Edit, MultiEdit, NotebookEdit, Glob and Grep. It blocks:
- the programs
kubectl,helm,secret-tooland the internal binary ofnexusctl, in command position, also behindsudo,env,xargs,bash -c,eval,ssh,$(...)and backquotes; microk8s kubectl,microk8s helm,microk8s config,microk8s ctr, andkubectl,helmormicrok8sstarted bysnap run;- any text that names the
.kubefolder, the administration kubeconfig (including the path inNEXUS_ADMIN_KUBECONFIG), the access configuration folder of nexus (including the folder resolved fromNEXUS_CONFIG_DIRorXDG_CONFIG_HOME), the token socket or port 16443 of the Kubernetes API, in a command or in the path of a file tool; - writes to a harness file:
Write,Edit,MultiEditandNotebookEdit, andBashcommands that write there (redirection,tee,mv,cp,rm,sed -iand similar). The message points toharnessctl edit.
The project root is CLAUDE_PROJECT_DIR, or the working folder of the call. Each block adds a line to infra/.nexusctl/guard.log of the project when that folder exists.
The guard reads the text of commands. A path built at run time, a script written then started, or another scripting language gets past it. The content of a file written by Write or Edit is not read.
Hook output and exit status
Both guards exit with code 0. When the call is allowed, they print nothing. When it is blocked, they print the PreToolUse decision of Claude Code on standard output, with the reason:
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"..."}}
Input that is not valid JSON produces no decision. hook with a missing or unknown guard name exits with code 2.
hook install
harnessctl hook install sandbox|nexus [--remove]
Registers a guard in the settings of Claude Code, or removes it with --remove, after confirmation.
| Guard | Settings file | Tools matched |
|---|---|---|
sandbox | ~/.claude/settings.json (whole account) | Bash|Read|Write|Edit|MultiEdit|NotebookEdit|Glob|Grep|EnterWorktree|Agent|Task |
nexus | .claude/settings.json of the clone | Bash|Read|Write|Edit|MultiEdit|NotebookEdit|Glob|Grep |
The registered hook runs harnessctl hook <guard> || exit 2 with a 10-second timeout: when the guard is missing or crashes, Claude Code blocks the call. Registration replaces earlier registrations of the same guard, including the former Python guards, and keeps the order of the other keys. When the guard is already registered as expected, or absent for --remove, the command prints inchangé and exits with code 0 without opening a window. Before the first change, the original file is saved next to it with the suffix .avant-harnessctl. A settings file that is not a JSON object exits with code 1 and nothing is written.
harnessctl hook install sandbox
allow
harnessctl allow <folder> --reason <text> [--days 1..30] [--project <name>]
Opens a folder outside the project to the agent, after confirmation.
| Option | Description |
|---|---|
--reason <text> | Required. Reason shown in the window and stored in the registry. |
--days N | Validity, from 1 to 30 days. Default: 30. The grant ends on today’s date plus N days. |
--project <name> | Project name stored in the registry. Default: the name of the folder of the clone. |
The folder must exist. The command exits with code 1 for your home folder or one of its parents, for a folder of secrets or a folder that contains one (.kube, .ssh, .gnupg, .config/nexus, .config/harnessctl, .local/share/keyrings, .claude in your home), and for a folder already inside the project. When an exception already covers the folder, the window says so and the grant renews it. After you allow it, the command adds a grant to the registry and prints the expiry date.
harnessctl allow ../shared-fixtures --reason "Read the shared test fixtures" --days 7
revoke
harnessctl revoke <folder>
Closes an open folder: it adds a revocation to the registry. It removes a right, so it opens no window. A folder with no exception in force exits with code 1.
list
harnessctl list [--json]
Prints the exceptions in force, sorted by folder: one line per folder with the folder, the expiry date, the project and the reason, separated by tabs. Without any exception, the output is Aucune exception en vigueur. With --json, each exception is a JSON object on its own line, and no exception prints nothing.
import
harnessctl import
Copies the former registry into an empty registry, after confirmation. It reads two legacy files of ~/.claude/: sandbox-exceptions.md, whose lines become archive entries that grant nothing, and sandbox-allow.txt, whose lines YYYY-MM-DD /path that have not expired become grants. The command exits with code 1 when neither file exists or when the registry already holds events.
Exceptions registry
The registry is harnessctl/exceptions.jsonl in your user configuration directory ($XDG_CONFIG_HOME, by default ~/.config). It holds one JSON object per event: octroi (grant), revocation or archive, with the date, the project, the folder, the reason, who granted it and the expiry date (YYYY-MM-DD). The state of a folder is its last event. A grant applies until the end of its expiry date; after that, it opens nothing until you grant it again. The file is created in mode 600 in a folder in mode 700. The sandbox guard reads it on each call; a registry that cannot be read opens nothing.
The registry is under ~/.config, which the sandbox guard keeps out of reach of the agent: only harnessctl, after your confirmation, writes there.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success, or nothing to change. The hook sandbox and hook nexus guards always exit with 0. |
| 1 | Failure: path outside the harness, text not found or ambiguous, file changed during the confirmation, folder that cannot be opened, registry or journal that cannot be read or written. |
| 2 | Wrong usage. |
| 3 | You clicked Refuser or closed the window. |
| 4 | The window could not open or got no answer within two minutes. |
Files and environment variables
| Name | Role |
|---|---|
$XDG_CONFIG_HOME/harnessctl/exceptions.jsonl | Exceptions registry. By default under ~/.config. |
HARNESSCTL_REGISTRE | Path of the registry, instead of the default one. |
$XDG_CONFIG_HOME/harnessctl/sandbox-audit.log | Audit log of the sandbox guard, in the registry folder. By default under ~/.config. |
infra/.nexusctl/journal.jsonl of the clone | Journal of the commands: start, decision and end of each request. |
NEXUSCTL_JOURNAL | Path of the journal, instead of the default one. |
infra/.nexusctl/guard.log of the project | Blocks of the nexus guard, when the folder exists. |
CLAUDE_PROJECT_DIR | Project root for the guards, set by Claude Code. |
~/.claude/settings.json, .claude/settings.json | Settings where hook install registers the guards. |