AI CLI
AI-Assisted Coding & Code Review — ship with an AI pair
Work with an AI pair the way you would a sharp junior: feed it the real context, demand a reviewable diff, prompt test-first, turn it loose on your own code as a bug/security reviewer, and never merge what you have not run and read.
Quick reference — reach for these first
paste the file + exact error + constraintsThe model only knows what is in the prompt. Include the relevant code, the real stack trace, and the hard rules (runtime, deps, style) — not a paraphrase."return a unified diff / patch, no explanation"A patch is reviewable and applyable. Prose forces you to re-transcribe and hides exactly what changed. Constrain the output shape up front."write a failing test for X, then the fix"A concrete failing test pins the spec, gives the model a target, and gives you a pass/fail oracle instead of a vibe check."find correctness, edge-case & security bugs, ranked by severity"Point it at bugs, not bikeshedding. Style is cheap; a missed null, a race, an injection is what a review is for.run the tests + read every changed lineModels hallucinate APIs and are confidently wrong. Treat output as a draft from a stranger: execute it and read it before it touches main.The AI pair-coding loop
Text equivalent: A left-to-right loop with five stages: Context (the file, the exact error, constraints), Prompt (ask for a diff or patch, test-first, small scope), AI draft (a unified diff), Verify (run the tests and read every line), and Commit (small, single-purpose). An arrow labeled 'fails: feed the failing test back' loops from Verify back to Context. Verify is drawn as the accented gate, and Commit is labeled as the only step that changes the repo.
Common tasks
Prompt · Review · Verify
| Prompt | Review | Verify |
|---|---|---|
| Gather the exact context before prompting | collect: failing file, full error text, constraints (lang/version, deps, perf/security rules) | you can paste a self-contained problem a stranger could act on |
| State the output format explicitly | "Reply with a unified diff only. No prose. Keep the change under ~40 lines." | response is a patch you can read top-to-bottom, not an essay |
| Prompt test-first for any non-trivial change | "Write a failing test that reproduces BUG, then the minimal fix." | test fails before the fix and passes after |
| Constrain scope to keep the diff reviewable | "Change only FUNCTION in FILE. Do not refactor unrelated code." | git diff touches only the files/lines you intended |
| Redact secrets before pasting code | replace API_KEY / DB_URL / tokens with CAPS placeholders | grep the prompt for 'sk-', 'password', '.env' values → none present |
| Run an AI code review on your own diff | paste `git diff`, ask for correctness + edge-case + security issues ranked by severity | you get a ranked list with file:line references, not generic advice |
| Feed the failing test when a review misses the bug | "This test still fails: TEST_OUTPUT. Re-review the diff against it." | the model's next finding explains the actual failure |
| Ask for reasoning when output looks confidently wrong | "Explain why this is correct and name the API you used + its source." | reasoning is checkable and the named API exists in the docs |
| Verify every invented API against official docs | search the library's official reference for each new symbol | each function/flag the model used appears in the docs with that signature |
| Run it locally before trusting it | apply the patch, run the unit tests and the lint/typecheck gate | green gates; you read every changed line and understand it |
| Keep each AI change a small, single-purpose commit | stage only the intended hunks; conventional-commit message | one logical change per commit, reviewable in under a minute |
| Sanity-check for false positives on a clean baseline | run the review prompt on an unchanged / known-good diff | reviewer reports few or no issues — high noise means a weaker prompt |
Run an AI code review that catches a planted bug
Review
You are reviewing a pull request diff. Find CORRECTNESS, EDGE-CASE, and SECURITY bugs only — skip style. For each issue output: severity (critical|high|medium), file:line, the bug in one sentence, and a minimal fix. Rank critical first. If you find nothing, say "no issues found". DIFF: <PASTE_DIFF_HERE>
# control run: paste a known-good diff → expect "no issues found"
Troubleshooting — symptom → first check → next check
| Symptom | First check | Establishes | Next check |
|---|---|---|---|
| AI invents an API / flag / method that does not exist | search the library's official docs for the exact symbol, then run the code | whether the symbol is real or a hallucination | reject it, paste the real API reference into the prompt, and ask it to redo the patch against that signature |
| Output is confidently wrong — plausible but incorrect logic | ask "explain your reasoning step by step and add a test that proves it" | whether the model can justify the change or just asserted it | require a failing-then-passing test; if the reasoning does not hold, discard and re-scope the prompt |
| Huge, unreviewable diff touching many files | look at `git diff --stat` — count files and lines changed | the change exceeded the scope you can actually review | revert, re-prompt with "change only FUNCTION in FILE, nothing else", split into small commits |
| You pasted code that contains secrets into the prompt | grep the prompt/history for keys, tokens, .env values, connection strings | whether credentials left your machine | treat the exposed secret as compromised and rotate it; redact with CAPS placeholders before any future paste |
| The review misses the real bug you are chasing | re-run the failing test and capture its exact output | the reviewer lacked the concrete failure signal | paste the failing test + output and ask it to review the diff specifically against that failure |
| Reviewer floods you with style nits, not real defects | re-read your prompt — did it ask for "issues" or specifically "correctness, edge-case, security bugs ranked by severity"? | the prompt invited low-value feedback | tighten the ask to severity-ranked correctness/security findings and tell it to skip formatting |
| Tests pass but behavior is still wrong in production | read the test — does it assert the real contract or just that the code ran? | the oracle was too weak to catch the defect | strengthen assertions on edge cases (empty, null, boundary, concurrency) and re-run |
| Everything looks fine and the review found nothing | run the same prompt on a deliberately buggy diff as a control | whether the reviewer actually detects planted bugs or just rubber-stamps | if it misses the planted bug, strengthen the prompt (give context, examples, severity rubric) before trusting a clean verdict |
References
- Claude Code — overview & workflowsdocs.claude.com
- Anthropic — prompt engineering guidedocs.claude.com
- Anthropic — models overview (Opus / Sonnet)docs.claude.com
- GitHub Copilot — code reviewdocs.github.com
- GitHub Copilot — prompt engineering tipsdocs.github.com
Renderer-agnostic data object; hrefs point at official Anthropic and GitHub docs. Verification is docs-checked (content verified against official documentation, not sandbox-executed). Model names kept generic (latest Claude Opus 4.x / Sonnet) per the brief.