Create Pr
Create a pull request with a context-rich summary derived from code changes and conversation context
Step 1 — Determine PR mode
Analyze the context above and present the user with the appropriate options using AskUserQuestion:
-
If there are uncommitted changes AND the branch has no commits ahead of main, offer:
- "New branch with uncommitted changes" — stash changes, update main, create a new branch, apply stash, commit, and PR
- "Commit to current branch and PR" — commit changes on the current branch and PR from there
-
If the current branch has commits ahead of main (with or without uncommitted changes), offer:
- "PR from current branch" — create PR from the current branch's commits (optionally committing any uncommitted changes first)
- "New branch with uncommitted changes only" — only if there are also uncommitted changes: isolate them onto a new branch
-
If on main with no changes, tell the user there's nothing to PR and stop.
Always confirm the chosen mode before proceeding with any git operations.
If $ARGUMENTS contains commit instructions (e.g. "use the last 3 commits", "cherry-pick abc123"), follow those instructions instead of the default mode selection.
Step 2 — Execute git operations (with confirmation)
For "New branch with uncommitted changes" mode:
- Propose a branch name based on the nature of the changes. Use
AskUserQuestionto confirm the name. - Stash uncommitted changes.
- Fetch and fast-forward local main:
git fetch origin main && git checkout main && git merge origin/main --ff-only - Create the new branch from main:
git checkout -b <branch-name> - Pop the stash:
git stash pop - Stage and commit the changes with a descriptive commit message.
For "PR from current branch" mode:
- If there are uncommitted changes, stage and commit them first.
- Ensure the branch is pushed to origin.
For "New branch with uncommitted changes only" mode:
- Propose a branch name based on the uncommitted changes. Use
AskUserQuestionto confirm. - Stash uncommitted changes.
- Create a new branch from main:
git fetch origin main && git checkout -b <branch-name> origin/main - Pop the stash:
git stash pop - Stage and commit the changes with a descriptive commit message.
Step 3 — Gather context for PR summary
The goal is to understand why these changes were made, what problem they solve, and what alternatives were considered — enough for a reviewer to understand the reasoning.
Primary sources, in order:
-
Current conversation. If the work was discussed, planned, and executed here, this is often sufficient on its own.
-
Past conversations. When the current conversation lacks context (e.g., multi-session work, or you were invoked fresh with just "create a PR"), search past conversations via an Explore subagent. Conversations are JSONL files at
~/.claude/projects/[encoded-path]/where the encoded path is the working directory with/replaced by-, prefixed with-. The subagent should grep for keywords from the diff and extract motivation, decisions, and trade-offs. -
Linear tickets. If a ticket ID appears anywhere in the context (commit messages, branch name, conversation,
$ARGUMENTS), invoke the/linearskill to fetch the ticket. Also fetch related tickets (parent, blocking/blocked-by) if they exist — these often contain the broader motivation. Always do this when a ticket is referenced; don't skip it even if the conversation seems to have enough context, since the ticket may have details that weren't discussed.
Step 4 — Compose PR summary
Combine insights from:
- The code diff (what changed)
- The conversation context (why it changed)
$ARGUMENTS(any additional context the user provided)
Draft the PR using this structure:
## Summary
[1-3 paragraphs: what changed and WHY — lead with the motivation/problem, then describe the solution. Use the conversation research to explain the reasoning that led to these changes.
Weave Linear ticket links naturally into the summary text where they provide context — e.g., "This resolves [ENG-123](linear-url) by..." or "As discussed in [ENG-456](linear-url), the approach...". Include links for all relevant tickets (the primary ticket, parent epics, related/blocking issues). Don't dump them in a separate list — they should read as part of the narrative.]
### Ticket
[If the PR addresses a single primary ticket, include a standalone link here — e.g., "Resolves [ENG-123](linear-url)". Omit this section if there is no clear primary ticket.]
### Changes
[Bulleted list of specific changes — group by logical area, not by file]
## Test plan
[Bulleted checklist of how to verify the changes work]
Step 5 — Confirm with user
Present the full PR title and summary as a regular chat message (not AskUserQuestion, to avoid truncation) and ask the user to confirm or request changes.
Step 6 — Create PR
Once confirmed:
- Push the branch if not already pushed:
git push -u origin <branch-name> - Create the PR:
gh pr create --title "<title>" --body "<body>" --base main - Return the PR URL.
Step 7 — Post to Slack
Load the slack skill using the Skill tool, then follow its pr_announcement_flow to compose and send the PR announcement to #engineering-pr.
- If MISSING_TOKEN or AUTH_FAILED: Skip this step silently — Slack is not configured.
- If CHANNEL_NOT_FOUND: Use
AskUserQuestionto ask the user which channel to post in.
<success_criteria>
- No git operations (mode selection, branch creation, commit, push) executed without user confirmation
- Branch name confirmed via AskUserQuestion when creating a new branch
- PR context sourced from current conversation, past conversations, and/or Linear tickets as appropriate
- Linear ticket fetched via
/linearskill whenever a ticket ID appears in context — including related tickets - PR summary presented as regular chat message for user review before creation
- PR created with descriptive summary combining diff analysis and conversation reasoning
- PR URL returned to user
- Slack notification sent to
#engineering-prafter user confirms the message draft (skipped silently if Slack not configured) </success_criteria>