I want to be able to merge PRs, in threads
Merge PRs from Threads
Plan: add a Pull requests panel on the thread page with a Merge button per PR.
- Server (
lib/merge.ts): export the "latest PR per repo alias" lookup that status sync already uses; addthreadPullRequestStates()(open/merged/closed, GitHub's mergeable state, CI verdict) andmergeThreadPullRequest()→PUT /repos/:o/:r/pulls/:n/mergewith the requester's own GitHub token (so GitHub's repo permissions apply — no merging through the owner's token), pinned to the head sha we inspected; merge method = first of merge → squash → rebase the repo allows. On success: aprogressnote in the thread ("Merged web #12 by @login") and a forced status sync so the badge flips tomerged. - API:
GET /api/threads/[id]/prs(signed-in; PR states) andPOST /api/threads/[id]/merge {alias}(workspace members, 409 while Claude is running). - UI:
components/merge-prs.tsxunder the thread-meta line:alias #nlink · state (open / CI passing / CI failed / conflicts / merged) · two-tap Merge button for members. Panel only renders when the thread has PRs.
No migration needed.
threadide@a2e881eCommitted a2e881e (not pushed yet). Typecheck passes. What's in:
lib/merge.ts:threadPullRequests()is now exported (latest PR per alias, from post meta); newthreadPullRequestStates()(open/merged/closed + GitHubmergeable_state+ CI verdict) andmergeThreadPullRequest()(PUT …/pulls/:n/merge with the requester's token,sha-pinned, merge → squash → rebase per repo settings; progress note + forced status sync afterwards).MergeRefusedcarries an HTTP status so the route answers 403/409 with a reason.GET /api/threads/[id]/prs(any signed-in user) andPOST /api/threads/[id]/merge {alias}(members; 409 while running).components/merge-prs.tsxpanel under the thread-meta line;.pr-panel/button.merge-prCSS.
Now doing a static mockup screenshot of the panel (app can't run in the sandbox), then pushing.
threadide@e9af599Pushed thread/fb855dab (a2e881e + e9af599). You can now merge a thread's PRs from the thread page.
What you'll see: a Pull requests row right under the thread-meta line (only on threads that opened PRs, signed-in users only). Each repo shows its latest PR as a pill link, a state badge, and — for workspace members — a Merge button. Tap once → "Really merge?" (auto-disarms in 4s) → tap again → merged. The row then shows merged, a progress note lands in the thread ("Merged threadide #74 by @osebo (merge, 9f3c1e2)") and the thread badge flips to merged once every PR has landed.
State badges (from GitHub, fetched after the page paints so it never waits on GitHub): CI passing / open (no CI) / CI running / CI failed / conflicts / blocked (branch protection) / draft / merged / closed. Merge is hidden for drafts, conflicts, merged and closed PRs; disabled while Claude is running on the thread.
Who can merge, and as whom — the one real decision here:
- The button needs workspace membership (same gate as asking Claude).
- The merge itself is done with your own GitHub token, never the workspace owner's. So GitHub's repo permissions apply exactly as on github.com; a member without write access gets a clear 403, and someone signed in without a linked GitHub account is told to connect it. I didn't fall back to the owner's token on purpose — that would let any member merge into main under the owner's name. Say the word if you'd rather have that.
- Merge method = the first one the repo allows in the order merge commit → squash → rebase (your history shows merge commits). The call is pinned to the head sha the panel inspected, so a push between look and click is a "changed while you were looking" 409, not a surprise merge.
Files: lib/merge.ts (merge + state readers, MergeRefused), app/api/threads/[id]/merge/route.ts, app/api/threads/[id]/prs/route.ts, components/merge-prs.tsx, app/threads/[id]/page.tsx, app/globals.css. No migration.
Verified: npm run typecheck; panel layout via a static mockup on the real stylesheet (screenshots attached, light 900px + dark 390px). Not verified: a real GitHub merge — the app can't run here. Please try the first one on a PR you don't mind merging (this branch's own PR is a candidate once it's reviewed).
Costs one extra GitHub GET per PR (+2 for CI) per thread-page view by signed-in users; fine at this scale, easy to throttle later if it ever matters.

