create-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Pull Request

创建拉取请求

Comprehensive PR creation with validation. All output goes directly to GitHub PR.
带有验证机制的全面PR创建流程。所有输出直接同步至GitHub PR。

Quick Start

快速开始

bash
/create-pr

bash
/create-pr

STEP 0: Verify User Intent with AskUserQuestion

步骤0:使用AskUserQuestion确认用户意图

BEFORE creating tasks, clarify PR type:
python
AskUserQuestion(
  questions=[{
    "question": "What type of PR is this?",
    "header": "Type",
    "options": [
      {"label": "Feature (Recommended)", "description": "New functionality with full validation"},
      {"label": "Bug fix", "description": "Fix for existing issue"},
      {"label": "Refactor", "description": "Code improvement, no behavior change"},
      {"label": "Quick", "description": "Skip validation, just create PR"}
    ],
    "multiSelect": false
  }]
)
Based on answer, adjust workflow:
  • Feature: Full validation with all agents
  • Bug fix: Focus on test verification
  • Refactor: Skip new feature validation
  • Quick: Skip all validation, just create PR

在创建任务之前,请明确PR类型:
python
AskUserQuestion(
  questions=[{
    "question": "What type of PR is this?",
    "header": "Type",
    "options": [
      {"label": "Feature (Recommended)", "description": "New functionality with full validation"},
      {"label": "Bug fix", "description": "Fix for existing issue"},
      {"label": "Refactor", "description": "Code improvement, no behavior change"},
      {"label": "Quick", "description": "Skip validation, just create PR"}
    ],
    "multiSelect": false
  }]
)
根据回答调整工作流:
  • Feature(功能新增):使用所有Agent进行完整验证
  • Bug fix(BUG修复):重点进行测试验证
  • Refactor(代码重构):跳过新功能验证
  • Quick(快速创建):跳过所有验证,直接创建PR

⚠️ CRITICAL: Task Management is MANDATORY (CC 2.1.16)

⚠️ 关键要求:任务管理是强制性的(CC 2.1.16)

BEFORE doing ANYTHING else, create tasks to show progress:
python
undefined
在执行任何操作之前,请先创建任务以展示进度:
python
undefined

1. Create main PR task IMMEDIATELY

1. 立即创建主PR任务

TaskCreate( subject="Create PR for {branch}", description="PR creation with parallel validation agents", activeForm="Creating pull request" )
TaskCreate( subject="Create PR for {branch}", description="PR creation with parallel validation agents", activeForm="Creating pull request" )

2. Create subtasks for phases

2. 为各个阶段创建子任务

TaskCreate(subject="Pre-flight checks", activeForm="Running pre-flight checks") TaskCreate(subject="Run parallel validation agents", activeForm="Validating with agents") TaskCreate(subject="Run local tests", activeForm="Running local tests") TaskCreate(subject="Create PR on GitHub", activeForm="Creating GitHub PR")
TaskCreate(subject="Pre-flight checks", activeForm="Running pre-flight checks") TaskCreate(subject="Run parallel validation agents", activeForm="Validating with agents") TaskCreate(subject="Run local tests", activeForm="Running local tests") TaskCreate(subject="Create PR on GitHub", activeForm="Creating GitHub PR")

3. Update status as you progress

3. 随着进度更新状态

TaskUpdate(taskId="2", status="in_progress") # When starting phase TaskUpdate(taskId="2", status="completed") # When phase done

---
TaskUpdate(taskId="2", status="in_progress") # 开始阶段时 TaskUpdate(taskId="2", status="completed") # 阶段完成时

---

Workflow

工作流

Phase 1: Pre-Flight Checks

阶段1:预检检查

bash
undefined
bash
undefined

Verify branch

Verify branch

BRANCH=$(git branch --show-current) if [[ "$BRANCH" == "dev" || "$BRANCH" == "main" ]]; then echo "Cannot create PR from dev/main. Create a feature branch first." exit 1 fi
BRANCH=$(git branch --show-current) if [[ "$BRANCH" == "dev" || "$BRANCH" == "main" ]]; then echo "Cannot create PR from dev/main. Create a feature branch first." exit 1 fi

Check for uncommitted changes

Check for uncommitted changes

if [[ -n $(git status --porcelain) ]]; then echo "Uncommitted changes detected. Commit or stash first." exit 1 fi
if [[ -n $(git status --porcelain) ]]; then echo "Uncommitted changes detected. Commit or stash first." exit 1 fi

Push branch if needed

Push branch if needed

git fetch origin if ! git rev-parse --verify origin/$BRANCH &>/dev/null; then git push -u origin $BRANCH fi
undefined
git fetch origin if ! git rev-parse --verify origin/$BRANCH &>/dev/null; then git push -u origin $BRANCH fi
undefined

Phase 2: Parallel Pre-PR Validation (3 Agents)

阶段2:PR创建前的并行验证(3个Agent)

Launch validation agents in ONE message BEFORE creating PR:
python
undefined
在创建PR前,通过一条消息启动所有验证Agent:
python
undefined

PARALLEL - All 3 in ONE message

PARALLEL - All 3 in ONE message

Task( subagent_type="security-auditor", prompt="""Security audit for PR changes:
  1. Check for secrets/credentials in diff
  2. Dependency vulnerabilities (npm audit/pip-audit)
  3. OWASP Top 10 quick scan Return: {status: PASS/BLOCK, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|BLOCK] - [N] issues: [brief list or 'clean']" """, run_in_background=True, max_turns=25 ) Task( subagent_type="test-generator", prompt="""Test coverage verification:
  1. Run test suite with coverage
  2. Identify untested code in changed files Return: {coverage: N%, passed: N/N, gaps: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [N]% coverage, [passed]/[total] tests - [status]" """, run_in_background=True, max_turns=25 ) Task( subagent_type="code-quality-reviewer", prompt="""Code quality check:
  1. Run linting (ruff/eslint)
  2. Type checking (mypy/tsc)
  3. Check for anti-patterns Return: {lint_errors: N, type_errors: N, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|FAIL] - [N] lint, [M] type errors" """, run_in_background=True, max_turns=25 )

Wait for agents, then run local validation:

```bash
Task( subagent_type="security-auditor", prompt="""Security audit for PR changes:
  1. Check for secrets/credentials in diff
  2. Dependency vulnerabilities (npm audit/pip-audit)
  3. OWASP Top 10 quick scan Return: {status: PASS/BLOCK, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|BLOCK] - [N] issues: [brief list or 'clean']" """, run_in_background=True, max_turns=25 ) Task( subagent_type="test-generator", prompt="""Test coverage verification:
  1. Run test suite with coverage
  2. Identify untested code in changed files Return: {coverage: N%, passed: N/N, gaps: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [N]% coverage, [passed]/[total] tests - [status]" """, run_in_background=True, max_turns=25 ) Task( subagent_type="code-quality-reviewer", prompt="""Code quality check:
  1. Run linting (ruff/eslint)
  2. Type checking (mypy/tsc)
  3. Check for anti-patterns Return: {lint_errors: N, type_errors: N, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|FAIL] - [N] lint, [M] type errors" """, run_in_background=True, max_turns=25 )

等待Agent完成,然后运行本地验证:

```bash

Backend

Backend

cd backend poetry run ruff format --check app/ poetry run ruff check app/ poetry run pytest tests/unit/ -v --tb=short -x
cd backend poetry run ruff format --check app/ poetry run ruff check app/ poetry run pytest tests/unit/ -v --tb=short -x

Frontend

Frontend

cd ../frontend npm run lint && npm run typecheck
undefined
cd ../frontend npm run lint && npm run typecheck
undefined

Phase 3: Gather Context

阶段3:收集上下文信息

bash
BRANCH=$(git branch --show-current)
ISSUE=$(echo $BRANCH | grep -oE '[0-9]+' | head -1)

git log --oneline dev..HEAD
git diff dev...HEAD --stat
bash
BRANCH=$(git branch --show-current)
ISSUE=$(echo $BRANCH | grep -oE '[0-9]+' | head -1)

git log --oneline dev..HEAD
git diff dev...HEAD --stat

Phase 4: Create PR

阶段4:创建PR

bash
TYPE="feat"  # Determine: feat/fix/refactor/docs/test/chore

gh pr create --base dev \
  --title "$TYPE(#$ISSUE): Brief description" \
  --body "## Summary
[1-2 sentence description]
bash
TYPE="feat"  # Determine: feat/fix/refactor/docs/test/chore

gh pr create --base dev \
  --title "$TYPE(#$ISSUE): Brief description" \
  --body "## Summary
[1-2 sentence description]

Changes

Changes

  • [Change 1]
  • [Change 2]
  • [Change 1]
  • [Change 2]

Test Plan

Test Plan

  • Unit tests pass
  • Lint/type checks pass
Closes #$ISSUE

Generated with Claude Code"
undefined
  • Unit tests pass
  • Lint/type checks pass
Closes #$ISSUE

Generated with Claude Code"
undefined

Phase 5: Verify

阶段5:验证

bash
PR_URL=$(gh pr view --json url -q .url)
echo "PR created: $PR_URL"
gh pr view --web
bash
PR_URL=$(gh pr view --json url -q .url)
echo "PR created: $PR_URL"
gh pr view --web

CC 2.1.27+ Enhancements

CC 2.1.27+ 增强功能

Auto PR Linking

自动PR关联

Sessions created via
gh pr create
are now automatically linked to the PR. Use
--from-pr <number|url>
to resume sessions linked to a specific PR:
bash
claude --from-pr 123          # Resume session linked to PR #123
claude --from-pr https://github.com/org/repo/pull/123
This means PR context (diff, comments, review status) is available when resuming.
通过
gh pr create
创建的会话现在会自动关联到对应的PR。使用
--from-pr <number|url>
可以恢复与特定PR关联的会话:
bash
claude --from-pr 123          # Resume session linked to PR #123
claude --from-pr https://github.com/org/repo/pull/123
这意味着恢复会话时可以获取到PR的上下文信息(代码差异、评论、评审状态)。

Task Metrics (CC 2.1.30)

任务指标(CC 2.1.30)

Task tool results now include
token_count
,
tool_uses
, and
duration_ms
. Report validation efficiency:
markdown
undefined
任务工具的结果现在包含
token_count
tool_uses
duration_ms
字段。可以报告验证效率:
markdown
undefined

Pre-PR Validation Metrics

Pre-PR Validation Metrics

AgentTokensToolsDuration
security-auditor5201015s
test-generator380612s
code-quality-reviewer450810s
Total: 1,350 tokens in 37s
undefined
AgentTokensToolsDuration
security-auditor5201015s
test-generator380612s
code-quality-reviewer450810s
Total: 1,350 tokens in 37s
undefined

Session Resume Hints (CC 2.1.31)

会话恢复提示(CC 2.1.31)

At session end, Claude shows resume hints. Before ending PR creation sessions:
bash
undefined
会话结束时,Claude会显示恢复提示。在结束PR创建会话之前:
bash
undefined

Store PR context for future sessions

Store PR context for future sessions

/ork:remember PR #123 created: [brief description], pending review from [team]
undefined
/ork:remember PR #123 created: [brief description], pending review from [team]
undefined

Rules

规则

  1. NO junk files - Don't create files in repo root
  2. Run validation locally - Don't spawn agents for lint/test
  3. All content goes to GitHub - PR body via
    gh pr create --body
  4. Keep it simple - One command to create PR
  1. 禁止生成无用文件 - 不要在仓库根目录创建文件
  2. 本地运行验证 - 不要为lint/测试任务启动Agent
  3. 所有内容同步至GitHub - 通过
    gh pr create --body
    提交PR正文
  4. 保持简洁 - 使用单一命令创建PR

Agent Usage

Agent使用规范

Only use Task agents for:
  • Complex code analysis requiring multiple files
  • Security review of sensitive changes
  • Architecture review for large refactors
仅在以下场景使用Task Agent:
  • 需要分析多个文件的复杂代码分析
  • 敏感变更的安全评审
  • 大型重构的架构评审

Related Skills

相关技能

  • commit: Create commits before PRs
  • review-pr: Review PRs after creation
  • commit: 创建PR前的代码提交
  • review-pr: PR创建后的评审

References

参考资料

  • PR Template
  • PR模板