Metadata-Version: 2.4
Name: ezco
Version: 0.2.1
Summary: Security guard for AI coding agents: fake packages, leaked secrets, poisoned agent files, at commit, install and clone time
License-Expression: MIT
Project-URL: Homepage, https://github.com/negimedhansh47-jpg/ezco
Project-URL: Issues, https://github.com/negimedhansh47-jpg/ezco/issues
Keywords: security,ai-agents,slopsquatting,prompt-injection,mcp,pre-commit,claude-code,codex,cursor
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# ezco

Website: https://negimedhansh47-jpg.github.io/ezco/

A security guard for commits written by AI coding agents. It runs before every `git commit` and **blocks the commit** if it finds:

- **Fake or suspicious packages.** AI tools invent package names that don't exist (about 1 in 5 in one study of 576,000 code samples). Attackers register those names ("slopsquatting"). Blocks packages that don't exist and typos of popular packages that almost nobody uses. Checks `requirements.txt`, `pyproject.toml`, `package.json` and packages launched by MCP configs.
- **Leaked secrets.** API keys (AWS, GitHub, OpenAI, Anthropic, Google, Stripe, Slack, Groq; from 0.2.0 also npm, PyPI, Hugging Face, GitLab, Slack webhooks, and keys split with `+` or written in base64), private keys (PGP from 0.2.0), passwords inside database URLs, and random-looking hard-coded secrets, with the exact link and steps to revoke each one. Secrets are masked in the report. Also warns when a `.env` file is committed.
- **Poisoned MCP tools and agent files.** Hidden Unicode characters, prompt-injection phrases in MCP tool code, `AGENTS.md`, `CLAUDE.md`, `.cursorrules` and Cursor `.mdc` rules, and risky MCP server configs (unpinned packages, `curl | sh`, plain-http servers). It scans files in your repo; it does not connect to live MCP servers.
- **`--deep` mode (optional).** An LLM (Groq) second pass for attacks the rules can't see. Secrets are redacted before anything is sent, and the LLM can only add warnings, never cancel a rule.

## Install

```
pip install ezco
cd your-project
ezco install
```

That's it. Every `git commit` in that repo is now checked. Only the lines and packages the commit **adds** are checked, so it stays fast. Needs Python 3.11+.

**Versions:** the current release is 0.2.1: 0.2.0 has every fix from stress test 3 ([docs/stress-test-report.md](docs/stress-test-report.md)), 0.2.1 adds the lines marked "from 0.2.1". On an older version? Run `pip install -U ezco`. Lines below marked "from 0.2.0" are new in that release.

If `ezco` isn't found (or Windows blocks `ezco.exe`), use `python -m ezco` instead: `python -m ezco install`. If you already have a pre-commit hook, `ezco install --force` keeps it as `pre-commit.old` and runs it first.

## Use

| Command | What it does |
|---|---|
| `ezco install` | Turn on the check for every commit in this repo |
| `ezco scan` | Scan the whole folder now (or `ezco scan file.py folder/`) |
| `ezco scan --deep` | Same, plus the LLM review (needs `GROQ_API_KEY`) |
| `ezco install --agent [claude\|codex\|gemini\|all]` | Also stop an AI agent from **installing** a fake package (see below). Default: `claude` |
| `ezco clone <url> [folder]` | Clone a repo and quarantine dangerous AI-agent files (see below) |
| `ezco guard [folder]` | Check a folder's AI-agent files before opening an agent there |
| `ezco uninstall` | Turn it off |

**Why `--agent` matters:** a malicious package can run code the moment it is installed, so catching it at commit time is too late. `--agent` adds a hook to the agent's project settings (`.claude/settings.json`, `.codex/hooks.json` or `.gemini/settings.json`). Before the agent runs `pip install`, `npm i`, `uv add`, `npx` and similar, the packages are checked. A fake or typo package gets the command denied, and the agent is told why, so it picks the real package instead. The hook answers with each tool's documented JSON "deny", so the shell's exit-code handling doesn't matter. It runs in PowerShell, sh, bash and `cmd.exe`. On Windows, Claude Code uses Git Bash or PowerShell, Codex uses `cmd.exe /C` and Gemini CLI uses PowerShell (read from their source code on Nov 28, 2026; each hook command was run the same way here). The Codex part is **inferred** from one file (`codex-rs/hooks/src/engine/command_runner.rs`), not traced end to end and not live-tested. Earlier versions of this README said cmd can't run the hook's `C:/.../python.exe` path. That was too broad: it fails only after a pipe inside a cmd line, not at the start, which is where Codex puts it (if the inference holds). With 0.1.0, the gate let everything through when Windows PowerShell piped the hook JSON with a byte-order mark and Python's UTF-8 mode was off; fixed from 0.2.0. ezco must be pip-installed, because the hook runs `python -m ezco`. Codex asks you to review and trust a new hook before it runs.

**From 0.2.1:** the gate also denies an agent's `git commit --no-verify` (or `-n`, also inside `-anm`), which would skip the commit hook. The agent is told to fix what the hook found or ask you; if you want the hook skipped, run that commit yourself. It stops the one-flag escape, not a determined agent: `git -c core.hooksPath=...`, deleting the hook, a git alias or a script that commits are not caught. Multi-line commands are now read as the shell reads them: a heredoc or here-string commit message is one argument (the usual Claude Code commit shape), and a `\` or `` ` `` line continuation no longer hides a package on the next line (that hid installs in 0.2.0 too). Quote marks inside heredoc and here-string bodies are ignored, so an apostrophe in a message (`don't`) no longer hides a `--no-verify` after it or an install on a later line. Body lines are still read as commands, as in 0.2.0, because a body is often a script that runs (`cat > i.sh <<EOF` then `bash i.sh`, `ssh host <<EOF`). A body inside an open quote (`git commit -m @'...'@`, `-m "$(cat <<EOF ...)"`) is one argument, the message, and is also read as commands when something may run it (a shell, `eval`, `source` or `iex` on its first or last line, a `$c = @'` assignment, `$(...)` lines in `<<EOF` or `@"`). So a heredoc body outside any quote that starts with `git commit -n` or a fake install is denied, like 0.2.0 did for installs. The gate also gives up on a hanging registry sooner: 5 s per network wait instead of 10 s (the commit hook keeps 10 s), and a timeout still means allow. Tested by piping hook JSON to the gate, **not yet live** inside Claude Code.

**Also from 0.2.1:** `pip install -r file` (and `uv pip install -r`) reads that file, and a bare `npm install` / `pnpm install` / `yarn install` / `bun install` reads `package.json`. Only names the file adds compared with its last commit are checked (a file git doesn't know yet counts as all new), so the packages your project already had, private ones too, aren't looked up again. A requirements file with `--index-url` or `--extra-index-url` is skipped, because its packages may come from a private index. Paths are read from the agent's folder (`cwd` in the hook input; Claude Code documents it, Codex and Gemini CLI are unverified). Not read: `npm ci` (lockfile), `uv sync`, `poetry install`, `-r` files inside `-r` files, and a `cd other && npm install` (the gate reads the agent's folder, not `other`).

**Also from 0.2.1 (commit hook, `scan` and gate):** `pyproject.toml` `[dependency-groups]` (PEP 735) and Poetry `[tool.poetry.dependencies]`, `dev-dependencies` and `group.*.dependencies` are read (Poetry entries from a path, git, URL or a private `source` are skipped), and so are `package.json` `optionalDependencies` and `peerDependencies`.

## Which agents are covered

| | Claude Code | Codex CLI | Gemini CLI | Cursor | Any other agent |
|---|---|---|---|---|---|
| Commit hook (git) | Yes (from 0.2.1 the install gate also denies `--no-verify`) | Yes (same) | Yes (same) | Yes, unless it uses `--no-verify` | Yes, if it commits with git and doesn't use `--no-verify` |
| Clone guard: instruction files | `CLAUDE.md` | `AGENTS.md`, `AGENTS.override.md` | `GEMINI.md` | `.cursor/rules/*.mdc`, `.cursorrules`, `AGENTS.md` | Windsurf, Cline, Copilot files |
| Clone guard: hooks + MCP servers | `.claude/settings.json`, `.mcp.json` | `.codex/hooks.json`, `.codex/config.toml` | `.gemini/settings.json` | `.cursor/hooks.json`, `.cursor/mcp.json` | `.vscode/mcp.json` |
| Install gate | Yes, **live-tested** (Windows) | Yes, format from Codex docs, **not live-tested** | Yes, format from Gemini docs, tested by piping its hook JSON through PowerShell and sh. Gemini CLI 0.58 loads the hook ("These hooks will be executed"), but a full live run is **not done yet** | **No** (see below) | No |

- **No Cursor install gate, on purpose.** Cursor's docs don't say whether a hook answering "allow" skips your normal approval prompt. If it does, a gate that allows clean commands would auto-run every command, and Cursor would get *less* safe. The clone guard still covers Cursor's files.
- Formats and sources: [docs/research-harnesses.md](docs/research-harnesses.md). CI runs the tests on Linux, macOS and Windows, with Python 3.11 to 3.13.
- **Live tests:** Claude Code on Windows (Nov 27, 2026). `pip install reqeusts-toolbeltz` was denied with the reason shown to Claude, and `pip install requests` ran normally.
- **Try it yourself in Codex or Gemini:** in a throwaway git repo, run `ezco install --agent codex` (or `gemini`) and start the agent there (trust the folder or hook if asked). Ask it to run `pip install reqeusts-toolbeltz`: it should be denied with the reason. Then `pip install requests` should run normally. Please report the result in an issue.

## Clone guard: protect yourself from repos you pull in

```
ezco clone https://github.com/someone/repo
```

A repo you clone can attack **you**, not just your commits. Its `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, `.cursorrules`, `.windsurfrules`, `.clinerules`, Cursor `.mdc` rules or `copilot-instructions.md` can hide instructions for your AI agent (invisible Unicode, "ignore previous instructions..."). Its `.mcp.json` can launch a server, and its `.claude/settings.json`, `.cursor/hooks.json`, `.codex/hooks.json`, `.codex/config.toml` or `.gemini/settings.json` can hold a hook that runs a command on your machine. When a hook runs a script shipped in the repo (`bash .cursor/hooks/setup.sh`), the script is checked too.

`ezco clone` runs `git clone`, then checks every one of those files. Any file with a BLOCK finding is renamed to `<name>.quarantined`, so no agent loads it. The report says what was found and how to rename it back. Hidden "tag" characters are decoded, so you see the smuggled message. In a cloned repo, `ezco:ignore` marks and `.ezcoignore` are **not** honoured, because the repo's author wrote them.

- Already cloned? `ezco guard path/to/repo` does the same check (`--no-quarantine` to only report).
- `--deep` (on `clone` or `guard`) also sends the agent files, secrets redacted, to the LLM. It catches reworded attacks with no trigger phrases. Unlike at commit time, an LLM hit here **quarantines** the file it names. The LLM can still only add findings, never clear the rules' findings, and a quarantine is just a rename you can undo.
- `ezco install` also adds a `post-merge` git hook that re-checks agent files after every `git pull` (warns only). `git pull --rebase` doesn't run post-merge hooks, so it's not covered there.
- A hardcoded key in a cloned agent file is reported as a WARN from 0.2.0 (a BLOCK and a quarantine in 0.1.0): someone else's leaked key can't attack you.
- Rules are stricter than at commit time, because a stranger wrote these files. **Any** prompt-injection sign in an agent file quarantines it, and so does a hook that uploads data (`curl -d`), runs encoded code (`-EncodedCommand`, `base64 -d | sh`) or runs downloaded code. Other hook commands only warn. The catch: a `CLAUDE.md` that quotes an attack as a security example gets quarantined too. Read it and rename it back.
- Exit codes: `0` clean or warnings only, `1` something was quarantined (or found, with `--no-quarantine`), `2` the folder doesn't exist. `ezco clone` passes on git's own exit code if the clone fails.
- `ezco uninstall` removes the commit hook, the post-merge hook and the agent gate.

**The honest catch:** Claude Code loads `CLAUDE.md` the moment it starts in a folder, and no Claude Code hook can stop that. So the protection only works if the check runs **before** you open an agent there: clone with `ezco clone`, or run `ezco guard` first. Opening a poisoned folder directly with an agent is not protected. (Claude Code does ask you to trust a new folder first; that is your last chance to run `ezco guard`.)

**Demo** (run it in a clone of this repo; `demo/` is not in the pip package): `python demo/make_trap_repo.py trap` builds a booby-trapped repo (hidden Unicode + an injection line in `CLAUDE.md`, and a `.claude/settings.json` hook that runs `curl ... | sh`). Then `ezco clone trap victim`. The payload points at `example.invalid`, which can never resolve.

**False alarm? Three ways out:**

| Way | Works in | Example |
|---|---|---|
| `ezco:ignore` anywhere on the line | any file with comments (`.py`, `.js`, `.env`, `.yaml`, `requirements.txt`, Markdown via `<!-- ezco:ignore -->`) | `KEY = load()  # ezco:ignore` |
| `.ezcoignore` file in the repo root | any file, incl. JSON (no comments allowed there) | `demo/` or `*.min.js` |
| skip once | the whole commit | `git commit --no-verify` |

- **Deep mode on a commit:** set `EZCO_DEEP=1` (PowerShell: `$env:EZCO_DEEP=1`) before `git commit`. Get a free key at console.groq.com/keys and set `GROQ_API_KEY`, or put `GROQ_API_KEY=...` in a `.env` file in the repo folder (keep `.env` in `.gitignore`). A real environment variable wins over `.env`.

`BLOCK` stops the commit. `WARN` is printed but lets it through.

## Try the demo

```
python -m ezco scan demo
```

Run it in a clone of this repo. `demo/` has planted problems: a fake package, a typo package, leaked keys, a poisoned MCP tool and a risky `.mcp.json`. None of the keys are real.

## Run tests

```
python -m unittest discover -s tests
```

## How it compares (honest table)

Taken from each tool's own README, read Nov 27, 2026. "Not stated" means their docs don't say. It does **not** mean the tool can't do it. slopgate-cli's npm page refused automated reading, so its column comes from Socket.dev's copy of its README and is **unverified**.

| Feature | ezco | [slopscan](https://github.com/DARusrus/slopscan) | [depfence](https://github.com/ericrihm/depfence) | [gitleaks](https://github.com/gitleaks/gitleaks) | slopgate-cli (unverified) | [What's Inherited](https://github.com/stcmain/whats-inherited-mcp) |
|---|---|---|---|---|---|---|
| Fake (AI-invented) packages | Yes: PyPI + npm, live registry | Yes, live registry check is opt-in | Yes, 14 ecosystems, from curated lists | No | Yes, npm only | No |
| Typos of popular packages | Yes | Not stated | Yes | No | Yes | No |
| Leaked secrets | Yes | Yes | Yes | Yes (the most mature here) | No | No (reads env var names only) |
| Exact revoke steps per key | Yes | Not stated | Not stated | Not stated | No | No |
| Prompt injection / hidden Unicode in agent files | Yes | Partly (in source code) | Yes (zero-width, MCP tool text) | No | No | Lists the files, doesn't judge them |
| MCP config check | Yes | Secrets only | Yes | No | No | Lists servers only |
| Pre-commit hook | Yes | Yes | Yes | Yes | No | No |
| Stops an agent's install before it runs | Yes: Claude Code (live-tested), Codex, Gemini CLI | Not stated | Listed as an integration, no details | No | Yes, Claude Code + Codex, npm only, macOS/Linux builds | No |
| Checks `.claude/settings.json` hook commands | Yes | Secrets only | Partly (SessionStart hook injection) | No | No | Yes, lists them |
| Quarantines a cloned repo's agent files before an agent opens them | **Yes** (`ezco clone`) | Not stated | Not stated | No | No | No: "Nothing is edited, quarantined or scored" |
| Optional LLM review | Yes, Groq, secrets redacted, can only add warnings | Yes, Gemini | No | No | No | No |

**What only ezco does (by these tools' own docs):** quarantining a cloned repo's agent files before an agent loads them, and giving revoke steps for each leaked key. It also covers commit time, install time and clone time in one zero-dependency tool.

**Where others are stronger:** depfence covers far more ecosystems (Cargo, Go, Maven...) and does SBOMs. gitleaks has much deeper secret rules and scans git history. What's Inherited gives a fuller inventory of what a repo hands an agent (skills, subagents, imports).

## Limits (honest list)

- Secret detection uses patterns. Unusual secret formats are missed, and deep-mode redaction only hides what the patterns catch.
- Injection phrases are English keyword rules; clever rewording gets past them (that's what `--deep` is for). A single phrase only blocks in agent files and MCP tool code; elsewhere (e.g. docs that quote an attack) it warns.
- If PyPI/npm can't be reached, unknown packages get a WARN, not a BLOCK, so a network hiccup never stops your work.
- Deep mode is tested offline with a fake LLM, and was run live once on Groq with `openai/gpt-oss-120b`. Override the model with `EZCO_MODEL`.
- The clone guard checks only the agent files listed above (from 0.2.0 also `CLAUDE.local.md`, `.claude/agents`, `.claude/commands`, `.claude/skills` and Copilot `*.instructions.md`). It doesn't check `statusLine` commands or a repo's normal code. It follows hook commands into scripts inside the repo, but not Windows-style `.\script.ps1` paths.
- The install gate doesn't run in Claude Code if Python is installed in a folder with a space (`C:\Program Files\...`) and Claude Code uses PowerShell: the hook's quoted path needs `&` there, and `&` would break Git Bash, which Claude Code may use instead. From 0.2.1 the Gemini CLI hook adds the `&` (Gemini always uses PowerShell on Windows), and cmd runs the quoted path as is (Codex uses cmd on Windows, inferred from its source, not live-tested). A per-user Python install has no space.
- The install gate fails open: if the registry can't be reached it allows the install. A registry that hangs makes it wait up to 10 s per batch of 8 unknown names before allowing.
- More limits found by the stress test: [docs/stress-test-report.md](docs/stress-test-report.md).

## Test results

**0.2.0 (Nov 28, 2026):** 127 automated tests. Clone corpus 44 of 47, harness corpus 44 of 44, install-gate corpus 98 of 98. The corpora grew during stress test 3: the added cases (`s3_*`) were written by the session that fixed them, not by an independent agent. The original 70 repo cases score 67 of 70. On 500 real agent files from 7 public repos, 2 were quarantined, both security guides quoting "ignore previous instructions" as an example. Full report: [docs/stress-test-report.md](docs/stress-test-report.md).

**Now (0.2.1, Nov 28, 2026):** 138 tests. Install-gate corpus 120 of 120 (22 cases for `--no-verify`, heredoc and here-string bodies and line continuations, added by the sessions that built and fixed the rule). Clone and harness corpora unchanged.

**Earlier results (Nov 27, 0.1.0):**

- **Accuracy:** 99 of 107 hand-labelled cases correct, written by a separate AI agent that hadn't seen the code. **0 false alarms** on 30 normal files (lookalikes like `tokenizer=`, UUIDs, lockfile hashes, emoji, Hindi/Arabic text, placeholder keys).
- **Clone guard (Nov 27):** 37 of 40 hand-labelled repos correct with the rules alone (written by a separate AI agent that hadn't seen the code). Misses: two attacks reworded with no trigger phrases, and one false alarm, a `CLAUDE.md` security note quoting an attack. With `--deep`, both reworded attacks were caught. One more harmless-labelled repo was flagged, a hook that silently runs `pip install -r requirements.txt`.
- **Cursor / Codex / Gemini files (Nov 27):** 30 of 30 hand-labelled cases correct, after adding a rule for script-level attacks (Python/JS that fetch-and-eval, save-and-run, or send secrets out). 0 false alarms on 102 real `.cursor/hooks.json`, `.codex/config.toml`, `.codex/hooks.json` and `.gemini/settings.json` files from public GitHub repos.
- **Rerun them:** `python tests/corpus/score.py`. The cases are stored as JSON, not as real files, so no agent working on this repo loads the poisoned ones.
- **Real repos:** 0 false alarms on 271 real agent files from [awesome-cursorrules](https://github.com/PatrickJS/awesome-cursorrules) (257 Cursor rules), openai/codex, anthropics/claude-code and langfuse, after fixing one hit on "builds do not read `.env` files". Guarding a 5,000-file repo with a 1 MB `CLAUDE.md` takes about 2 seconds.
- **Install gate (Nov 27):** 40 of 40 commands correct (15 fake or typo installs blocked, 25 real or non-install commands allowed). It takes about 0.4 s per command, or about 1 s when an unknown package needs a registry lookup.
- **Speed:** a normal commit takes under 1 second. The first commit of a 40-package npm app is instant (popular packages are known-safe). A full scan of 2,000 files takes about 12 seconds. A 1 MB single-line file takes under 1 second.

See `AI_USAGE.md` for every tool, API and dataset used.

## Maintainers: publishing to PyPI

Releases use PyPI Trusted Publishing (`.github/workflows/release.yml`). No API token is stored anywhere. It runs only when a `v*` tag is pushed.

1. Create an account at pypi.org/account/register and turn on 2FA (PyPI requires it).
2. Go to pypi.org/manage/account/publishing and add a **pending publisher**: PyPI project name `ezco`, owner `negimedhansh47-jpg`, repository `ezco`, workflow `release.yml`, environment `pypi`.
3. On GitHub: repo Settings > Environments > New environment, name it `pypi`. (Optional: add yourself as a required reviewer, so each release waits for your click.)
4. Make sure `version` in `pyproject.toml` is the version you want, commit and push.
5. Tag and push the same version, e.g. `git tag v0.2.0` then `git push origin v0.2.0`.
6. Watch the Actions tab. When the `release` job is green, the package is on pypi.org/project/ezco.

A version number can be published only once. For a fix, bump `version` and push a new tag.

## License

MIT. See [LICENSE](LICENSE).
