---
name: self-review-before-pr
description: Runs a checklist pass over your own diff before opening a pull request, catching debug leftovers, dead code, secrets, missing tests, poor naming, scope creep and migration or config impact. Use when the user is about to open a PR or says the work is done.
---

# Self-Review Before PR

Read your own diff as if a stranger wrote it. Everything you catch here is a review round trip you save.

## 1. Look at exactly what will be submitted

```bash
git fetch origin
git status --short
git diff origin/main...HEAD --stat
git diff origin/main...HEAD
git diff                      # anything unstaged or forgotten?
git diff --staged              # staged but not committed
git ls-files --others --exclude-standard   # untracked files
```

Read the whole diff top to bottom once without fixing anything, then go through the checklist below and fix.

## 2. Checklist

Leftovers:

- Debug output: `console.log`, `print`, `dbg!`, `debugger`, `TODO`/`FIXME` you added, commented-out code.
- Temporary files, local scripts, logs, `.bak` files, editor settings, build output accidentally tracked.
- Focus and skip markers left in tests (`.only`, `fit`, `.skip`, `xit`, `@pytest.mark.skip`, `t.Skip`).

Secrets and private data:

- API keys, tokens, passwords, private URLs, real emails or phone numbers, internal hostnames in code, tests, fixtures or docs.
- `.env` files or credentials staged. If found, stop and tell the user; the secret must be rotated, not just deleted.

Scope:

- Every changed file is related to the stated goal. Unrelated reformatting, drive-by renames or lockfile churn should be split into a separate commit or PR.
- Diff size is reviewable. If it is huge, propose a split into independent commits or PRs.

Correctness:

- Edge cases handled: empty input, null, large input, errors from network or disk.
- Error paths do something sensible and do not swallow exceptions silently.
- No hardcoded values that belong in config.

Tests:

- New behavior has a test; a bug fix has a test that fails without the fix.
- The test suite, linter, formatter and type checker pass locally. Run them and note the result.
- Tests assert behavior, not only that code runs.

Naming and clarity:

- Names say what things are; no leftover `tmp`, `data2`, `foo`.
- Comments explain why, not what; outdated comments updated or removed.
- Public APIs, docs and README updated if behavior changed.

Impact outside the code:

- Database migrations: reversible, safe on big tables, deploy order considered.
- Config and environment: new env vars documented and added to examples and deployment files.
- Dependencies: every new package is needed and intended; lockfile changes match.
- Backward compatibility: API shape, CLI flags, file formats, events consumed by others.
- Rollout and rollback: can this be deployed safely, and undone?

## 3. Commits and branch

```bash
git log --oneline origin/main..HEAD
```

- Commit messages are clear and follow the repo's convention; no "wip" or "fix fix".
- The branch is based on a recent main (`git merge-base --is-ancestor origin/main HEAD && echo "main included" || echo "behind main"`; the command itself answers only with its exit code). If not, offer to rebase or merge and ask before rewriting shared history.

## 4. Output format

Fix what is safe to fix (leftovers, naming, missing tests the user asked for) and report:

```
Ready to open PR: yes / no
Fixed during self-review: <list>
Needs your decision: <list, e.g. split the PR, rotate a leaked key>
Checks run: <commands and results>
Risks to mention in the PR description: <migration, env var, behavior change>
```

## Pitfalls

- Do not skip the untracked-files check; forgotten new files break CI.
- Do not "clean up" unrelated code while at it; that is the scope creep you are looking for.
- Do not delete files, rewrite history or force-push without asking the user.
- Do not claim tests pass unless you ran them in this session.
- Do not open the PR yourself unless the user asked for it.

Source: [AnyModel skills catalog](https://anymodel.org/en/skills) · License: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
