patch-generator — Claude Code subagent: security fixes as a patch
Turns one security finding into a staged change inside a throwaway clone, ready to be handed over as a patch file.
/plugin install claude-security@claude-plugins-officialWhat patch-generator does
This subagent never edits your working tree. It runs in a scratch clone that the fix job creates, checked out at a chosen patch base — detached, not on a branch. That base can sit ahead of the commit the report was built from, so a recorded line number is a hint at best; the flagged code is found through its snippet and symbol instead.
The change has to address the root cause and stay narrow: only what closing that single finding requires. No drive-by refactors, no dependency bumps. If the honest fix alters observable behaviour, summary must say which behaviour changed. When the code at this revision is no longer exploitable, or the call belongs to the owner, nothing is touched and summary explains why.
Before returning, the agent runs git add -A once inside the workspace so the staged diff covers every changed byte, new files included. Nothing is committed or pushed. An independent verifier inspects the diff and runs the tests, and the patch only leaves the run on a PASS. Dispatch comes from the fix job; there is no manual invocation. The agent installs nothing on its own — no packages, no toolchain — and uses the project's own test command. A suite that will not run in the environment gets reported, not worked around.
What it helps with
- close one security finding without disturbing the rest of the code
- produce a patch for review instead of committing straight to the repo
- find the vulnerable spot by snippet when the line number has drifted
- check whether the finding still reproduces at the current revision
- flag a behaviour change in summary for the verifier
Example prompts for the agent
- Fix the finding in the
FINDINGblock insideWORKSPACEand leave the change staged - Locate the flagged code by snippet and symbol, treat the line number as a hint
- If the finding does not reproduce at this revision, change nothing and explain in
summary
How to install patch-generator
1Plugin marketplace
/plugin install claude-security@claude-plugins-official2Manually: put the files in place
.claude/agents/patch-generator.mdFor all projects use ~/.claude/agents/. Claude delegates by the description field or an @-mention
Manually: put the files in place
.codex/agents/patch-generator.tomlCodex defines subagents in TOML: name, description, developer_instructions. Move the Markdown text into developer_instructions by hand. For all projects use ~/.codex/agents/
Manually: put the files in place
.cursor/agents/patch-generator.mdCursor also reads .claude/agents/
Step by step, with commands for each platform: Claude Code subagents: how to create one, call it and keep context clean
Questions about patch-generator
How do I install patch-generator in Claude Code?
From the marketplace: run /plugin install claude-security@claude-plugins-official, then add the agent file .claude/agents/patch-generator.md.
What does patch-generator do?
It fixes a single security finding inside a scratch clone and leaves the change staged. The fix job then writes that diff out as a patch you read and apply yourself.
Can I invoke it directly?
No, the fix job dispatches it. It refuses to run when the task carries no FINDING block or when WORKSPACE does not look like the clone that was created.