Merge the PR, remove the worktree, and close the Notion ticket in one command once testing is approved.
After testing passes, closing a ticket still means four separate steps: merge the PR, delete the remote branch, clean up the local worktree, and update the Notion status to Done.
Done in isolation, each step is trivial. But they add up — and skipping cleanup means stale branches and worktrees accumulate silently.
Retrieves the PR for the given branch (defaults to the current worktree's branch). Validates it exists and is not in a conflicting state before proceeding.
Merges the PR with gh pr merge --merge --delete-branch. If already merged, skips this step.
Returns to the main repo if currently inside the worktree, then removes it via wt remove.
Finds the ticket via the URL stored in the PR body, sets its status to Done, and stamps the Done at date — so the ticket history stays accurate without any manual update.
# From inside the worktree (branch auto-detected)
/ticket-done
# Or pass the branch explicitly from anywhere
/ticket-done feat/my-branch---
name: ticket-done
description: Merge the PR, remove the worktree, and set the Notion ticket to "Done". Use when the user runs /ticket-done [branch].
---
# Ticket cleanup
Argument: the branch name (optional — defaults to the branch of the worktree the session is currently in).
## 1. Find the PR
- `gh pr view {branch} --json number,state,mergedAt,url,body,mergeable,reviewDecision`
- If no open or merged PR exists for the branch, report it and STOP.
- Extract the Notion ticket URL from the PR body.
## 2. Merge (if not already merged)
- If `state` is already `MERGED`, skip to step 3.
- If `mergeable` is `CONFLICTING`, report it and STOP — the user must resolve conflicts first.
- Merge: `gh pr merge {number} --merge --delete-branch`
## 3. Leave the worktree
If the session is currently inside that worktree, return to the main repo first (ExitWorktree with action "keep" — removal is done by `wt`, not by ExitWorktree).
## 4. Remove the worktree
- `wt remove {branch}`
## 5. Close the ticket on Notion
- Load Notion MCP tools via ToolSearch (query: "notion") if not already loaded.
- Set the ticket status to **Done** and set `Done at` to today's date (ISO format `YYYY-MM-DD`). Find the ticket via the URL in the PR body, or by searching the tickets database for an entry whose **PR** property matches the PR URL.
- Use `update_properties` with both `{"Status": "Done", "date:Done at:start": "<today>", "date:Done at:is_datetime": 0}`.
## 6. Report
Confirm to the user: PR merged, worktree removed, ticket set to Done.
Looking to bring your web ideas to life?
Reach out to me on Linkedin or Twitter
jeanrobertou.com
Apps