agentleFS
mythrenmythren/git-fence/CLAUDE.md

git-fence

CLAUDE.md0 starsChanged 5 months agoMITView on GitHub

A Claude Code plugin + CLI that warns AI agents, via a non-blocking PreToolUse hook, when an edit touches code introduced by a bug-fix commit (a "Chesterton's Fence" guard). Indexes git history into SQLite, blames the exact lines being edited. No pytest, linter, or build step - tests are stdlib unittest. The entire implementation is one file, git_fence.py. bin/git-fence is a thin launcher importing it; hooks/hooks.json invokes that launcher via ${CLAUDE_PLUGIN_ROOT}; pyproject.toml exposes the same main() as a console script.…

The file

We split this CLAUDE.md into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No pytest, linter, or build step - tests are stdlib unittest.

    line 21

≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

A Claude Code plugin + CLI that warns AI agents, via a non-blocking PreToolUse hook, when an edit touches code introduced by a bug-fix commit (a "Chesterton's Fence" guard). Indexes git history into SQLite, blames the exact lines being edited.

Commands

python3 -m unittest discover -s tests -v                # run all tests
python3 -m unittest tests.test_git_fence.TestHook -v    # run one test class
claude plugin validate .                                # validate manifests
claude --plugin-dir .                                   # develop live (/reload-plugins after edits)
scripts/demo.sh                                         # end-to-end demo on a fresh Express.js clone
python3 scripts/benchmark.py <indexed-repo> [subdir] [samples]  # fire-rate benchmark

No pytest, linter, or build step - tests are stdlib unittest.

Architecture

The entire implementation is one file, git_fence.py. bin/git-fence is a thin launcher importing it; hooks/hooks.json invokes that launcher via ${CLAUDE_PLUGIN_ROOT}; pyproject.toml exposes the same main() as a console script. Tests import the module via SourceFileLoader and also drive the CLI as a subprocess.

Two flows meet in .git/git-fence.db (found via --git-common-dir, so worktrees share one index):

  • Index time (cmd_index, incremental from meta.last_sha): git log -z --name-only -> iter_log_records (NUL-delimited; a %x1f header sentinel keeps control bytes in messages from corrupting rows) -> classify_commit -> commits/file_commits. --github backfills PRs/issues via gh GraphQL and escalates commits whose PR closed a bug-labeled issue.
  • Edit time (cmd_hook, PreToolUse JSON on stdin): edited line spans (edit_spans; whole-file history for Write) -> git blame -L -> look up blamed SHAs at severity >= 2 -> emit additionalContext JSON. cmd_refresh (SessionStart) reindexes already-indexed repos only.

The two-tier severity classifier is the core of the project and is deliberately verb-sensitive: tier 2 (warns) = fixes #N, severe defect keywords, or bug-label evidence; tier 1 (silent) = generic "fix" / closes #N. Bare "revert"/"security" were demoted after causing false positives - code comments record those decisions; don't re-add them without benchmark proof.

Invariants

  • The hook must never break a session: every path in cmd_hook/cmd_refresh exits 0 silently on failure (GIT_FENCE_DEBUG=1 shows tracebacks).
  • Re-run the fire-rate benchmark after any classifier change. Kill metric: fire rate on random 5-line edits in Express.js lib/, baseline ~11%; a higher rate needs example warnings proving real fixes (CONTRIBUTING.md).
  • git_fence.py stays Python-stdlib-only; gh is optional, never required.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.