PTENES
Skip to content
MODULE 4.5

🤖 Pull Requests and Code Review

Create PRs with gh CLI, use Claude as an automated reviewer, integrate CI checks, and adopt best practices for PRs that merge quickly.

6
Topics
~45
Minutes
4.4
Prerequisite
Practical
Type
Progress:0%0 of 6
1

Create PRs with gh CLI

Claude Code uses the gh (GitHub CLI) to create PRs directly from the terminal. It analyzes the commits, generates a title and description, and opens the PR with a single command. You can ask: "create a PR with these changes" and it does everything.

criar-pr.sh
# Claude gera e executa algo como:
gh pr create \
  --title "feat(auth): add JWT refresh token rotation" \
  --body "## Summary
- Add automatic JWT refresh token rotation
- Implement token blacklist for revoked tokens
- Add tests for token refresh flow

## Test plan
- [ ] Run auth test suite
- [ ] Manual test with expired tokens"

In one sentence: Claude uses gh pr create to open PRs with automatically generated titles and descriptions.

2

Automated review

Claude can act as a code reviewer: it reads the PR diff, identifies logic, security, performance, and style issues, and comments directly. You can ask "review PR #42" and it uses gh api to fetch the changes and post structured comments.

In one sentence: Claude reads a PR's diff and posts review comments via the gh API.

3

CI checks integration

Before merging, Claude checks whether the CI checks passed using gh pr checks. If any failed, it reads the failure log, identifies the problem, and tries to fix it. If it can’t, it reports what it found and suggests the next step.

ci-checks.sh
# Verificar status dos checks
gh pr checks 42

# Ver log de uma check que falhou
gh run view <run-id> --log-failed

In one sentence: Claude checks CI checks and tries to fix failures before the merge.

4

Addressing feedback

When human reviewers leave comments on the PR, you can ask Claude to: "read the comments on PR #42 and make the requested changes". It uses gh api repos/.../pulls/42/comments to read, understand each request, make the changes, and commit with a message referencing the feedback.

In one sentence: Claude reads review comments and automatically implements the requested changes.

5

Squash and rebase

To keep the history clean, use squash merge: all commits from the PR become a single commit on main. Claude can also rebase before merging to avoid merge commits. Configure GitHub to use "Squash and merge" by default, and the history stays linear and readable.

In one sentence: squash merge keeps the history clean with one commit per PR.

6

Best practices

PRs that merge quickly follow a recipe: small (under 400 lines), focused (a single logical change), well documented (clear title + body with context), and with tests passing. Claude naturally follows these rules when you ask it to create PRs.

checklist-pr.txt
PR que faz merge rapido:
[ ] Menos de 400 linhas de diff
[ ] Uma mudanca logica por PR
[ ] Titulo semantico (feat/fix/refactor)
[ ] Body com Summary + Test Plan
[ ] Todos os CI checks passando
[ ] Sem segredos no diff
[ ] Reviewer atribuido

In one sentence: Small, focused, well-described PRs with green tests merge in minutes.

🧾 Module Summary

✓
gh pr create — Automatic PRs with semantic titles and descriptions.
✓
Automated review — Claude as a code reviewer via the gh API.
✓
CI + feedback loop — checks validations and implements requested changes.
✓
Small, focused PRs — the quick-merge recipe.

Next module:

4.6 — CI/CD and GitHub Actions: Automate Deployments, Tests, and Security.