# Recipe E — PR description auto-writer

# Recipe E — PR description auto-writer

**Outcome:** A `PR_BODY.md` file populated by passing your branch's `git diff`
through Claude Sonnet with a project-specific system prompt. Plug into
`gh pr create --body-file PR_BODY.md`.

**Approx cost:** ~$0.04 per PR.

## Setup — one-time

Create a project system prompt at `.github/prompts/pr-description.md`:

```markdown
You are writing a pull request description for the visa-mono monorepo.

Structure the output as:

## Summary
- 2-3 bullets describing what the PR does and why.

## What changed
- file: short rationale per file.

## Test plan
- bulleted checklist of how the reviewer should verify.

Match the existing PR style on the repo. Be specific about the why
(non-obvious constraints, past incidents, drift this prevents). Don't
re-explain what the code already says.
```

## Script

```bash
#!/bin/bash
set -euo pipefail

BASE="${1:-main}"

git diff "origin/$BASE...HEAD" \
  | visa-cli run-llm --json --yes - \
      --model or-claude-sonnet \
      --system @.github/prompts/pr-description.md \
      --max-tokens 4000 \
  | jq -r '.text' > PR_BODY.md

echo "Wrote PR_BODY.md ($(wc -l < PR_BODY.md) lines)"
echo "Open the PR with: gh pr create --body-file PR_BODY.md"
```

## Cost breakdown

| Step | Tool | Approx |
|---|---|---|
| Diff → PR body | `or-claude-sonnet` | $0.04 |
| **Total** | | **~$0.04** |

## Variations

- **Lower-cost** — swap `or-claude-sonnet` for `or-claude-haiku` (~$0.005).
- **Self-review** — pipe the PR_BODY through `run-llm` again with a system
  prompt asking it to flag missing test plans, ambiguous wording, or
  missing context.
- **Stacked PRs** — feed `git diff origin/main...HEAD` for the full stack
  vs `git diff origin/PREV_PR...HEAD` for the incremental.
