Automating PR Title and Description Updates in Claude Code with Custom Slash Commands
Introduction
Claude Code excels at creating well-structured PR titles and descriptions when initially generating pull requests. However, real-world development workflows often present a unique challenge that many developers face daily.
The Problem
When working with Draft PRs, we often accumulate changes over time. By the time we’re ready to open the PR for review, the content has evolved significantly from its initial state. The original title and description no longer accurately represent the full scope of changes.
Previously, I found myself repeatedly asking Claude Code to “Update PR title and description” to refresh these fields. This manual approach of instructing Claude Code had two major drawbacks:
- Repetitive manual work — Writing the same instruction to Claude Code repeatedly becomes tedious
- Context limitations — Claude Code would often focus only on the most recent changes, missing the bigger picture
Example
Consider this scenario: You’ve just renamed a variable as part of cleanup. If you ask for a PR update at this moment, you might get “Rename xxx variable” as your PR title. However, this rename was actually a minor adjustment to a variable that was introduced as part of a larger feature implementation. The resulting title completely misrepresents the PR’s actual purpose.
The Solution: A Custom Slash Command
To solve this problem, I created a custom slash command that analyzes the entire PR diff and generates appropriate titles and descriptions based on the complete set of changes.
Implementation
Here’s the slash command definition:
# Update PR title and description
## ARGUMENTS
<pr number>
## Usage
/pr-update 123
## Instruction
1. Use `git diff` command to check the changed files and changes of the PR.
2. Update the PR title and description based on the changes obtained in the step 1.
## Rules
1. PR title should follow conventional commitsHow It Works
Basic Usage
- Continue working on your Draft PR with multiple iterations
- Before marking the PR as ready for review, simply run:
/pr-update 123
(where 123 is your PR number)
Behind the Scenes
The command follows this workflow:
- Analyze the complete diff — Uses
git diffto capture all changes in the PR - Understand the context — Analyzes the full scope of modifications to identify the core purpose
- Generate updated content — Creates a title following Conventional Commits and a comprehensive description
Key Benefits
1. Consistent PR Titles
By enforcing Conventional Commits format, your project maintains a uniform commit message convention across all contributions.
2. Comprehensive Change Representation
Since the command analyzes the entire PR diff, it captures the true essence of your changes rather than focusing on recent modifications.
3. Time Efficiency
Transform a repetitive manual task into a single command, streamlining your PR preparation workflow.
Customization Options
This slash command can be tailored to your team’s specific needs:
- Commit conventions — Adjust the Rules section if your project uses custom commit message formats
- Additional requirements — Add specific formatting requirements or mandatory information to the Instruction section
- Template customization — Include project-specific templates or sections that should appear in every PR description
Conclusion
By leveraging Claude Code’s slash command functionality, we can automate the tedious task of keeping PR titles and descriptions up-to-date. This simple automation ensures that our PRs always accurately represent their contents, regardless of how many iterations they’ve gone through.
If you’re using a Draft PR workflow in your development process, give this slash command a try. Feel free to customize it to match your team’s conventions and requirements. Small automations like these can significantly improve your development workflow and reduce cognitive overhead.