mantis-patch

A security-fix step that creates, applies, and verifies small code changes for confirmed vulnerabilities using isolated copies or backups.

In plain words
What is it for?
Use it after a vulnerability has been reproduced to apply and verify the corresponding security patch.
Why use it?
It limits the chance that patching a security issue will damage unrelated source code and checks whether the fix works.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/google/mantis/mantis-patch
Any agent
npx skills add google/mantis --skill mantis-patch
Clone the repo
git clone --depth 1 https://github.com/google/mantis

Made for: Claude Code, Codex.

Per session 52 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 10,940 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00052 $0.10940
Opus 5 $0.00026 $0.05470
Sonnet 5 $0.00010 $0.02188
Haiku 4.5 $0.00005 $0.01094

Measured 2d ago against content hash c14701e02eb6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

mantis-patch scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Recursive force deletemediumDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

completely (e.g., `rm -rf <shadow_directory>`). Since the original

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

mantis-patch/SKILL.md · 774 lines

How it starts

The opening of the file, as written. The whole thing — 774 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Patcher (/mantis-patch)

System Goal

Security Patching Expert. Generates minimal, correct code fixes, applies them to source code files, and verifies them inside isolated sandboxes before appending logs to long-term memory.

Command Definition

  • Command: /mantis-patch [--target_root=<path>] [--state_root=<path>] [--snapshot_root=<path>] [--snapshot_id=<id>] [--snapshot_pinned=<true|false>]
  • Description: Generates minimal security fixes using transactional isolation (shadow directories or file backups), applies patches, and verifies them.
  • Parameters (all optional; absent ⇒ today's behavior):
    • --target_root: Root of the code snapshot to read (CODE_ROOT). When the orchestrator pins a snapshot it passes --snapshot_root; --target_root is reserved for a caller that hands you an already-prepared tree.
    • --snapshot_root: Root of the pinned immutable snapshot for this pass.
    • --snapshot_id: The SNAPSHOT_ID string of the pinned snapshot (used by the Snapshot Match Check).
    • --snapshot_pinned: true when a pinned immutable snapshot exists this pass; false/absent ⇒ degraded/legacy (see Backward-compat).
    • --state_root: Root of the Mantis state directory that contains workspace/ (defaults to the current directory). ALL workspace/... paths in this file are STATE-RELATIVE and resolve under <state_root>/workspace/....

Input/Output Contract

  • Reads:
    • workspace/findings/ (reproduced finding JSON files where patch_status is not "VERIFIED_SECURE" or "MITIGATION_PROPOSED").
    • workspace/.mantis_state.json (to track current loop pass).
    • workspace/.mantis_state.json active_snapshot (root, snapshot_id, snapshot_pinned) — resolved via Block A; supplies CODE_ROOT and the SNAPSHOT_ID used by the Snapshot Match Check when no --snapshot_* flag is passed.
    • Target source code files.
    • Reproducer script path (repro_file_path) and command (run_command) from findings.
    • Pre-existing backup files matching finding ID (if Option B is used).
  • Writes:
    • Source code modifications (applied transactionally and rolled back).
    • Updates finding JSON files in-place (sets "patch_status", "patch_diff", re-attack details including "reattack_status" and "reattack_variants", and history).
    • Appends to workspace/learnings.jsonl.
    • Reusable helper script workspace/helpers/append_patch.py.
  • Preconditions:
    • Findings must exist in workspace/findings/.
  • Idempotency Guarantee:
    • Snapshot-aware skip: Skips a finding whose patch_status is already "VERIFIED_SECURE" or "MITIGATION_PROPOSED" ONLY when its recorded patch_base_snapshot equals the current SNAPSHOT_ID (i.e. it was verified against THIS snapshot). If patch_base_snapshot is absent, empty, or different from the current SNAPSHOT_ID, the terminal status is stale — do NOT skip; re-open and re-verify the finding against the current snapshot. In legacy mode (no active_snapshot and no --snapshot_* flags) skip exactly as today (by patch_status alone).
    • Transactional isolation: modifies code inside uniquely generated temporary directories or creates temporary file backups (target.c.bak-[id]), restoring baseline state upon completion (using try...finally rollback mechanisms).
    • Reuses the existing append_patch.py script once created.

Read the full file on GitHub · 774 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 774 lines · 52 tokens per session scan B c14701e02eb6

Subscribe to this mod's changes

mantis-patch is a skill published in the GitHub repository google/mantis (781 stars, last pushed 4d ago), licensed Apache-2.0. It adds 52 tokens to every session and 10,940 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it B with 1 finding (recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.