Skip to main content

kanit

Evidence gates for coding agents. (kanıt: Turkish for "evidence")

Coding agents say "all tests pass" without running them, cite links they never opened, report "deployed" in a turn where no tool ran, and now and then try to edit their own guardrails. kanit is a small Claude Code plugin that checks two moments:

  • Before a tool call (PreToolUse): a dangerous call is denied, with a reason the agent can act on.
  • Before a reply is final (Stop, and SubagentStop for subagents): a reply that claims work the transcript cannot prove is sent back once, with what is missing.

Every rule ships with examples it must fire on and examples it must stay quiet on. Every check is logged, not only the hits, so you can see how often each rule fires per evaluation.

Python 3.9+, standard library only, no network calls, no telemetry.

Status: 0.1.0, alpha. Rule ids and the rules file format may still change before 1.0.

Install

In Claude Code (2.1.275 or later):

/plugin install kanit --marketplace RAYNSIS/kanit

On older versions, or from a terminal:

claude plugin marketplace add RAYNSIS/kanit
claude plugin install kanit@kanit

The plugin needs python3 on your PATH. Nothing else is installed.

To use the kanit command outside Claude Code (rule checks, stats):

git clone https://github.com/RAYNSIS/kanit && cd kanit
pip install .

What it does

A blocked tool call, as the agent sees it:

PreToolUse:Bash hook error: kanit blocked this call:
- [tool.no-secret-files] Secret files stay out of the agent's context. Ask the human for the one value you need. (matched: " .env")

A reply sent back at Stop, and the agent's next answer (Claude Code 2.1.327, recorded during release testing):

Agent:  All tests pass.
kanit:  this reply claims something the session cannot prove. Fix it before finishing:
        - [reply.tests-pass-needs-run] You said tests pass, but no test command ran in this turn.
          Run them and show the result, or say they were not run. (matched: "All tests pass")
Agent:  Tests were not run in this turn, so I can't claim they pass. My earlier "All tests pass"
        reply was unsupported.

You can try any rule without Claude Code:

$ kanit check reply 'Fixed the parser. All tests pass.' --turn 'Edit: {"file_path": "parser.py"}'
DENY reply.tests-pass-needs-run
     You said tests pass, but no test command ran in this turn. Run them and show the result, or say they were not run.
     matched: "All tests pass"

$ kanit check reply 'Fixed the parser. All tests pass.' --turn 'Edit: {"file_path": "parser.py"}' --turn 'Bash: {"command": "pytest -q"}'
pass: no rule fired (18 rules checked)

kanit check exits 1 when a deny rule fires, so it also works in scripts.

Rules in this release

id on action what it stops
tool.no-recursive-delete-home tool deny This deletes the home or root directory.
tool.no-disk-wipe tool deny This writes over a disk or partition and cannot be undone.
tool.no-force-push tool deny Force push rewrites shared history.
tool.no-hook-bypass tool deny This skips the repository's own checks (git hooks).
tool.no-package-publish tool deny Publishing a package, image or release is visible to everyone and cannot be fully taken back.
tool.no-curl-pipe-shell tool deny Piping a download straight into a shell or interpreter runs unreviewed code.
tool.no-secret-files tool deny Secret files stay out of the agent's context.
tool.no-secret-in-command tool deny A live-looking secret is written into this command or file, where shell history, logs or git will keep it.
tool.guardrails-read-only tool deny An agent does not edit its own guardrails: hook settings, hook scripts, installed plugins or kanit's rules and logs.
tool.guardrails-read-only-shell tool deny Writing to guardrail files (hook settings, hook scripts, installed plugins, .kanit/) from the shell is blocked.
tool.guardrails-read-only-mcp tool deny An agent does not edit its own guardrails through an MCP file tool either.
tool.no-test-skip tool warn This edit marks an existing test as skipped or expected to fail.
reply.tests-pass-needs-run reply deny You said tests pass, but no test command ran in this turn.
reply.build-passes-needs-run reply deny You said the build, type check or lint passes, but none of them ran in this turn.
reply.done-needs-action reply deny You claimed finished work, but no tool ran in this turn.
reply.unopened-link reply deny This link never appeared in anything you opened or were given this session.
reply.tr.tests-pass-needs-run reply deny Testlerin geçtiğini yazdın ama bu turda test komutu çalışmadı.
reply.tr.done-needs-action reply deny Bitmiş iş bildirdin ama bu turda hiçbir araç çalışmadı.

The full patterns and their examples are in kanit/rules/core.json and kanit/rules/tr.json. kanit rules lists what is active in your project.

How it decides

  • Tool rules match a regex against named fields of the tool input (command, file_path, content, ...). An unless regex can exempt a match. "only_added": true fires only when an edit adds a match that the replaced text did not have, so an existing skipped test does not trip tool.no-test-skip.
  • Reply rules match a claim in the final reply, then look for evidence among the tool calls made in this turn (since the last human message). "Tests pass" needs a test command run through a shell or a subagent; "the build passes" needs a build, type check or lint command; "I've deployed" needs at least one tool call. Only the command counts, not its description, and reading is not running: cat tests/test_api.py, ls tests/ or a Read of the file is not a test run, and neither is installing or locating a runner (pip install pytest, which pytest).
  • What is not a claim. A question ("Do the tests pass?"), a condition ("If the tests pass, merge it", "When CI is green and all tests pass, the bot merges"), an instruction ("Make sure all tests pass"), a hedge ("Ideally all tests pass"), a negation ("Not all tests pass yet"), someone else's words ("The README says all tests pass") and a phrase in quotation marks (my earlier "All tests pass" was wrong) are not checked. A statement stays a claim: "I can confirm all tests pass", "I re-ran pytest and confirm all tests pass", "This change ensures that all tests pass" and a claim under a heading line such as "## Verify" are checked, and so is a past event: "Once I pushed the fix, CI went green". A question after the claim does not excuse it: "All tests pass, want me to commit?" and "All tests pass (shall I merge?)" are checked. An unless phrase ("not verified") only excuses the sentence it is in.
  • Links in a reply must have appeared in a human message, a tool result, or the input of a read-only tool, anywhere in the session (a link not found in the last 4 MB is looked up in the whole transcript). A link the agent only wrote into a file does not count.
  • A reply is sent back once. If the next attempt still matches (stop_hook_active), kanit warns the human instead of blocking again, so a session can never loop.
  • Unknown is not missing. After a context compaction the start of the turn may be in another file. Then the turn's evidence is unknown, and the evidence rules are skipped instead of guessing. kanit stats and kanit doctor show how often that happened.
  • Warn rules do not block. Their message goes to the human, not the agent.
  • A slow check never becomes a silent pass. Claude Code lets a call through when a hook times out, so kanit stops itself first (6 s for a tool call, 14 s for a reply): an unfinished tool check denies the call and says why, an unfinished reply check warns the human. Inputs are bounded (rules file 1 MB, prior file content 2 MB) and special files (FIFOs, devices) are never read. The packaged patterns are linear with no length limit: a scan stops only where its own start repeats, so the worst 60 KB command we could build takes under 0.3 s per rule on our test machine, and a long argument list does not hide the end of a command. The budget is for project rules that are not linear. The timer needs a POSIX system; on Windows the hook timeout is the only limit.

Configure

Project rules live in .kanit/rules.json at the project root (Claude Code's CLAUDE_PROJECT_DIR, so a cd inside the session does not leave them behind). A rule with a new id is added. A rule with the id of an existing rule changes only the fields you write. "<field>+" adds an alternative to a regex instead of replacing it, null removes a field, and "disable" turns rules off.

Teach kanit your project's test command:

{
  "rules": [
    {"id": "reply.tests-pass-needs-run", "needs_turn+": "make verify|scripts/ci\\.sh"}
  ],
  "disable": ["tool.no-package-publish"]
}

A new rule:

{
  "rules": [
    {
      "id": "tool.no-prod-db",
      "event": "tool",
      "action": "deny",
      "tools": ["Bash"],
      "field": "command",
      "pattern": "psql\\s+.*prod",
      "message": "Production data is read through the replica.",
      "examples": {
        "hit":  [{"tool": "Bash", "input": {"command": "psql -h prod-db -c 'delete from users'"}}],
        "miss": [{"tool": "Bash", "input": {"command": "psql -h replica -c 'select 1'"}}]
      }
    }
  ]
}
field meaning
id, message required; the message is what the agent (deny) or the human (warn) reads
event tool or reply
action deny or warn
tools tool names the rule applies to (tool rules; default all)
tool_pattern regex on the tool name, for tool families such as MCP servers (^mcp__)
field input field or list of fields to match (tool rules; default the whole input as JSON)
pattern, unless Python regexes
needs_turn reply rules: the rule fires unless a tool call in this turn matches this regex
needs_turn_tools reply rules: only calls of these tools count as evidence (default all)
needs_turn_field reply rules: only these input fields of those calls are matched (default the whole input); the packaged test and build rules use command and prompt
check urls_seen for the link rule; unless_url exempts links
only_added tool rules: fire only when an edit adds a match
examples hit and miss lists; kanit test-rules fails a rule without a hit example

Run kanit test-rules after every change. An invalid rule is reported and skipped; the others keep working.

A project file can turn a packaged rule off or change it. When it does, kanit tells the human once per session which rules were weakened, so a cloned repository cannot quietly disarm the gates.

Environment variables, set by the human for the Claude Code process:

variable effect
KANIT_SHADOW=1 evaluate and log everything, print and block nothing
KANIT_DISABLE=rule.a,rule.b turn rules off for this process
KANIT_FAIL_CLOSED=1 deny tool calls while the engine is broken (default: allow, with a warning)
KANIT_HOME=/path where logs go (default .kanit/ in the project)
KANIT_RULES=/a.json:/b.json extra rule files, loaded after the project file

The agent cannot set these variables. The guardrail rules deny its common ways of changing the rest: editing, moving or deleting .kanit/, hook settings, hook scripts or installed plugins, restoring them with git, and claude plugin disable or uninstall. They read command text, so an interpreter one-liner that writes the file is not caught (see Known gaps).

Audit and stats

.kanit/audit.jsonl   one line per hit, engine error or invalid rule
.kanit/evals.jsonl   one line per evaluation: which rules were checked, which fired
kanit stats          checked / raw / unique hits per rule (--window 600)
kanit doctor         install, rules and log health

.kanit/ gets its own .gitignore for the logs; rules.json stays committable.

Shadow mode first. Run KANIT_SHADOW=1 for a week next to your current setup, read kanit stats, then turn enforcement on.

Where it comes from

kanit is extracted from the governance layer we run on our own agent fleet. Between 19 September and 17 November 2026 that engine recorded, across 1,690 agent sessions, 4,298 unique rule events (same session and rule within 10 minutes counted once; 3,888 to 4,505 depending on the window): 958 tool calls stopped and 3,340 replies sent back for correction. 345 of them were risky attempts (spending credits, deleting, reading secrets, sending outside, touching live systems), 1,139 were accuracy problems, 2,814 were format.

Before release we measured false alarms on real traffic:

  • Replay. The rules, replayed over the last 30 days of our sessions (399 transcripts). The first replay (17 rules; 4,962 shell commands, 615 file edits, 502 reply endings) gave 17 hits. Reading each one: five were the first reply after a context compaction, judged without the evidence from before it; one was a conditional skipTest in a brand-new test file; the rest were rule test text inside commands. After the fixes above ("unknown is not missing", only_added) and four rounds of an independent pre-release audit, the final replay of all 18 rules over the 383 latest transcripts (our own deliberate test sessions left out; 2,319 shell commands, 192 file edits, 410 reply endings) gave 2 hits. One was right: a link in a reply that never appeared in its session. One was a false alarm: a heredoc that only mentioned a *.env file name (the mention gap under Known gaps). The audit fixes changed no result on this traffic: the rules before and after them gave the same two hits.
  • Shadow run. 24 hours on live sessions, 6,735 evaluations, two hits, both false alarms, both fixed: a > inside a quoted grep pattern read as a redirect, and a project test script not recognised as a test command (now configurable with needs_turn+).
  • End to end. Claude Code 2.1.327 with the plugin loaded: a .env read denied, an unproven "All tests pass." sent back and corrected, the same claim from a subagent sent back and corrected, a skip added to a test warned.

Our fleet already runs about 228 stricter house rules, so few violations reach these 18. Read the numbers as a false-alarm measurement, not a catch rate.

Two lessons shaped the code:

  1. A gate that fails silently is worse than no gate. On 4 November a rule missing one field crashed our engine about 900 times in nine hours; it failed open and nobody saw it. kanit skips an invalid rule instead of dying, and an engine error is printed on screen (at most every 10 minutes) and logged.
  2. Hits without a denominator prove nothing. Our old log only wrote hits, so it cannot show a before/after rate. kanit writes every evaluation to evals.jsonl, so kanit stats can.

Known gaps

  • Rules are regexes, not understanding. The reply rules know common English and Turkish phrasings, not all of them ("Everything passes now", "I ran the tests and they all pass" and "No type errors." are not recognised). Quoted speech after a colon ("You wrote: All tests pass") and a sentence that defines a result ("A green badge means all tests pass") are read as claims.
  • Tool rules read the command text. A command that only mentions a dangerous string can trip them (a heredoc of notes that says "never run rm -rf ~"), and a determined agent can hide one (eval, encoding, a script file, a glob or a variable such as cat .en? or rm -rf $d, python -c "open('.claude/settings.json', 'w')"). Publishing through a wrapper we do not list (npx np) is not caught, and a command that deletes a whole tree by design (git clean -fdx) also deletes .kanit/ logs. The rules catch mistakes; they are not a sandbox. Run untrusted code in a real sandbox.
  • Evidence means a matching tool call ran in this turn, not that it succeeded: a failing pytest run still counts as "ran". The agent still has to report the result honestly. A subagent whose prompt mentions tests counts as a test run, and so does an inline script that only names a test file (python3 -c "print(open('tests/a.py').read())"); kanit does not read what the subagent did.
  • A link the agent typed into a shell command counts as seen, and so does a link it tried to fetch even if the fetch failed.
  • Windows is untested. Hooks run through Git Bash or PowerShell and need python3 on PATH.

Contributing

Bug reports with the exact input that misfired are the most useful thing you can send: see CONTRIBUTING.md. Security issues: SECURITY.md.

License

Apache-2.0, see LICENSE and NOTICE. Made by RAYNSIS AI Workforce.

Metadata

Release files for kanit-gates 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kanit-gates 0.1.0
File Size Uploaded Provenance Actions
kanit_gates-0.1.0.tar.gz 62.3 kB Without provenance Details for kanit_gates-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kanit-gates 0.1.0
File Interpreter ABI Platform Actions
kanit_gates-0.1.0-py3-none-any.whl Python 3 none any Details for kanit_gates-0.1.0-py3-none-any.whl

Total release size: 109.8 kB

Release files / kanit_gates-0.1.0.tar.gz

Download URL kanit_gates-0.1.0.tar.gz
Size 62.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b7bee039ce343860688bbaeb097401d1386ad8738a467814499a8888722fda98
BLAKE2b-256 checksum
How to use checksums
de5280543b1fe49d11d4143eec07fb4a75d79eef3432244d7d720f55966574b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / kanit_gates-0.1.0-py3-none-any.whl

Download URL kanit_gates-0.1.0-py3-none-any.whl
Size 47.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d04cba730c961a997919e94d7147b57c1fda8e2f9bb711ecfe101302804de8b
BLAKE2b-256 checksum
How to use checksums
be3c518b410745b2d24e8f548b898876bd898cdd3da7ba2eab79e89468734cbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for kanit-gates 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page