The current branch's GitHub PR as a bar above the prompt or a panel, with one-press commit, review and CI actions

A Claude Code mod that shows the GitHub pull request for the session's current git branch in a bar above the prompt box, with its actions as buttons under it.
PR #128 · draft ✗ 1 failed 2 unresolved changes requested feat(app): let pull…
[ Check feedback ] [ Fix CI ]
> _
The bar is a full-width grey row; the PR state and CI result are coloured pills on it: draft grey, open green, merged purple, closed red; CI green, amber while pending, red on a failure. The title links to the PR and is cut to fit the row.
At the prompt of a Claude Code terminal session:
/plugin install pr-bar --marketplace gugahoi/claude-mods
Answer y to add the marketplace, then pick a scope.
Needs the GitHub CLI installed and signed in (gh auth login).
✓ passed, ✗ N failed, … N pending), the review decision, and how many review threads are unresolved.master/main, or when gh is missing or failing.The buttons show only when they apply, and each submits a prompt:
| Button | When | Prompt |
|---|---|---|
Commit + draft PR (c) | no PR yet | Commit the changes, push, and open a draft PR |
Check feedback (f) | open PR with unresolved threads | I've received feedback on PR #n. Check each unresolved review comment: is it correct and do we need to fix it? |
Commit + resolve (r) | after the Check feedback turn ends, while threads are unresolved | Commit the changes and push, then reply to and resolve each review thread on PR #n we've addressed. |
Fix CI (x) | open PR with a failed check | CI is failing on PR #n. Find out why and fix it. |
Click a button, or focus the band (ctrl+x tab) and press its letter: c, f, r or x. The bar steps aside while a survey uses the band.
/pr/pr opens the same PR in a panel, docked beside the transcript in fullscreen or above the prompt otherwise, with room for the detail the bar leaves out:
PR #128 · draft ✗ 1 failed 2 unresolved
feat(app): let pull to refresh start on the home screen on iOS and Android
feat/pull-to-refresh · changes requested
Checks
✗ App / test
… App / deploy
✓ 14 passed
Unresolved threads (2)
src/feed/useVideoPreloader.ts:134 @reviewer
Should this guard against a missing ref?
[ Check feedback ] [ Fix CI ]
Every check and thread is a link to it on GitHub. The buttons are the bar's. /pr opens the panel with the keyboard, so c, f, r and x press them at once (unless you have text in the prompt); Esc hands the keyboard back to the prompt, ctrl+x tab returns to the panel, and ctrl+x x closes it.
The layout setting picks where the PR shows:
bar (default): the bar above the prompt. /pr opens the panel when you want the detail.panel: no bar. The panel opens by itself when a session starts on a branch with something to show, and /pr reopens it after you close it.Change it in /config (the pr-bar Layout row); the mod reloads with the new layout. /plugin install also asks for it.
It runs git rev-parse, gh pr view --json ... and one gh api graphql query for the review threads when the session starts, after each turn (Claude may have pushed or switched branch), and every 60 seconds so CI results arrive while the session is idle. One fetch runs at a time.
claude plugin validate .
claude plugin test .
claude --plugin-dir .hooks/register.tsx 313 lines1import { atom, read, update } from 'claude-code'
2import type { ElementTable, EngineInterface, Register } from 'claude-code'
3
4import type { PrBarCheck, PrBarChecks, PrBarPr, PrBarSnapshot, PrBarThread } from '../types'
5
6const snapshot = atom({ plugin: 'pr-bar', key: 'snapshot' } as const, null)
7// The PR whose feedback Claude has checked: its threads can now be committed and resolved.
8const feedbackChecked = atom({ plugin: 'pr-bar', key: 'feedbackChecked' } as const, null)
9const PANE = 'pr'
10
11const FIELDS = 'number,title,state,isDraft,url,statusCheckRollup,reviewDecision'
12// ponytail: first 100 threads only; paginate if a PR ever has more
13const THREADS =
14 'query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){reviewThreads(first:100){nodes{isResolved path line comments(first:1){nodes{author{login} body url}}}}}}}'
15
16// The buckets `gh pr checks` uses. A CheckRun carries `conclusion` ('' while it runs), a StatusContext `state`.
17const FAILED = ['FAILURE', 'ERROR', 'CANCELLED', 'TIMED_OUT', 'ACTION_REQUIRED', 'STARTUP_FAILURE']
18const PASSED = ['SUCCESS', 'NEUTRAL', 'SKIPPED']
19const ORDER = { failed: 0, pending: 1, passed: 2 } as const
20
21type GhCheck = {
22 conclusion?: string
23 state?: string
24 name?: string
25 workflowName?: string
26 context?: string
27 detailsUrl?: string
28 targetUrl?: string
29}
30type GhView = {
31 number: number
32 title: string
33 url: string
34 state: 'OPEN' | 'MERGED' | 'CLOSED'
35 isDraft: boolean
36 reviewDecision: string
37 statusCheckRollup: GhCheck[]
38}
39type GhThread = {
40 isResolved: boolean
41 path: string
42 line: number | null
43 comments: { nodes: { author: { login: string } | null; body: string; url: string }[] }
44}
45
46const bucket = (c: GhCheck): keyof PrBarChecks => {
47 const s = c.conclusion || c.state || ''
48 return FAILED.includes(s) ? 'failed' : PASSED.includes(s) ? 'passed' : 'pending'
49}
50
51export function summarise(rollup: readonly GhCheck[]): PrBarChecks {
52 const sum = { passed: 0, failed: 0, pending: 0 }
53 for (const c of rollup) sum[bucket(c)] += 1
54 return sum
55}
56
57export const ci = ({ passed, failed, pending }: PrBarChecks) =>
58 failed ? `✗ ${failed} failed` : pending ? `… ${pending} pending` : passed ? '✓ passed' : 'no checks'
59
60const STATE_BG = { draft: 'inactive', open: 'success', merged: 'merged', closed: 'error' } as const
61const ciBg = ({ passed, failed, pending }: PrBarChecks) =>
62 failed ? 'error' : pending ? 'warning' : passed ? 'success' : 'inactive'
63
64export function buttons({ pr }: PrBarSnapshot, checked: number | null = null) {
65 const out: { key: string; label: string; hotkey: string; prompt: string }[] = []
66 const isLive = pr?.state === 'draft' || pr?.state === 'open'
67 if (!pr)
68 out.push({ key: 'commit', label: 'Commit + draft PR', hotkey: 'c', prompt: 'Commit the changes, push, and open a draft PR' })
69 if (pr && isLive && pr.threads.length > 0)
70 out.push({
71 key: 'feedback',
72 label: 'Check feedback',
73 hotkey: 'f',
74 prompt: `I've received feedback on PR #${pr.number}. Check each unresolved review comment: is it correct and do we need to fix it?`,
75 })
76 if (pr && isLive && pr.threads.length > 0 && checked === pr.number)
77 out.push({
78 key: 'resolve',
79 label: 'Commit + resolve',
80 hotkey: 'r',
81 prompt: `Commit the changes and push, then reply to and resolve each review thread on PR #${pr.number} we've addressed.`,
82 })
83 if (pr && isLive && pr.checks.failed > 0)
84 out.push({ key: 'ci', label: 'Fix CI', hotkey: 'x', prompt: `CI is failing on PR #${pr.number}. Find out why and fix it.` })
85 return out
86}
87
88export async function load($: EngineInterface): Promise<PrBarSnapshot | null> {
89 const head = await $.process.run(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
90 const branch = head.stdout.trim()
91 // ponytail: default branch by name, and gh is skipped there (no PR is ever opened from it)
92 if (head.exitCode !== 0 || ['HEAD', 'master', 'main'].includes(branch)) return null
93 const view = await $.process.run(['gh', 'pr', 'view', '--json', FIELDS])
94 if (view.exitCode !== 0) return /no pull requests found/i.test(view.stderr) ? { branch, pr: null } : null
95 const pr: GhView = JSON.parse(view.stdout)
96 const threads = await $.process.run([
97 'gh', 'api', 'graphql',
98 '-F', 'owner={owner}', '-F', 'repo={repo}', '-F', `number=${pr.number}`, '-f', `query=${THREADS}`,
99 ])
100 if (threads.exitCode !== 0) return null
101 const nodes: GhThread[] = JSON.parse(threads.stdout).data.repository.pullRequest.reviewThreads.nodes
102 const checkRuns: PrBarCheck[] = pr.statusCheckRollup
103 .map(c => ({
104 name: c.workflowName ? `${c.workflowName} / ${c.name}` : (c.name ?? c.context ?? 'check'),
105 result: bucket(c),
106 url: c.detailsUrl ?? c.targetUrl ?? pr.url,
107 }))
108 .sort((a, b) => ORDER[a.result] - ORDER[b.result])
109 const open: PrBarThread[] = nodes
110 .filter(n => !n.isResolved)
111 .map(n => {
112 const first = n.comments.nodes[0]
113 return {
114 path: n.path,
115 line: n.line,
116 author: first?.author?.login ?? 'ghost',
117 body: first?.body.split('\n').find(l => l.trim())?.trim() ?? '',
118 url: first?.url ?? pr.url,
119 }
120 })
121 return {
122 branch,
123 pr: {
124 number: pr.number,
125 title: pr.title,
126 url: pr.url,
127 state: pr.state === 'OPEN' && pr.isDraft ? 'draft' : (pr.state.toLowerCase() as PrBarPr['state']),
128 checks: summarise(pr.statusCheckRollup),
129 checkRuns,
130 review: pr.reviewDecision.toLowerCase().replaceAll('_', ' '),
131 threads: open,
132 },
133 }
134}
135
136let isRunning = false
137let isQueued = false
138
139// One fetch at a time; a refresh asked for mid-fetch runs once more after it, so a push isn't missed.
140// Resolves the snapshot it stored, or undefined when it only queued a rerun.
141async function refresh($: EngineInterface) {
142 if (isRunning) return void (isQueued = true)
143 isRunning = true
144 let snap: PrBarSnapshot | null = null
145 try {
146 do {
147 isQueued = false
148 snap = await load($).catch(() => null) // gh or git missing: draw nothing
149 await update($, snapshot, () => snap)
150 } while (isQueued)
151 } finally {
152 isRunning = false
153 }
154 return snap
155}
156
157// Drawing helpers shared by the bar and the panel.
158type Els = ElementTable
159
160const pill = (Text: Els['Text'], bg: string, text: string) => (
161 <Text backgroundColor={bg} color="inverseText" bold>{` ${text} `}</Text>
162)
163
164// A list, not a fragment: `<>...</>` is a column Box here.
165const pills = (Text: Els['Text'], pr: PrBarPr) => [
166 pill(Text, STATE_BG[pr.state], `PR #${pr.number} · ${pr.state}`),
167 pill(Text, ciBg(pr.checks), ci(pr.checks)),
168 pr.threads.length ? pill(Text, 'warning', `${pr.threads.length} unresolved`) : null,
169]
170
171// Set when Check feedback is pressed; turn.complete hands it to feedbackChecked once that turn ends.
172let feedbackAsked: number | null = null
173
174const actions = ($: EngineInterface, { Box, Button }: Els, snap: PrBarSnapshot, checked: number | null, marginTop = 0) => {
175 const list = buttons(snap, checked)
176 const press = async (key: string, prompt: string) => {
177 if (key === 'feedback') feedbackAsked = snap.pr?.number ?? null
178 if (key === 'resolve') await update($, feedbackChecked, () => null)
179 return $.prompt.submit({ text: prompt, asUser: true })
180 }
181 return list.length > 0 ? (
182 <Box gap={1} marginTop={marginTop}>
183 {list.map(b => (
184 <Button key={b.key} label={b.label} hotkey={b.hotkey} onPress={() => press(b.key, b.prompt)} />
185 ))}
186 </Box>
187 ) : null
188}
189
190export const register: Register = (on, options) => {
191 const isPanel = options.layout === 'panel'
192
193 on('session.start', async ($, e, next) => {
194 await $.command.register({ name: 'pr', description: "Show this branch's pull request in a panel" })
195 // The panel layout opens the panel once, when the branch has something to show.
196 void refresh($).then(snap => (isPanel && snap ? $.ui.open({ id: PANE, title: 'Pull request' }) : undefined))
197 $.clock.every(60_000, () => void refresh($)) // CI moves while the session is idle
198 return next(e)
199 })
200
201 on('turn.complete', async ($, e, next) => {
202 if (e.agentId) return next(e)
203 if (feedbackAsked !== null) {
204 const number = feedbackAsked
205 feedbackAsked = null
206 await update($, feedbackChecked, () => number)
207 }
208 void refresh($) // Claude may have committed, pushed or switched branch
209 return next(e)
210 })
211
212 // Asked for, so it asks for the keyboard too: its buttons' letters work at once.
213 on('command.run', { command: 'pr' }, async $ => {
214 void refresh($)
215 await $.ui.open({ id: PANE, title: 'Pull request', focus: true })
216 return { text: 'Pull request panel opened.' }
217 })
218
219 // Above the prompt (the bar layout): the PR as a row of pills, its actions
220 // under it. A band Button takes its hotkey once the band has focus.
221 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
222 const snap = await read($, snapshot)
223 const checked = await read($, feedbackChecked)
224 if (isPanel || !snap || e.props.hasSurvey) return next(e)
225 const els = $.ui.resolve(e)
226 const { Box, Text, Link } = els
227 const { pr } = snap
228 const bar = pr
229 ? [
230 ...pills(Text, pr),
231 pr.review ? <Text>{pr.review}</Text> : null,
232 <Box flexShrink={1}>
233 <Text wrap="truncate-end">
234 <Link href={pr.url} label={pr.title} />
235 </Text>
236 </Box>,
237 ]
238 : [pill(Text, 'inactive', 'no PR'), <Text>{snap.branch}</Text>]
239 return (
240 <Box flexDirection="column">
241 <Box flexDirection="row" gap={1} width={e.props.bodyColumns} backgroundColor="subtle">
242 {bar}
243 </Box>
244 {actions($, els, snap, checked)}
245 </Box>
246 )
247 })
248
249 // The panel: the same PR with each check that isn't green and each unresolved
250 // thread listed, every one a link. A Button takes its hotkey once the panel has focus.
251 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
252 const snap = await read($, snapshot)
253 const checked = await read($, feedbackChecked)
254 const els = $.ui.resolve(e)
255 const { Box, Text, Link } = els
256 if (!snap) return <Text dimColor>No pull request here: not a git repo, the default branch, or gh is unavailable.</Text>
257 const { pr } = snap
258 if (!pr)
259 return (
260 <Box flexDirection="column">
261 <Box gap={1}>{[pill(Text, 'inactive', 'no PR'), <Text>{snap.branch}</Text>]}</Box>
262 {actions($, els, snap, checked, 1)}
263 </Box>
264 )
265
266 const heading = (text: string) => (
267 <Box marginTop={1}>
268 <Text bold>{text}</Text>
269 </Box>
270 )
271 const notGreen = pr.checkRuns.filter(c => c.result !== 'passed')
272 return (
273 <Box flexDirection="column">
274 <Box gap={1}>{pills(Text, pr)}</Box>
275 <Box marginTop={1}>
276 <Text bold wrap="truncate-end">
277 <Link href={pr.url} label={pr.title} />
278 </Text>
279 </Box>
280 <Text dimColor wrap="truncate-end">
281 {[snap.branch, pr.review].filter(Boolean).join(' · ')}
282 </Text>
283
284 {heading('Checks')}
285 {notGreen.map(c => (
286 <Text color={c.result === 'failed' ? 'error' : 'warning'} wrap="truncate-end">
287 {c.result === 'failed' ? '✗ ' : '… '}
288 <Link href={c.url} label={c.name} />
289 </Text>
290 ))}
291 {pr.checks.passed ? <Text color="success">✓ {pr.checks.passed} passed</Text> : null}
292 {pr.checkRuns.length === 0 ? <Text dimColor>No checks</Text> : null}
293
294 {pr.threads.length ? heading(`Unresolved threads (${pr.threads.length})`) : null}
295 {pr.threads.map(t => (
296 <Box flexDirection="column">
297 <Text wrap="truncate-start">
298 <Link href={t.url} label={t.line ? `${t.path}:${t.line}` : t.path} />
299 <Text dimColor> @{t.author}</Text>
300 </Text>
301 <Text dimColor wrap="truncate-end">
302 {' '}
303 {t.body}
304 </Text>
305 </Box>
306 ))}
307
308 {actions($, els, snap, checked, 1)}
309 </Box>
310 )
311 })
312}
313types/index.d.ts 30 lines1export type PrBarChecks = { passed: number; failed: number; pending: number }
2
3/** One check run or status, bucketed as `gh pr checks` does. */
4export type PrBarCheck = { name: string; result: keyof PrBarChecks; url: string }
5
6/** An unresolved review thread and its first comment's first line. */
7export type PrBarThread = { path: string; line: number | null; author: string; body: string; url: string }
8
9export type PrBarPr = {
10 number: number
11 title: string
12 url: string
13 state: 'draft' | 'open' | 'merged' | 'closed'
14 checks: PrBarChecks
15 /** every check, failed first, then pending, then passed */
16 checkRuns: PrBarCheck[]
17 /** reviewDecision in words ("review required"), '' when GitHub has none */
18 review: string
19 threads: PrBarThread[]
20}
21
22/** null: draw nothing (not a repo, detached, default branch, gh failing) */
23export type PrBarSnapshot = { branch: string; pr: PrBarPr | null }
24
25declare module 'claude-code' {
26 interface PluginState {
27 'pr-bar': { snapshot: PrBarSnapshot | null; feedbackChecked: number | null }
28 }
29}
30