Autonomous PR
Create a pull request without user interaction. This is the worktree variant of pr_create.
Rule: no blocking for feedback. Auto-generate PR text from commits and issue.
Precondition: Issue Branch Required
- Run:
git branch --show-current - The branch name must match
<type>/<issue_number>-<summary>(e.g.feature/79-declarative-sync-manifest). See branch-naming.mdc for the full convention. - Extract the
<issue_number>from the branch name.
Workflow Steps
1. Ensure clean state
bash1git status 2git fetch origin
- If there are uncommitted changes, commit them first.
- Push the branch:
git push -u origin HEAD
2. Determine base branch
Detect whether this issue is a sub-issue and resolve the correct merge target:
-
Determine the repo:
gh repo view --json nameWithOwner --jq '.nameWithOwner' -
Check for a parent issue:
bash1gh api repos/{owner}/{repo}/issues/{issue_number}/parent --jq '.number' -
If a parent exists, resolve its linked branch:
bash1gh issue develop --list <parent_number>- Use the parent's branch as
<base_branch>. - If the parent has no linked branch, fall back to
dev.
- Use the parent's branch as
-
If no parent exists, use
devas<base_branch>.
3. Gather context
bash1git log <base_branch>..HEAD --oneline 2git diff <base_branch>...HEAD --stat 3gh issue view <issue_number> --json title,body
- Read the issue title and acceptance criteria.
- Summarize what the commits accomplish.
4. Ensure CHANGELOG is updated
- Check
CHANGELOG.mdfor an entry under## Unreleasedthat covers the changes. - If missing, add the appropriate entry and commit.
5. Generate PR text
- Read the template:
cat .github/pull_request_template.md - Use it as the literal skeleton — keep every heading, every checkbox line, every sub-heading. Strip only the HTML comments (
<!-- ... -->). - Section-by-section mapping:
- Description: Summarize what the PR does from the issue body and commit messages.
- Type of Change: Check the single box matching the branch type / commit types. Check
Breaking changemodifier only if commits contain!. - Changes Made: List changed files with bullet sub-details (from
git diff --statandgit log). - Changelog Entry: Paste the exact
## Unreleaseddiff from CHANGELOG.md. If no changelog update, write "No changelog needed" and explain. - Testing: Check
Tests pass locallyif tests were run. CheckManual testing performedonly if actually done. FillManual Testing Detailsor write "N/A". - Checklist: Check only items that are genuinely true. Leave unchecked items unchecked — do not remove them.
- Additional Notes: Add design links, context, or write "N/A".
- Refs:
Refs: #<issue_number>
- Explicit prohibitions: Do not invent new sections. Do not rename headings. Do not omit sections. Do not remove unchecked boxes.
- Write the body to
.github/pr-draft-<issue_number>.md.
6. Create PR
bash1# Append reviewer if PR_REVIEWER is set in environment 2REVIEWER_ARG="" 3if [ -n "${PR_REVIEWER:-}" ]; then 4 REVIEWER_ARG="--reviewer $PR_REVIEWER" 5fi 6 7gh pr create --base <base_branch> --title "<type>: <description> (#<issue_number>)" \ 8 --body-file .github/pr-draft-<issue_number>.md \ 9 --assignee @me $REVIEWER_ARG
If the WORKTREE_REVIEWER environment variable is set (populated by just worktree-start), add the reviewer:
bash1gh pr create --base <base_branch> --title "<type>: <description> (#<issue_number>)" \ 2 --body-file .github/pr-draft-<issue_number>.md \ 3 --assignee @me \ 4 --reviewer "$WORKTREE_REVIEWER"
The reviewer is the person who launched the worktree (their gh user login), not the agent.
7. Clean up
- Delete the draft file:
rm .github/pr-draft-<issue_number>.md - Report the PR URL.
Delegation
The following steps SHOULD be delegated to reduce token consumption:
- Steps 1-2 (precondition check, ensure clean state, determine base branch): Spawn a Task subagent with
model: "fast"that validates the branch name, runsgit status/git fetch, pushes the branch, checks for a parent issue viagh api, resolves the base branch. Returns: issue number, base branch name, clean state confirmation. - Step 3 (gather context): Spawn a Task subagent with
model: "fast"that executesgit log,git diff,gh issue viewand returns the raw outputs. Returns: commit log, diff stat, issue title/body. - Steps 6-7 (create PR, clean up): Spawn a Task subagent with
model: "fast"that takes the PR title and body file path, executesgh pr create, deletes the draft file, and returns the PR URL.
Steps 4-5 (ensure CHANGELOG updated, generate PR text) should remain in the main agent as they require understanding changes and writing structured content.
Reference: subagent-delegation rule
Important Notes
- Never block for user review of the PR text. Generate the best text from available context.
- Base branch is auto-detected: parent issue's branch for sub-issues,
devotherwise. - The PR title should follow commit message conventions:
type(scope): description (#issue). - NEVER add 'Co-authored-by: Cursor cursoragent@cursor.com' to commit messages.