# Repository Briefing: Zazel-pixel/injection-guard
> Source: https://repoforai.com/repo/Zazel-pixel/injection-guard (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/Zazel-pixel/injection-guard
- **Category**: Coding, Skills & MCP (AI 编程 / Skills / MCP)
- **Primary Language**: Python
- **License**: MIT
- **Engineering Health**: B (59/100 · Maintenance 31/35 · Adoption 2/25 · Releases 6/20 · License 20/20)
- **Review Snapshot**: 2026-12-02
- **Deployment / Stack Signals**: CLI, Self-Hosted
- **Momentum**: 195 ★ total (+0 24h / +195 7d) · 1 forks
- **Topics**: `ai-agents`, `claude-code`, `codex`, `llm-security`, `prompt-injection`, `security-tools`
- **When to Use**: Best for: Claude Code or Codex teams that want an offline, auditable warning layer for explicit prompt injection and a narrow shell gate alongside existing sandbox and approval controls. Skip if: You need reliable multilingual or paraphrase detection, comprehensive shell enforcement, or a standalone security boundary for agents with sensitive credentials or broad write access.

## Overview
```text
### Architecture & Core Mechanics
injection-guard is a single-file Python extension for Claude Code and Codex hooks. `PostToolUse` inspects returned text from files, web pages, command output, and MCP responses; it can warn the agent but never vetoes the completed call. `PreToolUse` is the enforcement point: it parses shell quoting and blocks supported download-and-execute patterns without rejecting a command merely because it quotes an example.

The scanner uses regular expressions and Unicode heuristics rather than a trained model. It strips invisible characters for matching and assigns severity based on the pattern and its context. Short citations can be logged without surfacing an alert, while strings in structured value positions remain eligible for alerting. Repeated findings are logged but not shown again within the same session. There is no network dependency.

### Key Capabilities & Differentiators
The scanner flags patterns such as instruction overrides, fake authority, credential bait, and tool coercion. The public evaluation counts documents with at least one alert shown to the agent, not all matches. Current results are 1.6% on unmodified InjecAgent attacker instructions versus 100% with an explicit override prefix, 45.5% on 112 held-out Lakera Gandalf prompts, and 4.0% on the English deepset injections. None of the 399 benign deepset prompts surfaced an alert.

Replay of about 86,400 private tool outputs from one person's sessions reduced surfaced alerts from 323 to 53; no genuine injection was identified among the reviewed alerts. This is evidence of lower alert noise on that workload, not a measure of attack recall. For ongoing review, the local JSONL log records redacted excerpts, and `tools/audit_log.py --list` displays them.

### Trade-offs & Limitations
The main advantage is inspectability: one standard-library file, no model to operate, and no remote API. The cost is narrow coverage. English-only patterns miss paraphrases, the German deepset subset produced no alerts, and citation handling trades fewer false alarms for missed detections. The shell gate covers only selected execution forms; it is not a general command policy or sandbox. After a post-tool warning, the agent still decides what to do.

Classifier-based alternatives such as Llama Prompt Guard 2 and LLM Guard are worth evaluating for paraphrase coverage, with additional model runtime and licensing considerations. Azure Prompt Shields and Lakera Guard offer hosted scanning, changing the data boundary. Choose this hook for local visibility and narrow enforcement, while keeping sandboxing, least-privilege credentials, and human approval for consequential actions independent of it.

### Hardware & Deployment Guide
Install from a checkout with `python3 install.py` on Python 3.10 or newer. It copies `injection_guard.py` to `~/.local/share/injection-guard/`, links detected Claude Code and Codex hook directories to the shared copy, and backs up replaced files. The installer does not edit settings: use `python3 install.py --config` to print the entries to add to `~/.claude/settings.json` and `~/.codex/hooks.json` as applicable.

Run `python3 install.py --check` to confirm that both installed hooks, where present, resolve to the shared script and that it matches the checkout. There is no published release to pin; for a repeatable rollout, select a specific revision and validate it with `python3 -m unittest discover -s tests` and `python3 evaluate.py` before installing. The runtime is entirely local and reads no model weights.
```

## Key Capabilities
```text
- Hook model: Claude Code and Codex use separate post-tool alerting and pre-shell enforcement hooks.
- Execution control: Shell-aware parsing distinguishes supported download-to-shell commands from quoted mentions.
- Local audit: JSONL records redacted finding excerpts; `tools/audit_log.py` summarizes them and `--list` displays them.
- Detection coverage: InjecAgent alert rates were 1.6% for unmodified attacker instructions and 100% with an explicit override prefix; the German deepset subset yielded no alerts.
- Regression gates: `tests/test_corpus.py` checks detection and false-alarm thresholds; `evaluate.py --guard OLD.py` enables direct comparison against another version.
- Installation: One shared local script backs both agents through symlinks; settings registration remains manual.
```

## Quick Start / Clone
```bash
python3 install.py
```
