A brief view of the repo's BACKLOG.md: what's next, and how many items are to-do, new, parked or blocked

A Claude Code mod that summarises the repository's BACKLOG.md: what's next, and how many items are to-do, new (proposed, not yet confirmed), parked or blocked.
backlog · next: Real-Jira first sync · 9 to-do · 2 new · 3 parked/blocked, in two purple shades (violet for the label and what's next, lavender for the counts). It stacks with other bands, such as plan-progress, rather than replacing them. (A status-line entry can't take a colour of its own, hence the band.)/backlog opens a pane: each status with its items' titles and the ## section they sit under, plus an untagged count. Next is violet, to-do and new lavender, parked and blocked dimmed — nothing in the warning colour.backlog: a read-only tool, so Claude can answer "what's next?" without reading the file.It refreshes at session start, on every prompt (so a git pull shows), after an Edit or Write to BACKLOG.md, on a working-directory change and on /backlog. A repo without BACKLOG.md, or with no tagged items, shows nothing.
It always reads the main checkout's BACKLOG.md (via git rev-parse --git-common-dir), so a session working in a linked worktree, such as .claude/worktrees/<name>, still shows the trunk's backlog, not the worktree's copy. Outside a git repo it reads the working directory's file.
Tag each top-level item under a ## section at its start; the topic sections stay as they are:
## Engineering follow-ups
- [todo] **Data profile: multi-project boards.** A board whose filter spans several projects …
- [parked] **D6 — de-Jira the Connector seam.** Not before the GitLab connector.
- [new] **Cache the profile query.** …
[next], [todo], [new], [parked], [blocked] (case-insensitive).bold run, else its first sentence.## and inside code fences are not items.[new] is for items Claude proposes; the person promotes them to [todo] or [next].
/plugin install backlog --marketplace liveweird/claude-mods
Answer y, pick the user scope. Develop with claude plugin validate . and claude plugin test . in this folder, then /reload-plugins.
hooks/register.tsx 146 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import { EMPTY, LABELS, LAVENDER, STATUSES, VIOLET, counts, parseBacklog, reportText, summarize } from './parse'
5
6const PANE = 'backlog'
7const FILE = 'BACKLOG.md'
8
9const backlog = atom({ plugin: 'backlog', key: 'backlog' } as const, EMPTY)
10
11export const register: Register = on => {
12 on('session.start', async ($, e, next) => {
13 await $.command.register({ name: 'backlog', description: "The backlog at a glance: what's next, to-do, new, parked, blocked" })
14 await $.tool.register({
15 name: 'backlog',
16 description:
17 "Read-only: the working directory's BACKLOG.md by status tag ([next], [todo], [new], [parked], [blocked]), each item's title and section, and the untagged count.",
18 inputSchema: { type: 'object', properties: {} },
19 })
20 // 0.3.0 draws a band above the prompt instead; clear a line an older load pinned.
21 $.ui.status(undefined)
22 await refresh($)
23
24 return next(e)
25 })
26
27 on('tool.call', { tool: 'mcp__backlog__backlog' }, async $ => ({ result: reportText(summarize(await refresh($).catch(() => EMPTY))) }))
28
29 // A git pull or an edit made outside Claude shows on the next prompt; one small file read.
30 on('prompt.submit', async ($, e, next) => {
31 await refresh($).catch(() => undefined)
32 return next(e)
33 })
34
35 on('classic.CwdChanged', async ($, e, next) => {
36 const ran = await next(e)
37 await refresh($).catch(() => undefined)
38 return ran
39 })
40
41 for (const tool of ['Edit', 'Write'] as const) {
42 on('tool.call', { tool }, async ($, e, next) => {
43 const ran = await next(e)
44 if (isBacklogFile(e.file_path)) await refresh($).catch(() => undefined)
45 return ran
46 })
47 }
48
49 on('command.run', { command: 'backlog' }, async $ => {
50 await refresh($)
51 await $.ui.open({ id: PANE, title: 'Backlog' })
52 return { text: 'Backlog pane opened.' }
53 })
54
55 // One row above the prompt, in the two purple shades. It stacks with any band drawn beneath (e.g. plan-progress)
56 // rather than replacing it, and yields to a survey.
57 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
58 const below = await next(e)
59 const sum = summarize(await read($, backlog))
60 if (e.props.hasSurvey || !sum.found || sum.tagged === 0) return below
61
62 const { Box, Text } = $.ui.resolve(e)
63 const first = sum.next[0]
64 const tail = counts(sum).map(c => ` · ${c}`).join('')
65 const row = (
66 <Text wrap="truncate-end">
67 <Text color={VIOLET} bold>
68 backlog
69 </Text>
70 {first === undefined ? null : (
71 <Text>
72 <Text color={LAVENDER}> · next: </Text>
73 <Text color={VIOLET} bold>
74 {first.title}
75 </Text>
76 {sum.next.length > 1 ? <Text color={LAVENDER}> +{sum.next.length - 1}</Text> : null}
77 </Text>
78 )}
79 <Text color={LAVENDER}>{tail}</Text>
80 </Text>
81 )
82 // The engine's own placeholder (`{ type: 'engine' }`, nothing to draw) can't be nested in a tree: embed only a
83 // drawing another plugin made.
84 if (below.type === 'engine') return row
85 return (
86 <Box flexDirection="column">
87 {row}
88 {below}
89 </Box>
90 )
91 })
92
93 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
94 const { Box, Text } = $.ui.resolve(e)
95 const sum = summarize(await read($, backlog))
96 if (!sum.found || sum.tagged === 0) return <Text dimColor>{reportText(sum)}</Text>
97
98 return (
99 <Box flexDirection="column">
100 {STATUSES.filter(s => sum.byStatus[s].length > 0).map(status => {
101 const items = sum.byStatus[status]
102 const held = status === 'parked' || status === 'blocked'
103 return (
104 <Box flexDirection="column" marginBottom={1}>
105 <Text bold color={status === 'next' ? VIOLET : held ? undefined : LAVENDER} dimColor={held}>
106 {LABELS[status]} {items.length}
107 </Text>
108 {items.map(i => (
109 <Text wrap="truncate-end" dimColor={status !== 'next'}>
110 {' '}
111 {i.title}
112 <Text dimColor> · {i.section}</Text>
113 </Text>
114 ))}
115 </Box>
116 )
117 })}
118 {sum.untagged > 0 ? <Text color={LAVENDER}>Untagged: {sum.untagged}</Text> : null}
119 </Box>
120 )
121 })
122}
123
124function isBacklogFile(path: unknown): boolean {
125 return typeof path === 'string' && /(^|[/\\])BACKLOG\.md$/.test(path)
126}
127
128/**
129 * The main checkout's BACKLOG.md. git's common dir is the main checkout's `.git` from a linked worktree too, so a
130 * session working in `.claude/worktrees/<name>` still reads the main file, not the worktree's (older) copy. Outside a
131 * git repo, or in a bare/submodule layout, it falls back to the working directory's file.
132 */
133async function backlogPath($: EngineInterface): Promise<string> {
134 const git = await $.process.run(['git', 'rev-parse', '--path-format=absolute', '--git-common-dir']).catch(() => undefined)
135 const common = git?.exitCode === 0 ? git.stdout.trim() : ''
136 return /[\\/]\.git$/.test(common) ? `${common.slice(0, -'.git'.length)}${FILE}` : FILE
137}
138
139async function refresh($: EngineInterface) {
140 const text = await $.fs.read(await backlogPath($)).catch(() => undefined)
141 const parsed = text === undefined ? EMPTY : parseBacklog(text)
142 // The band reads the atom, so the write redraws it.
143 await update($, backlog, () => parsed)
144 return parsed
145}
146hooks/parse.ts 102 lines1import type { Backlog, Item, Status } from '../types'
2
3export const STATUSES: readonly Status[] = ['next', 'todo', 'new', 'parked', 'blocked']
4
5export const EMPTY: Backlog = { found: false, items: [], untagged: 0 }
6
7const BULLET = /^[-*+]\s+(.*)$/
8const TAG = /^\[(next|todo|new|parked|blocked)\]\s*(.*)$/i
9const SECTION = /^##\s+(.*?)\s*#*\s*$/
10/** A heading's trailing parenthetical, `(needs the user)`: dropped from the section name. */
11const ASIDE = /\s*\([^)]*\)\s*$/
12const FENCE = /^\s*(```|~~~)/
13const BOLD = /\*\*(.+?)\*\*/
14const TITLE_MAX = 60
15
16/**
17 * The tagged items of a backlog file. An item is a top-level bullet under a `##` section, tagged at its start
18 * (`- [todo] **Title.** …`); nested bullets belong to their parent, the preamble before the first `##` and fenced
19 * code are not items, and an untagged top-level bullet is only counted.
20 */
21export function parseBacklog(md: string): Backlog {
22 const items: Item[] = []
23 let untagged = 0
24 let section: string | undefined
25 let fenced = false
26 for (const line of md.split(/\r?\n/)) {
27 if (FENCE.test(line)) fenced = !fenced
28 if (fenced) continue
29 const heading = SECTION.exec(line)
30 if (heading) {
31 section = (heading[1] ?? '').replace(ASIDE, '')
32 continue
33 }
34 if (section === undefined) continue
35 const bullet = BULLET.exec(line)
36 if (!bullet) continue
37 const tag = TAG.exec(bullet[1] ?? '')
38 if (!tag) {
39 untagged += 1
40 continue
41 }
42 items.push({ status: (tag[1] ?? '').toLowerCase() as Status, title: titleOf(tag[2] ?? ''), section })
43 }
44 return { found: true, items, untagged }
45}
46
47/** The first bold run, else the text up to its first sentence end, at most TITLE_MAX characters. */
48export function titleOf(text: string): string {
49 const bold = BOLD.exec(text)?.[1]
50 const raw = (bold ?? text.split(/(?<=[.:;])\s/)[0] ?? text).trim().replace(/[.:;,]+$/, '')
51 return raw.length > TITLE_MAX ? `${raw.slice(0, TITLE_MAX - 1)}…` : raw
52}
53
54export type Summary = {
55 found: boolean
56 next: Item[]
57 byStatus: Record<Status, Item[]>
58 untagged: number
59 tagged: number
60}
61
62export function summarize(backlog: Backlog): Summary {
63 const byStatus = Object.fromEntries(STATUSES.map(s => [s, backlog.items.filter(i => i.status === s)])) as Record<Status, Item[]>
64 return { found: backlog.found, next: byStatus.next, byStatus, untagged: backlog.untagged, tagged: backlog.items.length }
65}
66
67/** The non-zero counts, parked and blocked together: `9 to-do · 2 new · 3 parked/blocked`. */
68export function counts(sum: Summary): string[] {
69 const held = sum.byStatus.parked.length + sum.byStatus.blocked.length
70 return [
71 sum.byStatus.todo.length ? `${sum.byStatus.todo.length} to-do` : '',
72 sum.byStatus.new.length ? `${sum.byStatus.new.length} new` : '',
73 held ? `${held} parked/blocked` : '',
74 ].filter(Boolean)
75}
76
77export const LABELS: Record<Status, string> = { next: 'Next', todo: 'To-do', new: 'New', parked: 'Parked', blocked: 'Blocked' }
78
79/** The summary as plain text: the read-only tool's answer. */
80export function reportText(sum: Summary): string {
81 if (!sum.found) return 'No BACKLOG.md in the working directory.'
82 if (sum.tagged === 0) {
83 return `BACKLOG.md has no tagged items (${sum.untagged} untagged). Tag top-level items with [next], [todo], [new], [parked] or [blocked].`
84 }
85 const lines: string[] = []
86 for (const status of STATUSES) {
87 const items = sum.byStatus[status]
88 if (items.length === 0) continue
89 lines.push(`${LABELS[status]} (${items.length}):`, ...items.map(i => ` - ${i.title} (${i.section})`))
90 }
91 if (sum.untagged > 0) lines.push(`Untagged: ${sum.untagged}`)
92 return lines.join('\n')
93}
94
95/**
96 * The mod's two purple shades: a deeper violet for what to look at (the label, what's next, a heading) and a light
97 * lavender for the rest. Mid-tone raw colours, so both read on a dark and a light terminal; no theme key is purple,
98 * and the theme's `warning` (yellow) made every parked or blocked item look like an alarm.
99 */
100export const VIOLET = '#8b5cf6'
101export const LAVENDER = '#a78bfa'
102types/index.d.ts 27 lines1export type Status = 'next' | 'todo' | 'new' | 'parked' | 'blocked'
2
3export type Item = {
4 status: Status
5 /** The item's first bold run, else its first sentence, clipped. */
6 title: string
7 /** The `##` section it sits under. */
8 section: string
9}
10
11export type Backlog = {
12 /** Whether BACKLOG.md was read at all. */
13 found: boolean
14 items: Item[]
15 /** Top-level bullets under a section that carry no tag. */
16 untagged: number
17}
18
19declare module 'claude-code' {
20 interface PluginState {
21 backlog: {
22 /** BACKLOG.md as last read from the working directory. */
23 backlog: Backlog
24 }
25 }
26}
27