Finish Task
Run the full closeout flow only when the goal is to land or close work, not when
the task still needs implementation or review fixes.
Invocation
$finish-task [optional task target]
/finish-task [optional task target]
If no target is provided, resolve the current task for this session with
get-task-details.
Reuse Existing Helpers
get-task-details for the current task metadata and status path
save-task-status for status updates before and after closeout
pr-autoreview-loop when the repo has a current-head reviewer/check workflow
gh for GitHub PR and issue operations
git for branch and worktree cleanup
Step 1: Resolve the task and repo surfaces
- Resolve the active task with
get-task-details unless the user already gave
an exact status.md, task folder, repo root, or tracker/PR URL.
- Read the resolved status file and identify every repo involved:
- the code repo or worktree that owns the implementation
- the task-tracking repo (for example
personal_os) when it differs from
the code repo
- task artifact folders such as
context/daily/.../<task-slug>/ that need
to be committed as durable closeout context
- whether each repo uses a dedicated task branch/PR or intentionally works
on its default branch, such as
personal_os tasks done directly on main
- tracker surfaces such as Linear issues, GitHub issues, PRs, and any
downstream linked tasks
- Capture the current local state before touching anything:
git status -sb
git branch --show-current
git worktree list
gh pr status or gh pr view <number> when the repo uses GitHub PRs
Step 2: Gate on closeout readiness
Do not treat finish-task as permission to force-close unfinished work.
If the task still has outstanding implementation, review findings, failing
checks, or missing human approval, stay in the active workflow and explain
what remains.
For PR-bearing tasks, confirm that the current-head reviewer/check sweep is
clean before merging. If the repo already uses pr-autoreview-loop, prefer:
pr-autoreview-loop status --repo "<repo-root>" --pr <number|url>
If there are multiple candidate PRs, multiple repos, dirty uncommitted
changes, or unclear merge strategy, stop and ask the smallest targeted
question needed to disambiguate.
For no-dedicated-branch tasks, do not require or invent a PR. Confirm the
work is on the expected default branch, usually main, and that the relevant
task context folder is included in the intended commit/push set.
For cross-repo tasks coordinated from personal_os, treat uncommitted
context/ task artifacts as part of closeout readiness. Do not close the
external PR or tracker while the corresponding task context folder is still
uncommitted unless the user explicitly chooses a different bookkeeping plan.
When local uncommitted changes exist, classify them before asking what to do:
in-scope closeout changes, unrelated user/workspace changes, or ambiguous.
If in-scope changes are present and the task is otherwise ready to close, the
user prompt must include an option to commit and push the scoped changes, then
continue the tracker closeout. Do not make tracker-only closeout the only
terminal option for a task whose relevant local work is still uncommitted.
Step 3: Ask for explicit confirmation before destructive actions
Get an explicit yes before any action that can delete, close, or merge. Treat
these as separate toggles when the user's request did not already specify them:
- merge the PR or land the branch
- delete the remote branch
- delete local branches or remove worktrees
- move a tracker to
Done or close a GitHub issue
- commit or push task context artifacts to a default branch such as
personal_os/main
- create bookkeeping commits in a task-tracking repo such as
personal_os
- switch a repo checkout from the task branch/worktree back to the updated
default branch when local state is dirty, ambiguous, or contains unmerged
local commits
- close a dedicated zellij session
If the user explicitly asked for a full merge-and-close flow, that counts as
permission for the matching items above, but still surface any ambiguity first.
When uncommitted changes are present, make the confirmation choices reflect the
actual closeout paths. Include options like:
- Commit scoped changes and close/move tracker
- Commit scoped changes and hand off for review
- Tracker-only handoff, leaving local changes uncommitted
- Pause for manual cleanup
Only offer the combined commit-and-close option for changes you can scope
clearly. If unrelated or ambiguous dirty files are mixed in, show the scoped file
set and ask before staging anything.
For post-merge branch cleanup, prefer request_user_input when available if a
checkout has dirty tracked changes, untracked files that may conflict, unmerged
local commits, or multiple plausible default branches. Offer explicit choices to
switch to the updated default branch now, preserve the branch and skip switching,
or pause for manual cleanup. If request_user_input is unavailable, ask the same
approval question concisely in chat.
Step 4: Execute closeout in a safe order
- Update local task state first.
- Refresh the task
status.md
- Record final validation, merge intent, and any residual risk
- Run
save-task-status before external writes so the task record reflects
the pre-merge state
- If the task does not have a dedicated branch and is meant to land on the
current repo's default branch, keep the relevant implementation files and
the task context folder in scoped commits on that same branch.
- For dirty working trees, stage only the files explicitly identified as
in-scope for the closeout. Leave unrelated local changes untouched and
mention them in the final handoff.
- If a task-tracking repo such as
personal_os owns closeout artifacts that
belong in version control, commit and push that bookkeeping deliberately in
the same closeout sequence. For cross-repo work, this is usually a separate
personal_os commit/push alongside the code repo PR merge, not a hidden
addition to the code repo PR.
- Land the code change if applicable.
- Ensure the working tree is intentionally clean
- Merge with the repo's expected strategy or the user's specified strategy
- Prefer
gh pr merge so the PR timeline and branch deletion stay in sync
- Run any repo-specific deploy, release, migration, or dependency follow-up
that the PR or task explicitly requires
- Handle downstream follow-ups.
- Check
blocks, blockedBy, related issues, linked roadmap/docs, and
release trackers
- Leave short heads-up notes only where the closeout changes somebody
else's next step
- Close the tracker surfaces.
- Post a closing note that states what landed, what was validated, where it
merged, and any concrete follow-up still left
- Preserve the GitHub authorship byline on GitHub comments or issue edits
- Move Linear or GitHub trackers to their terminal state only after the
merge or explicit local-only closure is complete
- Clean local state last.
- Switch relevant repo checkouts back to the updated default branch when
safe. Fetch first, switch to the default branch, and fast-forward from the
upstream default branch so the checkout ends on latest
main/default.
- If the switch is blocked by dirty changes, untracked conflicts, unmerged
local commits, multiple worktrees, or any ambiguity, prompt the user to
approve or skip the branch switch instead of guessing.
- Delete merged local branches
- Remove task-specific worktrees only when they are clean and no longer
needed
- Close a dedicated zellij session only if the user asked for it or it
clearly exists just for this finished task
- Re-run
save-task-status if metadata, tracker state, or artifact links
changed during closeout.
Step 5: Final response
Report only the concrete closeout results:
- what merged, landed, or closed
- what tracker notes or downstream heads-ups were posted
- what local cleanup ran
- what concrete next steps remain, if any
Special cases
- No PR exists: still use this flow for local-only or tracker-only closeout;
skip PR merge steps. If the work was intentionally done on the default branch,
verify the scoped commit/push that lands the task, including any relevant
context/ folder, before closing the tracker.
- Multiple repos are involved: treat the code repo and the task-tracking repo
as separate closeout surfaces that must both be handled in the same closeout
sequence; do not assume one PR should contain both.
- Dirty or unrelated changes are present: do not delete branches/worktrees or
auto-close the task until the user explicitly decides how to handle them. If
the dirty changes are in-scope, offer to commit/push the scoped changes and
then close or move the tracker in one confirmed closeout path.
- If the repo has no
gh auth, no tracker auth, or no deterministic way to
inspect PR state, stop after the local status update and ask for the missing
access.
1---2name: finish-task3description: Standardize end-of-task closeout when the user asks to finish, wrap up, merge-and-close, land, or otherwise cleanly close a tracked task or PR, including task-status sync, tracker notes/state changes, downstream heads-up checks, and local branch/worktree cleanup.4---56# Finish Task78Run the full closeout flow only when the goal is to land or close work, not when9the task still needs implementation or review fixes.1011## Invocation1213```text14$finish-task [optional task target]15/finish-task [optional task target]16```1718If no target is provided, resolve the current task for this session with19`get-task-details`.2021## Reuse Existing Helpers2223- `get-task-details` for the current task metadata and status path24- `save-task-status` for status updates before and after closeout25- `pr-autoreview-loop` when the repo has a current-head reviewer/check workflow26- `gh` for GitHub PR and issue operations27- `git` for branch and worktree cleanup2829## Step 1: Resolve the task and repo surfaces30311. Resolve the active task with `get-task-details` unless the user already gave32 an exact `status.md`, task folder, repo root, or tracker/PR URL.332. Read the resolved status file and identify every repo involved:34 - the code repo or worktree that owns the implementation35 - the task-tracking repo (for example `personal_os`) when it differs from36 the code repo37 - task artifact folders such as `context/daily/.../<task-slug>/` that need38 to be committed as durable closeout context39 - whether each repo uses a dedicated task branch/PR or intentionally works40 on its default branch, such as `personal_os` tasks done directly on `main`41 - tracker surfaces such as Linear issues, GitHub issues, PRs, and any42 downstream linked tasks433. Capture the current local state before touching anything:44 - `git status -sb`45 - `git branch --show-current`46 - `git worktree list`47 - `gh pr status` or `gh pr view <number>` when the repo uses GitHub PRs4849## Step 2: Gate on closeout readiness5051Do not treat `finish-task` as permission to force-close unfinished work.5253- If the task still has outstanding implementation, review findings, failing54 checks, or missing human approval, stay in the active workflow and explain55 what remains.56- For PR-bearing tasks, confirm that the current-head reviewer/check sweep is57 clean before merging. If the repo already uses `pr-autoreview-loop`, prefer:5859 ```bash60 pr-autoreview-loop status --repo "<repo-root>" --pr <number|url>61 ```6263- If there are multiple candidate PRs, multiple repos, dirty uncommitted64 changes, or unclear merge strategy, stop and ask the smallest targeted65 question needed to disambiguate.66- For no-dedicated-branch tasks, do not require or invent a PR. Confirm the67 work is on the expected default branch, usually `main`, and that the relevant68 task context folder is included in the intended commit/push set.69- For cross-repo tasks coordinated from `personal_os`, treat uncommitted70 `context/` task artifacts as part of closeout readiness. Do not close the71 external PR or tracker while the corresponding task context folder is still72 uncommitted unless the user explicitly chooses a different bookkeeping plan.73- When local uncommitted changes exist, classify them before asking what to do:74 in-scope closeout changes, unrelated user/workspace changes, or ambiguous.75 If in-scope changes are present and the task is otherwise ready to close, the76 user prompt must include an option to commit and push the scoped changes, then77 continue the tracker closeout. Do not make tracker-only closeout the only78 terminal option for a task whose relevant local work is still uncommitted.7980## Step 3: Ask for explicit confirmation before destructive actions8182Get an explicit yes before any action that can delete, close, or merge. Treat83these as separate toggles when the user's request did not already specify them:8485- merge the PR or land the branch86- delete the remote branch87- delete local branches or remove worktrees88- move a tracker to `Done` or close a GitHub issue89- commit or push task context artifacts to a default branch such as90 `personal_os/main`91- create bookkeeping commits in a task-tracking repo such as `personal_os`92- switch a repo checkout from the task branch/worktree back to the updated93 default branch when local state is dirty, ambiguous, or contains unmerged94 local commits95- close a dedicated zellij session9697If the user explicitly asked for a full merge-and-close flow, that counts as98permission for the matching items above, but still surface any ambiguity first.99100When uncommitted changes are present, make the confirmation choices reflect the101actual closeout paths. Include options like:102103- Commit scoped changes and close/move tracker104- Commit scoped changes and hand off for review105- Tracker-only handoff, leaving local changes uncommitted106- Pause for manual cleanup107108Only offer the combined commit-and-close option for changes you can scope109clearly. If unrelated or ambiguous dirty files are mixed in, show the scoped file110set and ask before staging anything.111112For post-merge branch cleanup, prefer `request_user_input` when available if a113checkout has dirty tracked changes, untracked files that may conflict, unmerged114local commits, or multiple plausible default branches. Offer explicit choices to115switch to the updated default branch now, preserve the branch and skip switching,116or pause for manual cleanup. If `request_user_input` is unavailable, ask the same117approval question concisely in chat.118119## Step 4: Execute closeout in a safe order1201211. Update local task state first.122 - Refresh the task `status.md`123 - Record final validation, merge intent, and any residual risk124 - Run `save-task-status` before external writes so the task record reflects125 the pre-merge state126 - If the task does not have a dedicated branch and is meant to land on the127 current repo's default branch, keep the relevant implementation files and128 the task context folder in scoped commits on that same branch.129 - For dirty working trees, stage only the files explicitly identified as130 in-scope for the closeout. Leave unrelated local changes untouched and131 mention them in the final handoff.132 - If a task-tracking repo such as `personal_os` owns closeout artifacts that133 belong in version control, commit and push that bookkeeping deliberately in134 the same closeout sequence. For cross-repo work, this is usually a separate135 `personal_os` commit/push alongside the code repo PR merge, not a hidden136 addition to the code repo PR.1372. Land the code change if applicable.138 - Ensure the working tree is intentionally clean139 - Merge with the repo's expected strategy or the user's specified strategy140 - Prefer `gh pr merge` so the PR timeline and branch deletion stay in sync141 - Run any repo-specific deploy, release, migration, or dependency follow-up142 that the PR or task explicitly requires1433. Handle downstream follow-ups.144 - Check `blocks`, `blockedBy`, related issues, linked roadmap/docs, and145 release trackers146 - Leave short heads-up notes only where the closeout changes somebody147 else's next step1484. Close the tracker surfaces.149 - Post a closing note that states what landed, what was validated, where it150 merged, and any concrete follow-up still left151 - Preserve the GitHub authorship byline on GitHub comments or issue edits152 - Move Linear or GitHub trackers to their terminal state only after the153 merge or explicit local-only closure is complete1545. Clean local state last.155 - Switch relevant repo checkouts back to the updated default branch when156 safe. Fetch first, switch to the default branch, and fast-forward from the157 upstream default branch so the checkout ends on latest `main`/default.158 - If the switch is blocked by dirty changes, untracked conflicts, unmerged159 local commits, multiple worktrees, or any ambiguity, prompt the user to160 approve or skip the branch switch instead of guessing.161 - Delete merged local branches162 - Remove task-specific worktrees only when they are clean and no longer163 needed164 - Close a dedicated zellij session only if the user asked for it or it165 clearly exists just for this finished task1666. Re-run `save-task-status` if metadata, tracker state, or artifact links167 changed during closeout.168169## Step 5: Final response170171Report only the concrete closeout results:172173- what merged, landed, or closed174- what tracker notes or downstream heads-ups were posted175- what local cleanup ran176- what concrete next steps remain, if any177178## Special cases179180- No PR exists: still use this flow for local-only or tracker-only closeout;181 skip PR merge steps. If the work was intentionally done on the default branch,182 verify the scoped commit/push that lands the task, including any relevant183 `context/` folder, before closing the tracker.184- Multiple repos are involved: treat the code repo and the task-tracking repo185 as separate closeout surfaces that must both be handled in the same closeout186 sequence; do not assume one PR should contain both.187- Dirty or unrelated changes are present: do not delete branches/worktrees or188 auto-close the task until the user explicitly decides how to handle them. If189 the dirty changes are in-scope, offer to commit/push the scoped changes and190 then close or move the tracker in one confirmed closeout path.191- If the repo has no `gh` auth, no tracker auth, or no deterministic way to192 inspect PR state, stop after the local status update and ask for the missing193 access.