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.
# 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.
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.
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.
# 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.
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.
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.
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.
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
Next module:
4.6 — CI/CD and GitHub Actions: Automate Deployments, Tests, and Security.