Zazel-pixel/injection-guard
Local Python hooks that flag prompt injection and block common download-to-shell commands
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Tracked from daily D1 telemetry snapshots. Hover any data point for exact daily star counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & 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.
tools/audit_log.py summarizes them and --list displays them.tests/test_corpus.py checks detection and false-alarm thresholds; evaluate.py --guard OLD.py enables direct comparison against another version.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.
You need reliable multilingual or paraphrase detection, comprehensive shell enforcement, or a standalone security boundary for agents with sensitive credentials or broad write access.
Quick Start & Installation
python3 install.pyComparison vs. Top Coding, Skills & MCP Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| injection-guard ★ | 195 | +195 | Python | MIT | Local Python hooks that flag prompt injection and block common download-to-shell |
| obsidian-skills | 56.2k | +1.7k | Shell | MIT | Agent Skills plugins for editing Obsidian files and working with vaults |
| spec-kit | 153.7k | +1.3k | Python | MIT | A Python CLI for spec-driven coding-agent workflows and reviewable handoffs |
| academic-research-skills | 59.6k | +694 | Python | — | Claude Code plugin for human-reviewed research, manuscript writing, and peer rev |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/Zazel-pixel/injection-guard.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about injection-guard
How does it integrate, and does it run an MCP server?
PostToolUse and PreToolUse in Claude Code or Codex to inspect returned content and gate supported shell commands, respectively. MCP responses are one kind of tool output the post-tool hook can inspect.What hardware and runtime budget does it need?
Can a commercial team self-host it, and what data remains on disk?
corpus/external/NOTICE.md separately if you plan to redistribute evaluation data.When should I choose a classifier or hosted service instead?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy