DEV Community

Vikas Sah
Vikas Sah

Posted on

Use git diff + Claude to Auto-Generate PR Descriptions in One Bash Alias

I used to spend five minutes writing PR descriptions. Now it takes five seconds. One bash alias pipes your diff and commit log into Claude CLI, and you get a formatted description back on stdout.

The Alias

Add this to your ~/.zshrc or ~/.bashrc:

alias prdesc='(echo "## Commits"; git log main..HEAD --oneline; echo "## Files changed"; git diff main..HEAD --stat; echo "## Diff"; git diff main..HEAD) | claude -p "Generate a concise PR description from this git diff. Use this format:

## Summary
One paragraph explaining what changed and why.

## Changes
- Bullet list of key changes (group by theme, not by file)

## Testing
- How to verify these changes work

Keep it under 200 words. No preamble. Start with the ## Summary heading."'
Enter fullscreen mode Exit fullscreen mode

Reload your shell:

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Usage

Make your changes, commit to a branch, then:

prdesc
Enter fullscreen mode Exit fullscreen mode

That's it. Claude reads your commits, file stats, and full diff, then spits out a ready-to-paste PR description.

Sample Output

For a branch with three commits touching auth middleware:

## Summary
Adds rate limiting to the authentication middleware. Requests exceeding
50 per minute per API key now receive a 429 response with a Retry-After
header. Includes Redis-backed sliding window counter and integration tests.

## Changes
- Add `RateLimiter` class with Redis sliding window algorithm
- Wire rate limiter into auth middleware pipeline
- Return 429 with Retry-After header on limit breach
- Add integration tests covering burst and sustained traffic patterns
- Update API docs with rate limit response schema

## Testing
- Run `pytest tests/test_rate_limiter.py` for unit tests
- Run `pytest tests/integration/test_auth_flow.py` for end-to-end
- Hit `/api/health` 51 times rapidly and verify 429 response
Enter fullscreen mode Exit fullscreen mode

Copy It Straight to gh

Pipe it into your PR creation command:

prdesc | gh pr create --title "Add rate limiting to auth middleware" --body-file -
Enter fullscreen mode Exit fullscreen mode

Or copy to clipboard for the GitHub web UI:

prdesc | pbcopy  # macOS
prdesc | xclip -selection clipboard  # Linux
Enter fullscreen mode Exit fullscreen mode

Why It Works

Claude's -p flag runs in headless mode — it reads stdin, processes the prompt, and prints the result to stdout. No interactive session, no TUI. That makes it composable with any Unix pipeline.

By feeding it three layers of context — commit messages (the why), file stats (the scope), and the full diff (the what) — you give the model enough signal to write a description that actually matches the change. Commit messages alone miss detail. Raw diffs alone miss intent. Both together hit the sweet spot.

Gotchas:

  • If your default branch is master, swap main for master in the alias. Or use git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' to detect it automatically.
  • If your diff is huge (7,000+ characters), the stdin pipe can hit limits in some Claude CLI versions. For large PRs, drop git diff main..HEAD and keep only --stat — you'll lose line-level detail but the summary stays accurate. Or split the PR. Which you probably should anyway.

Top comments (0)