𝄐 fermata

Do not use this software.

Caution

This is an experiment. It does not protect your secrets. Secrets can and do reach the model while it is installed. Do not rely on it. Do not install it on a real project.


Where it is known to fail: docs/known-failures.md.


What it tries to do

AI coding agents read files and run commands. When an agent reads .env, the values enter the model's context, and from there they can end up in commits or API calls. The experiment asks whether the output of a tool could be filtered before the model sees it, so that the agent could see which keys exist without seeing their values.

fermata is a program that runs in hooks around an agent's tool calls.

Where the two hooks sit around a tool call, and what each one tries to do

Before the tool runs (PreToolUse). fermata compares the call, and the files a command names, with the rules in .botsecrets [policy] and .botignore, and stops it when a rule matches. It also stops a Read of a listed secret file it cannot mask, and a Write or Edit that adds a mask to a file. When no rule matches it answers nothing, so Claude Code's own permission prompts stay. It has no rules unless you write them.

After the tool runs (PostToolUse). fermata finds the secret files named in .botsecrets, parses them, keeps the values under keys that look secret, and replaces those values in every string of the output with *****, using an Aho-Corasick automaton. A second scan with regular expressions looks for known formats such as AWS keys and JWTs. It only adds a warning and masks nothing. Each call parses the secret files again: in a release build that took 5 to 9 ms for a small .env and 0.13 s for a 2.3 MB JSON file of 35000 keys.

So in the cases it handles, source .env && echo $DB_PASSWORD comes back masked although no read was stopped. docs/known-failures.md shows how many cases it does not handle.

fermata is no sandbox. See docs/threat-model.md.


How it is configured

.botsecrets is a TOML file. It names the secret files ([files]), extra key names ([keys]), the mask style ([redaction]), the heuristic scan ([heuristic]) and the rules for the gate ([policy.write], [policy.bash], [policy.read]). fermata.toml is accepted as another name for it, and .botsecrets wins when both exist.

.botignore uses gitignore syntax and stops the Read, Write and Edit tools on paths that match. It is optional.

The reference is docs/configuration.md, and the CLI is in docs/commands.md.


Trying the experiment

Use a throwaway project and fake secrets. Nothing here makes a real project safer.

Install, with a working Rust toolchain:

cargo install --git https://git.g4b.org/dirigence/fermata --features cli

Create a .botsecrets in the throwaway project:

# .botsecrets
[files]
patterns = [".env", ".env.*", "secrets.*"]

[policy.write]
patterns = [".claude/**", "vendor/**", "*.lock"]

[policy.bash]
deny = ["rm -rf /", "curl * | sh"]

Setting patterns replaces the default list of files. Built-in key patterns such as *_KEY, *SECRET*, *PASSWORD*, *TOKEN* and DATABASE_URL decide which values count.

Add both hooks to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "hooks": [
          { "type": "command", "command": "fermata hook --harness claude", "onFailure": "block" }
        ]
      }
    ],
    "PostToolUse": [
      {
        "hooks": [
          { "type": "command", "command": "fermata hook --harness claude --event post-tool-use" }
        ]
      }
    ]
  }
}

Leave out matcher: a matcher that omits a tool leaves that tool's output unfiltered.

"onFailure": "block" (Claude Code v2.1.295 or later) stops a tool call when the hook cannot run. Without it, Claude Code carries out the call and the output passes unfiltered. On PostToolUse it can hold nothing back, because the tool has already run.


Harness support

Harness Status Mechanism
Claude Code Exists, and fails often PreToolUse and PostToolUse hooks
Any tool that can call a program Exists Exit codes of fermata check
Codex CLI Not built Hook adapter
Gemini CLI Not built MCP server mode
Any MCP agent Not built MCP proxy

Background

fermata is developed in the Dirigent monorepo and exported here. It needs no other Dirigent component.


License

Licensed under either of

at your option.

S
Description
Policy Gate Tool and library
Readme
717 KiB
Languages
Rust 100%