pr-loop-lifecycle
Opens and closes a PR-loop run: the .claude/** permission grant, worktree preflight, and cwd routing at the start; teardown, permission revoke, and final report at the end. Invoked by PR-loop orchestrators (bugteam, pr-converge, autoconverge, qbug); not for general git cleanup outside a PR loop.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 7
- Forks
- 1
01 前言 Front Matter
- name
- pr-loop-lifecycle
- description
- Opens and closes a PR-loop run: the .claude/** permission grant, worktree preflight, and cwd routing at the start; teardown, permission revoke, and final report at the end. Invoked by PR-loop orchestrators (bugteam, pr-converge, autoconverge, qbug); not for general git cleanup outside a PR loop.
02 资源文件 1
03 SKILL.md 正文
PR Loop Lifecycle
Core principle: a PR-loop run opens with an explicit, revocable permission grant and closes the same way every time — teardown, description rewrite, revoke, report — no matter how the run ended.
How callers invoke this
- Skill-capable contexts (a lead session with the
Skilltool):Skill({skill: "pr-loop-lifecycle", args: "--skill <caller> <open|close> [parameters]"}). - Fallback (a subagent or teammate without the
Skilltool): the caller's spawn prompt says "Read~/.claude/skills/pr-loop-lifecycle/SKILL.mdand apply the<open|close>section with the parameters below."
The caller passes its identity (fills the final-report header and scratch-file prefix), whether it runs an agent team (gates the TeamDelete step), and at close time the run's exit reason, loop count, and SHAs.
Open
-
Grant project permissions:
python "$HOME/.claude/_shared/pr-loop/scripts/grant_project_claude_permissions.py"The script writes idempotent allow-rules andadditionalDirectoriesentries into~/.claude/settings.jsonso subagents can edit the project's.claude/tree without prompting.Auto-mode escalation: in an unattended run the permission classifier can block this grant as an unrequested allowlist change. Keep the run alive — surface the exact command to the user through
AskUserQuestionand ask them to approve it or run it themselves with the!prefix. Continue once the grant lands. A user who wants future runs to skip the prompt can add a standing Bash allow-rule for the script in their settings. -
Worktree preflight: confirm the session is isolated (the working directory path includes
.claude/worktrees/) before the first tick or round. Classify the working tree against the PR's repo withpython "$HOME/.claude/skills/_shared/pr-loop/scripts/preflight_worktree.py" --owner <O> --repo <R> --mode <classify|strict>and route per the caller's cwd-routing reference (pr-converge Step 1.5 for the classify route; autoconverge pre-flight for the strict route). Capture the session worktree path before routing away — close-time steps target the session repo.
Close
Run these in order from the lead session on EVERY exit — converged, cap reached, stuck, or error.
- TeamDelete (team callers only). Callers that created an agent team remove it with
TeamDelete; single-agent and workflow callers skip this step. - Worktree teardown:
Tolerates already-removed worktrees and missing directories; removal is Windows-safe perpython "$HOME/.claude/skills/_shared/pr-loop/scripts/teardown_worktrees.py" \ --run-temp-dir "<run_temp_dir>" \ --all-pr-jsons '<json array of {number, owner, repo}>'~/.claude/rules/windows-filesystem-safe.md. - Clean the working tree. Return to the session worktree, remove run-scoped scratch files, and leave
git statusclean of run artifacts. - Update the PR description. Follow
reference/teardown-publish-permissions.md§ Publish the final PR description: capture the cumulative diff and original body, compose it against the description guide, publish viaupdate_pull_request, then remove the scratch files. - Revoke project permissions (always):
python "$HOME/.claude/_shared/pr-loop/scripts/revoke_project_claude_permissions.py"Non-negotiable, including on error exits: leaving the grant in place lets future sessions inherit elevated.claude/**access without an explicit opt-in. Run revoke even when earlier close steps partially failed; log cleanup errors separately. - Final report. Print the caller's report block verbatim — no paraphrase, no extra commentary:
Callers append their own lines (net change, loop log, converged SHAs) per their SKILL.md./<caller> exit: <converged | cap reached | stuck | error> Loops: <loop_count> Starting commit: <starting_sha7> Final commit: <current_HEAD_sha7>
Gotchas
- Revoke runs on the error path too. The single most common lifecycle defect is a run that dies mid-loop and leaves the
.claude/**grant in settings. - Close targets the session repo. A cross-repo run that routed its cwd into the PR's worktree returns to the session worktree before steps 3–5; grant and revoke read the current working directory.
- TeamDelete fires once, at run end. Removing the team between audit-fix iterations is a bug.
Folder map
SKILL.md— this file.reference/teardown-publish-permissions.md— the full close sequence: utility-script homes, teardown, PR-description rewrite brief, revoke, report shape.
04 同仓库更多 Skills
update
Fast-forwards a local repository's main branch to a remote's main after confirming the repo path and source remote through AskUserQuestion. Use when the user says '/update', 'update main', 'fast-forward main', 'sync main from origin', 'pull latest main into <path>', or 'bring main up to date'.
source-command-sr-loop
Converging cleanup loop: repeat /simplify until clean, then repeat /code-review --fix until clean
skill-builder
Skill lifecycle: classify, scaffold, write via the skill-writer-agent, self-audit, compose sub-skills, polish description triggers, enforce deterministic scripts. Triggers: build a skill, new skill workflow, improve this skill, optimize skill description, skill development lifecycle, skill modularity, skill composition, description trigger catalog, deterministic skill scripts.
session-tidy
Audit, clean, and consolidate session logs in the Obsidian vault. Fixes format drift, resolves orphaned next-steps, updates stale statuses, and generates project rollup summaries. Use when session logs feel cluttered or before starting a new project milestone. Triggers on '/session-tidy', 'tidy sessions', 'clean up session logs', 'session audit'.
session-log
Logs a session report as an HTML page, tracks vault context, extracts decisions, and outputs a /rename command. Use for /session-log, 'journal this session', 'log this work', 'session report', 'summarize/log/record this session', 'save session', 'capture session', or 'document what we did'.
run-claude-dev-env
Build, install, run, and test the claude-dev-env installer. Use when asked to run claude-dev-env, install the Claude Code config into ~/.claude, drive the installer, smoke-test it against a sandbox, or run its test suite.