py-harden

py-harden is a command for coding agents from mathisk2095/jko-claude-plugins. It costs 32 tokens per session (478 once invoked), scanned A, original, MIT.

A Python backend code review command that checks code for 22 known anti-patterns, such as database query mistakes, leaked sessions, and unsafe error handling. It reports problems and can apply selected fixes.

In plain words
What is it for?
Use it to inspect a whole Python source folder or a chosen file or directory, review findings by severity, and fix the issues you select.
Why use it?
It helps find recurring code problems systematically instead of relying on manual review. It also checks that files still parse after changes and runs available code-quality tools.

Command

Part of the python-backend plugin — 1 skill, 3 commands shipped together

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 commands/mathisk2095/jko-claude-plugins/py-harden
Clone the repo
git clone --depth 1 https://github.com/mathisk2095/jko-claude-plugins

Or install python-backend, the plugin that ships this one along with the rest of its 1 skill, 3 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for py-harden

README.md
[![agentmods](https://agentmods.dev/badge/commands/mathisk2095/jko-claude-plugins/py-harden.svg)](https://agentmods.dev/commands/mathisk2095/jko-claude-plugins/py-harden)
Your own site
<a href="https://agentmods.dev/commands/mathisk2095/jko-claude-plugins/py-harden"><img src="https://agentmods.dev/badge/commands/mathisk2095/jko-claude-plugins/py-harden.svg" alt="Measured on agentmods" height="20"></a>
Per session 32 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 478 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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.1 $0.00032 $0.00478
Opus 5 $0.00016 $0.00239
Sonnet 5 $0.00006 $0.00096
Haiku 4.5 $0.00003 $0.00048

Measured 5d ago against content hash 72aa55401c60, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

py-harden scanned grade A with 0 findings 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 5d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/python-backend/commands/py-harden.md · 35 lines

What it actually says

Systematically scan the Python backend for anti-patterns and fix every instance found. If $ARGUMENTS is provided, scan that file or directory. Otherwise scan the entire src/ directory.

First: Use the python-backend-expert skill. Read references/anti-patterns.md for the full catalog.

Process

  1. Scan phase (read-only):

    • Read every .py file in scope
    • Check each file against all anti-patterns AP-01 through AP-22
    • Record findings with file, line, pattern ID, and severity
  2. Report phase:

    • Present all findings grouped by severity (blocking first)
    • For each finding, show the problematic code and the proposed fix
    • Ask user which findings to fix (or "all")
  3. Fix phase:

    • Apply fixes in order: blocking -> important -> nit
    • After each fix, verify the file still parses (no syntax errors)
    • Run any available linters/formatters

Priority Order

Fix in this order:

  1. blocking: AP-01 (fat controller), AP-05 (N+1), AP-07 (session leak), AP-08 (expire_on_commit), AP-09 (blocking in async), AP-11 (bare except), AP-12 (mutable default), AP-14 (global state), AP-19 (god class)
  2. important: AP-02 (god module), AP-03 (import spaghetti), AP-06 (naked SQLAlchemy), AP-10 (fire-forget), AP-13 (stringly config), AP-15 (star imports), AP-17 (dict return), AP-22 (exception flow control)
  3. nit: AP-04 (anemic service), AP-16 (missing types), AP-18 (print debug), AP-20 (premature abstraction), AP-21 (boolean params)
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. 5d ago First seen · 35 lines · 32 tokens per session scan A 72aa55401c60

Subscribe to this mod's changes

py-harden is a command published in the GitHub repository mathisk2095/jko-claude-plugins (3 stars, last pushed yesterday), licensed MIT. It adds 32 tokens to every session and 478 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.