PostToolUse

A post-edit hook that runs a shell check after Python files are written or edited. When Ruff is installed, it formats those files automatically.

In plain words
What is it for?
Keeping edited Python files in Ruff's format automatically after Write or Edit operations.
Why use it?
It removes the need to format Python files manually after each change. It only acts when the file is Python code and Ruff is available.

Hook

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 hooks/deeleeramone/pywry/post-tool-use
Clone the repo
git clone --depth 1 https://github.com/deeleeramone/PyWry
Per session not measured What this adds to a session before it is invoked.
When invoked not measured Not applicable: nothing here is loaded into a session.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Security

Grade A, and why

PostToolUse scanned grade A 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 commands this hook runs, not an audit. A hook is shell that executes on your machine at the event it names, which is why every command in it is printed with what was found.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

"command": "python -c \"import json,sys,subprocess,shutil; d=json.load(sys.stdin); p=d.get('tool_input',{}).get('file_path',''); ruff=shutil.which('ruff'); sys.exit(0) if not (p.endswith('.py') and ruff) else subprocess.
claude/plugins/pywry/hooks/hooks.json · 14 lines

What it actually says

{
  "PostToolUse": [
    {
      "matcher": "Write|Edit",
      "hooks": [
        {
          "type": "command",
          "command": "python -c \"import json,sys,subprocess,shutil; d=json.load(sys.stdin); p=d.get('tool_input',{}).get('file_path',''); ruff=shutil.which('ruff'); sys.exit(0) if not (p.endswith('.py') and ruff) else subprocess.call([ruff,'format','--quiet',p])\"",
          "timeout": 15
        }
      ]
    }
  ]
}
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 · 14 lines scan A 8f6811b44659

Subscribe to this mod's changes

PostToolUse is a hook published in the GitHub repository deeleeramone/PyWry (93 stars, last pushed 8d ago), licensed Apache-2.0. Its token cost is not measured: a hook is shell that never enters the context. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.