Skip to content

ButterFence

ButterFence is a Claude Code-native safety harness that red-teams your repo against destructive and secret-leaking AI agent behavior, then auto-generates enforceable hooks to prevent it.

Core trick

Opus generates obfuscated attack scenarios against the repo, then writes regex patches that install as Claude Code hooks blocking the bypasses.

Tags

Description

ButterFence is a Claude Code-native safety harness that red-teams your repo against destructive and secret-leaking AI agent behavior, then auto-generates enforceable hooks to prevent it. The core innovation: Claude Opus 4.6 as the adversary. The redteam command scans your repo structure and tech stack, then asks Opus 4.6 to generate creative attack scenarios, obfuscation, encoding tricks, variable indirection, tailored to YOUR codebase. ButterFence catches them in real-time. When attacks get through, Opus 4.6 analyzes gaps and generates exact regex patches. One command runs the full attack-patch-verify loop. Ships with 44 scenarios, 11 threat categories, 7 rule packs (OWASP, AWS, Docker), 5 export formats, entropy detection, obfuscation decoding, behavioral chain detection, live dashboard, and CI/CD integration. Claude attacks. Claude defends. Claude patches. 315 tests. 35+ modules. Open source.
ayush585/ButterFence★ 11 forksPythonMITCreated Feb 15, 2026 · last push Feb 16, 2026

README excerpt

<p align="center">
  <img src="https://raw.githubusercontent.com/ayush585/ButterFence/main/assets/logo.png" alt="ButterFence Logo" width="200">
</p>

<h1 align="center">ButterFence</h1>

<p align="center">
  <strong>Claude Code-native safety harness</strong> that red-teams repos against destructive/secret-leaking agent behavior and auto-generates enforceable Claude Code hooks to prevent it.
</p>

<p align="center">
  <a href="https://pypi.org/project/butterfence/"><img src="https://img.shields.io/pypi/v/butterfence.svg" alt="PyPI"></a>
  <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python 3.10+"></a>
  <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License: MIT"></a>
  <img src="https://img.shields.io/badge/tests-315%20passing-brightgreen.svg" alt="Tests">
</p>

---

## What It Does

1. **Init** - Installs safety hooks into Claude Code that intercept dangerous tool calls in real-time
2. **Audit** - Runs 44 red-team scenarios covering 11 threat categories
3. **Red Team** - Uses **Claude Opus 4.6 as an adversary** to generate novel, repo-specific attack scenarios and test them against your defenses
4. **Scan** - Proactively scans repos for secrets, dangerous files, and high-entropy strings
5. **Report** - Generates scored safety reports in Markdown, HTML, JSON, SARIF, or JUnit
6. **Watch** - Live terminal dashboard monitoring all hook events in real-time
7. **CI** - CI/CD int

Team