grep -A 2 .env a.txt, rg -t py .env, tar --exclude=.env and git --no-pager status .env pass under a rule on .env. A small list of grep's and rg's flags with a value, four exclude flags and git's quiet flags; grep -A 2 TOKEN .env and --include=.env stay stopped.
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.
Known to fail
These failures were reproduced with fake values, through the fermata binary, and each is a test that asserts the failure happens, except where it says it comes from Claude Code's documentation. The list is not complete.
cat .env; falseis unprotected. According to Claude Code's documentation and bundled code, a failed tool's output goes down a path no hook can rewrite. With.envin.botignoreor[policy.read], a command that names the file (cat .env; false,cat ./.env; false) is stopped, andenv; falseand a failingnpm testthat prints its environment are not. On the default configuration a parseable.envis not stopped at all.- Commands are checked only for the files they name, in the forms the check reads. These pass, with
.envunder a rule:- a substitution that builds the name (
cat $(printf '.e%s' nv)), andecho "$(cat .env)", since a substitution inside double quotes is one word - a script that opens the file, a printing verb that is not on the list (
python -c,dd,perl), and a heredoc fed to a shell (bash <<EOFwithcat .envin its body) find . -name .env -exec cat {} \;,curl -d @.env,curl -F file=@.env,git show HEAD:.env,git show :.envandcat .{env,x}- a shell other than
bash,shandzsh(dash -c 'cat .env',ksh -c),bash -c -- 'cat .env',evalpast its first argument (eval 'true' 'cat .env'), and a shell behind a wrapper's flag value (sudo -u root bash -c 'cat .env') cd ../other && cat .env, and a file a command is about to make (cp a.txt vendor/newundervendor/)
- a substitution that builds the name (
- Some harmless commands are stopped under a rule. With
.envunder a rule,grep -A 2 .env a.txt,rg -t py .env,grep -r TOKEN --exclude=.env .,tar --exclude=.env -cf x.tar .andgit --no-pager status .envare denied. - A secret file fermata cannot mask is stopped only when a call names it. That means a Read, a Grep with that
path, or a printing command naming*.p12,*.pfx,.netrc,.htpasswdor a text*.key.grep -r TOKEN .,tar cf x.tar .and a script that opens the file pass. So dosudo -u root cat id_rsa,eval cat id_rsa,cat <&3 id_rsa,cat */id_rsaand a Grep withpath = "~/.ssh/id_rsa".- The stop needs the PreToolUse hook: without it a Read reaches the model.
- A text with
{{or{%that does not parse passes as a template, and a literal value in it reaches the model. - A
.pemis judged by its armor labels: with only certificate labels it passes, whatever other text it holds.
- Many values never enter the list of known secrets.
- a key the key filter does not match, in a parsed file; a
.tfvarsheredoc; a*.tfvarsother thanterraform.tfvarsand*.auto.tfvars; a comment in a TOML or YAML file - the first value of a duplicate JSON key
- a
.envvalue inside a quoted value that spans several lines, when a program prints it alone - Python triple quotes, and shell-quoted spellings such as
'a'\''b-xandabc"def"-x, when a program prints the decoded value - a number under 6 characters, and a secret number that a tool returns as a JSON number
- a UTF-16 or Latin-1 file, or JSON with comments, when no command names it
- a secret file outside the working project
- a key the key filter does not match, in a parsed file; a
- A short password's word is masked everywhere, in other files too. An Edit copied from such masked text fails, since Claude Code's Edit needs the real text (from its documentation). A short line of a multi-line value passes when printed alone.
- Other routes that stay open: Monitor's output, a changed file's attachment and a hook that times out (all from Claude Code's documentation), values split across strings, encoded values, binary fields, and any secret the heuristic scanner finds, since it only warns.
- The write guard is narrow. It stops a Write or Edit that adds a mask. A shell command that writes a mask, the
absentstyle, and a real run of exactly five asterisks are not handled.
The fuller list: docs/security-model.md. tests/known_limits.rs shows each limit through the binary, except what comes from Claude Code's own documentation. The test suite never runs Claude Code.
What it tries to do
AI coding agents read files and run commands, and what they read enters the model's context. The experiment asks whether a tool's output could be filtered before the model sees it, so that an agent could see which keys .env holds without seeing their values.
fermata runs in hooks around an agent's tool calls:
Agent wants to run a tool
|
PreToolUse ── .botsecrets [policy] / .botignore, read gate, write guard
| a rule matches? → deny or ask
| otherwise → no answer: Claude Code's permissions decide
|
Tool executes
|
PostToolUse ── .botsecrets [files] + [keys] + [heuristic]
| values it parsed? → masked
| known formats? → a warning, the value stays
|
Output enters LLM context, with whatever was missed
| Part | Mechanism | What it does |
|---|---|---|
| Known-value masking | .botsecrets names secret files; fermata parses those it has a parser for and builds an Aho-Corasick automaton |
Masks a value from the manifest in a string of a successful tool's output |
| Heuristic scan | Regex patterns from gitleaks (AWS keys, JWTs, GitHub PATs, database URLs) | Warns beside the output and masks nothing |
| Rules | .botsecrets [policy] / .botignore |
Stops the Read, Write and Edit tools on matching paths, commands whose text matches, and commands that name a matching file. No rules, nothing stopped |
| Read gate and write guard | built in; [enforcement] |
Stops a Read of a listed secret file it cannot mask, and a Write or Edit that adds a mask to a file |
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. A hook that times out lets the original output through.
fermata is no sandbox: see docs/threat-model.md.
Trying the experiment
Use a throwaway project and fake secrets.
cargo install --path . --features cli
# .botsecrets
[files]
patterns = [".env", ".env.*", "secrets.*"]
[keys]
include = ["STRIPE_*", "MY_APP_SIGNING_*"]
[policy.write]
patterns = [".claude/**", "vendor/**", "*.lock"]
[policy.bash]
deny = ["rm -rf /", "curl * | sh"]
fermata.toml is accepted as another name for .botsecrets, which wins when both exist. An optional .botignore uses gitignore syntax for the Read, Write and Edit tools. See docs/configuration.md.
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" }
]
}
]
}
}
PreToolUse is no permission approver: when no rule stops a call it answers nothing, and Claude Code's own prompts stay.
Leave out matcher: a matcher that omits a tool leaves that tool's output unfiltered.
"onFailure": "block" (Claude Code v2.1.295 or later; older versions ignore it) 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. With it, a teammate without fermata on PATH is blocked at every tool by a committed .claude/settings.json, so per-user installs belong in .claude/settings.local.json. To recover, edit the settings by hand or set "continue".
Commands
# Check a path against the rules
fermata check --op read /path/to/.env # exit 1 = a rule denies it
fermata check --op write /path/to/src/main.rs # exit 0 = no rule denies it
# Run as a hook (reads harness JSON from stdin)
fermata hook --harness claude
fermata hook --harness claude --event post-tool-use
See docs/commands.md.
Library API
use std::path::Path;
use dirigent_fermata::core::secrets::{Manifest, Redactor, Scanner, SecretsConfig};
let root = Path::new("/path/to/project");
let config = SecretsConfig::load(root)?;
let manifest = Manifest::build(&config, root)?;
let redactor = Redactor::new(&manifest, config.redaction.style);
let clean = redactor.redact("DB_PASSWORD=fake-db-pass-1");
// clean.text holds the masked text, if that value made it into the manifest
let scanner = Scanner::new(&config.heuristic)?;
let findings = scanner.scan("Found key: AKIA1234567890ABCDEF");
Harness support
| Harness | Status | Mechanism |
|---|---|---|
| Claude Code | Exists, fails as listed above | PreToolUse and PostToolUse hooks |
| Codex CLI | Not built | Pre-exec hook adapter |
| Gemini CLI | Not built | MCP server mode |
| Any MCP agent | Not built | MCP proxy |
Background
- docs/security-model.md: the idea of "reveal", as distinct from read and write, the design, and the known limits
- docs/threat-model.md: what fermata tries to catch and where it stops
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.