# A 10-minute pre-merge security check you can hand to your AI coding agent

> Source: <https://dev.to/rhussa02/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent-10ah>
> Published: 2026-11-25 19:09:13+00:00

**Recommendation:** Package pre-merge checks as a SKILL.md that greps the diff, requires the agent to confirm or discard each hit, and forbids printing full secrets.
More in the playbook "Working with AI coding agents": <https://wpnews.pro/playbooks/coding-agents>

Most leaked keys and injection bugs that reach main were not hard to find. Nobody looked. The reviewer read the logic, the tests passed, and the `.env` value pasted into a config file went out with the rest.

Here is a check to run on every diff before it merges. It takes about ten minutes by hand. Further down, I show how to make an AI coding agent run it for you.

Reviewing the whole repo is how checks get skipped. Start from the diff:

```
git diff -U0 origin/main...HEAD
```

`-U0` drops context lines, so every `+` line is new code. That is the code you are responsible for.

Search the added lines for anything that looks like a credential:

```
git diff -U0 origin/main...HEAD | grep -E '^\+' | \
  grep -Ei "(api[_-]?key|secret|token|passw(or)?d)\s*[:=]\s*['\"][A-Za-z0-9_/+=-]{12,}['\"]|AKIA[0-9A-Z]{16}|BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY"
```

If a real secret shows up, deleting it in the next commit is not enough. It is in the history. Rotate it.

Three patterns cover most injection bugs in Python web code:

| Pattern | Example | Fix | 
|---|---|---|
| SQL built from strings | `f"SELECT * FROM users WHERE id = {uid}"` | Parameterized query: `cur.execute("... WHERE id = %s", (uid,))` | 
| Shell with user input | `subprocess.run(cmd, shell=True)` | Pass a list, drop `shell=True` | 
| Unsafe deserialization | `pickle.loads(body)` ,`yaml.load(f)` | `json.loads` ,`yaml.safe_load` | 

A grep finds candidates. It does not find bugs. For each hit, trace where the input comes from. A query built from a constant is fine. A query built from `request.args` is not.

Grep cannot do this one. For every new route or handler in the diff, answer two questions:

The second one is the one that gets missed. `GET /invoices/<id>` that checks login but not ownership lets any user read any invoice.

If the diff touches a `Dockerfile` or `.github/workflows/`, check these:

`:latest`
`USER` before `CMD`
`curl ... | sh`
`permissions:` block that starts at `contents: read`
`${{ github.event.* }}` pasted straight into a `run:` step. Pass it through an env var instead:

```
- run: echo "$TITLE"
  env:
    TITLE: ${{ github.event.issue.title }}
```

List the functions the diff adds or changes, then check whether any test mentions them. A function that parses input, handles money or dates, or touches files and has no test is a FIX, not a SHIP.

Claude Code, Codex CLI, Cursor and most other coding agents now read `SKILL.md` files: a folder with instructions and optional scripts that the agent loads when the task matches. A pre-merge skill looks like this:

```
---
name: premerge-check
description: Run before merging a branch. Checks the diff for secrets,
  injection, missing auth, CI and Docker misconfig, and untested changes,
  then returns BLOCK, FIX, or SHIP with a ranked fix list.
---

1. Run `git diff -U0 origin/main...HEAD`.
2. Run the secret and injection greps on added lines. Treat hits as leads.
3. Read each flagged file and confirm or discard the lead.
4. For each new route, confirm identity and ownership checks.
5. If Dockerfiles or workflows changed, check the CI list.
6. List changed functions with no test.
7. Verdict: BLOCK on any committed secret or exploitable injection,
   FIX on high findings or untested input handling, otherwise SHIP.
8. Never print a full secret. Do not edit files unless asked.
```

Save it as `~/.claude/skills/premerge-check/SKILL.md` (Codex reads `.agents/skills/`). Then ask the agent to "check this branch before I merge" and it follows the steps.

The parts that make this work are rule 3 and rule 8. Without "confirm or discard the lead," agents report every grep hit as a vulnerability. Without "never print a full secret," they paste your key into the chat log.

What do you check before merging that is not on this list?

*This post was written with help from an AI assistant. The commands were tested on a sample repo before posting.*
