One line above the prompt with what needs you: next meeting, PRs, Linear issues and Slack DMs. /glance lists them all.

<h1 align="center">Claude Code mods</h1>
<a href="https://www.npmjs.com/package/claude-code-mods"><img src="https://img.shields.io/npm/v/claude-code-mods.svg" alt="npm"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT"></a> <a href="https://github.com/hamzafer/claude-code-mods/actions/workflows/ci.yml"><img src="https://github.com/hamzafer/claude-code-mods/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
<a href="#-install">Install</a> · <a href="#-the-mods">All mods</a> · <a href="docs/mods.md">Docs</a> · <a href="https://claude.dev/blog/getting-started-with-claude-code-mods/">What are mods?</a>
<table> <tr> <td align="center" width="33%"><a href="docs/mods.md#-context-bar"><img src="images/context-bar.png" alt="context-bar: Claude Code context window usage as a stacked bar, a color per category" width="260"></a><br>📊 <b>context-bar</b><br>what fills your context</td> <td align="center" width="33%"><a href="docs/mods.md#-review-watch"><img src="images/review-watch.png" alt="review-watch: live lines for running Codex and subagent code reviews in Claude Code" width="260"></a><br>🔍 <b>review-watch</b><br>running code reviews, live</td> <td align="center" width="33%"><a href="docs/mods.md#-md-preview"><img src="images/md-preview.png" alt="md-preview: Markdown that Claude Code edits, rendered like GitHub next to the diff" width="260"></a><br>📝 <b>md-preview</b><br>Markdown rendered like GitHub</td> </tr> <tr> <td align="center" width="33%"><a href="docs/mods.md#-blast-radius"><img src="images/gallery/blast-radius.png" alt="blast-radius: a Claude Code hook holds rm -rf and lists the files it would delete" width="260"></a><br>💥 <b>blast-radius</b><br>see what <code>rm -rf</code> would delete</td> <td align="center" width="33%"><a href="docs/mods.md#-now-playing"><img src="images/now-playing.png" alt="now-playing: Spotify track, progress bar and synced lyrics inside Claude Code" width="260"></a><br>🎵 <b>now-playing</b><br>Spotify and its lyrics, live</td> <td align="center" width="33%"><a href="docs/mods.md#-reels-and-snake"><img src="images/reels-demo.gif" alt="reels: YouTube Shorts in a Claude Code pane while it works" width="260"></a><br>📱 <b>reels</b><br>Shorts while Claude works</td> </tr> <tr> <td align="center" width="33%"><a href="docs/mods.md#-where-am-i"><img src="images/gallery/where-am-i.png" alt="where-am-i: the session goal, current step and what waits on you, above the Claude Code prompt" width="260"></a><br>📍 <b>where-am-i</b><br>goal, now, waiting on you</td> <td align="center" width="33%"><a href="docs/mods.md#-lines-above-the-prompt"><img src="images/gallery/lines.png" alt="token-weather, usage-meter and other Claude Code status lines stacked above the prompt" width="260"></a><br>🌦️ <b>token-weather and friends</b><br>lines above the prompt</td> <td align="center" width="33%"><a href="#mission-control"><img src="images/gallery/mission-control.png" alt="mission-control: Claude Code subagents, tool calls and the files they touch, live" width="260"></a><br>🛰️ <b>mission-control</b><br>agents and the code they touch</td> </tr> <tr> <td align="center" width="33%"><a href="docs/mods.md#-switchboard"><img src="images/switchboard.png" alt="switchboard: subagents routed from opus to sonnet and haiku, with confidence and cost" width="260"></a><br>🔀 <b>switchboard</b><br>cheaper models for subagents</td> <td align="center" width="33%"><a href="docs/mods.md#-agent-radar"><img src="images/agent-radar.png" alt="agent-radar: a running subagent and two background shells with their latest output" width="260"></a><br>📡 <b>agent-radar</b><br>subagents and shells, live</td> <td align="center" width="33%"><a href="docs/mods.md#-reels-and-snake"><img src="images/snake.png" alt="snake: a game of Snake in a Claude Code pane" width="260"></a><br>🐍 <b>snake</b><br>a game while Claude works</td> </tr> </table>
npx claude-code-mods@latest
Tick the mods you want in a checklist, see what each one adds, and press Enter to install. Untick a mod to disable it (its settings stay). Restart Claude Code after. @latest makes npx skip an old cached copy.
--project installs for this project only--dry-run prints the claude commands instead of running them--pick a,b turns on exactly these mods, no checklist (--pick "" turns all off)--yes-community installs picked community mods without asking (outside a terminal they are skipped without it)--help shows usageIt edits the Claude profile that claude uses here, shown at the top. For another profile, set it first: CLAUDE_CONFIG_DIR=~/.claude-other npx claude-code-mods@latest.
Press o in the checklist to order your bands (the lines above the prompt). Move the cursor with up/down or j/k, move a band with Shift+up/down or K/J, and press Enter to save. Esc goes back without saving. The order goes to <config dir>/claude-code-mods/bands.json, where the config dir is CLAUDE_CONFIG_DIR or ~/.claude. Restart Claude Code to apply it. Bands not in the file sit on top.
By hand:
claude plugin marketplace add hamzafer/claude-code-mods
claude plugin install context-bar@claude-code-mods
To try one without installing:
git clone https://github.com/hamzafer/claude-code-mods && cd claude-code-mods
claude --plugin-dir mods/context-bar
Needs Claude Code 2.1.287+. A few mods need more (Chrome,
gh, a connector); the tables say which.
| Mod | What it does | Command | |
|---|---|---|---|
| 🛰️ | mission-control | Live map of agents, tool calls and the code they touch | /mission |
| 📊 | context-bar | Your context window as one stacked bar, a color per category, with token counts and where it compacts | /context-bar |
| 🌦️ | token-weather | Context fill from Clear to Compact soon, plus a prompt-cache countdown | |
| ⏱️ | cache-clock | A prompt-cache line under your status line, from Claude Code's own figures: time left, hit rate and misses, and the tokens your next message re-caches once it goes cold. Needs Node and Claude Code 2.1.287+ | /cache-clock setup |
| 📍 | where-am-i | Goal, doing now, waiting on you, next step | /where |
| ➡️ | next-steps | 2 or 3 likely next prompts after each turn, one key to draft one. language sets their language, layout: rows keeps one per row | 1 2 3, 0 hides |
| 💰 | usage-meter | 5-hour and 7-day plan usage, the reset countdown and the session's cost | |
| 🔥 | heatmap | A GitHub-style grid of your Claude Code time, with your streak, peak hours and top projects | /heatmap |
| 💳 | openai-balance | Your OpenAI API credit: an estimated balance with a gauge, today's spend, where the money mostly went, and the last call. Needs an OpenAI organization Admin key | /openai-balance |
| 🪙 | openrouter-balance | Your OpenRouter credit: the real balance with a gauge, today's spend and the model the money mostly went to. A regular API key shows the balance too when OpenRouter allows it, plus its own spend and limit | /openrouter-balance |
| 📡 | agent-radar | One live line per running subagent or background shell | /radar |
| 🔍 | review-watch | One live line per running code review (Codex or a review subagent) with the model, target, elapsed time and Codex's latest output. A toast lists the findings when it ends | |
| 🌐 | browser-lanes | Whether this session has a browser, and who holds it | /browser |
| 🕌 | prayer-times | The current prayer and how long is left, the next one, and zawal. Computed on your computer, Hanafi or standard Asr | /prayers |
| 🎬 | replay-theater | Steps through the last turn's edits, one diff at a time | /replay |
| 📝 | md-preview | Renders the Markdown files Claude edits like GitHub does, with before and after side by side. Needs Chrome and a terminal that shows images | /md |
| Mod | What it does | Command | |
|---|---|---|---|
| 💥 | blast-radius | Holds rm -r, force pushes and migrations, shows what they'd delete, cancels after 60 s with no answer |
| Mod | What it does | Command | |
|---|---|---|---|
| 🔀 | switchboard | Picks the model for each subagent that doesn't name one, with OpenAI's Decisions API or Jev, from its short label only. Shows what every subagent cost | /route |
These are built around my own tools and rules. Fork them and change the rules to yours.
| Mod | What it does | Command | |
|---|---|---|---|
| 👀 | glance | One line with what needs you: next meeting, PRs, Linear issues, Slack DMs. Needs gh and the Google Calendar, Linear and Slack connectors | /glance |
| 🚦 | merge-gate | Holds gh pr merge until CI is green and Codex reviewed once. Needs gh and the Codex CLI. Reviews run on one fixed model; change it to yours | /gate |
| 📏 | rulebook-guard | Enforces my writing and git rules: rewrites em dashes, asks before --amend, unformatted pushes, emails and phone numbers in notes | |
| 💾 | session-saver | Saves where you left off, shows it on resume. Needs unpause | /park [note] |
| Mod | What it does | Command | |
|---|---|---|---|
| 📱 | reels | YouTube Shorts while Claude works, pauses when it's done | /reels |
| 🐍 | snake | Snake while Claude works | /snake |
| 🎵 | now-playing | What Spotify is playing, with a progress bar, the lyric being sung, and ⏮ ⏸ ⏭ buttons. Needs macOS and the Spotify app | /music |
Mods by other people, in their own marketplaces. They're not maintained here, so read the code before you install. They also show up last in the npx claude-code-mods@latest checklist.
| Mod | What it does | Install | |
|---|---|---|---|
| 🖼️ | image-view by @jarrodwatts | See the images you paste into Claude Code: thumbnails above the prompt instead of bare [Image #1] tags | claude plugin marketplace add jarrodwatts/claude-image-view then claude plugin install image-view@claude-image-view |
| 🏷️ | last-prompt-title by @zhangbububu | Session titles that follow your latest prompt: cut for the CLI, written by Haiku for the desktop sidebar | claude plugin marketplace add zhangbububu/session-titles then claude plugin install last-prompt-title@session-titles |
| 🌏 | cc-zh by @jiangnanquan | Simplified Chinese UI localization via static dictionary: slash-command descriptions, /config labels, spinner, hints, notices, command output, tool summaries and turn duration. Zero tokens / network; verified on CC 2.1.296 | claude plugin marketplace add jiangnanquan/claude-code-zh then claude plugin install cc-zh@claude-code-zh |
| 🎛️ | subagent-tuner by @Kruhlikau | Picks the model and effort of every subagent: a Manual/Auto band, a pick pane, review → Opus and search → Haiku, and a saved default that overrides what the agent asked for | claude plugin marketplace add Kruhlikau/subagent-tuner then claude plugin install subagent-tuner@subagent-tuner |
| 🛒 | mod-store by @hellosverre | An app store in a pane: /mods browses, searches and installs about 2,700 community mods, with what each one can access shown before you install. Or ask Claude to find one | claude plugin marketplace add hellosverre/mod-store then claude plugin install mod-store@mod-store |
| 📈 | cache-meter by @T-AI-Labs | The share of each turn the prompt cache served, next to the context fill, with an auto-compact threshold and Compact and Clear buttons | claude plugin marketplace add T-AI-Labs/claude-code-mods then claude plugin install cache-meter@T-AI-Labs |
| ⏳ | usage-limits by @T-AI-Labs | 5-hour and weekly plan limits in percent, with the time left until each resets | claude plugin marketplace add T-AI-Labs/claude-code-mods then claude plugin install usage-limits@T-AI-Labs |
| 🟣 | pixel-pulse by @air01aditya | A purple pixel strip above the prompt that drifts right to left and glows under the pointer, and a purple pixel spiral in place of the working spinner. Desktop app only; it only draws | claude plugin marketplace add air01aditya/pixel-pulse then claude plugin install pixel-pulse@pixel-pulse |
| 🔗 | open-paths by @kiankhooban | Click a file path in Claude's reply and the file opens in its app: Word, Preview or Excel for documents, your editor at the line for app.py:42, Finder for folders. Launchers, scripts and unknown types are never opened | claude plugin marketplace add kiankhooban/open-paths then claude plugin install open-paths@open-paths |
| 🎼 | workflow-conductor by @bruw | Terminal UI for planning, running and understanding complex agent workflows inside Claude Code: define the workflow as a graph, have Claude script and run it, and watch the run on the same graph. Needs Claude Code 2.1.296+ and a terminal 110+ columns wide | claude plugin marketplace add bruw/workflow-conductor then claude plugin install workflow-conductor@workflow-conductor |
| 💸 | bedrock-meter by @weidu-tpvision | Token and USD meter for Claude Code on Amazon Bedrock: session cost, context fill, cache hit rate and today's total above the prompt, priced at AWS's own on-demand rates (refreshed weekly from the AWS price list), with a per-model breakdown in /bedrock-cost | claude plugin marketplace add weidu-tpvision/claude-mods then claude plugin install bedrock-meter@weidu-claude-mods |
| 📱 | brainrot-break by @BordyV | A TikTok-style feed of 350+ pixel art mini-videos in a pane while Claude answers: scroll, like, pick your themes, and an end card when Claude is done. Every video is a small simulation drawn locally: no tokens, no model calls. Terminal and desktop app, in 6 languages. Try it in the browser | claude plugin marketplace add BordyV/brainrot-break then claude plugin install brainrot-break@brainrot-break |
Built one? Open a PR that adds a row.
<a id="mission-control"></a>
Every subagent, every tool call and every file they touch, in a pane next to the chat. Shown at 4x: two subagents building a logout feature across four files.

Install it like any mod, restart, and type /mission (or /mission code to open the code map). q closes it.
w shows the agents and every tool call, livec shows the code map, with import arrowsThe Code view runs on macOS and Linux and needs Google Chrome or Chromium and a terminal that shows images (Ghostty, kitty, iTerm2). The Who view works everywhere.
hooks/register.tsx 187 lines1// glance: one line above the prompt with what needs you: next meeting, PRs, Linear, Slack.
2import { atom, read, update } from 'claude-code'
3import type { EngineInterface, McpToolResult, Register, Timer } from 'claude-code'
4
5import type { Dm, Issue, Meeting, Pr, Source } from '../types'
6import { bandsFile, parseOrder, stackBands } from './bands'
7import type { Part } from './pick'
8import {
9 PR_QUERY, SEPARATOR, clock, dmPart, dmsFrom, fit, issuePart, issuesFrom, meetingPart, meetingsFrom, mergeDms, prPart, prsFrom, slackIdFrom, when,
10} from './pick'
11
12const EVERY_MS = 5 * 60 * 1000
13const TICK_MS = 60 * 1000 // the meeting countdown moves each minute without a fetch
14const SLACK_WINDOW_S = 2 * 60 * 60
15
16// Held by the host, so what was fetched survives a hot reload of this file.
17const meetings = atom({ plugin: 'glance', key: 'meetings' } as const, { items: [], fetchedAt: 0, isFailed: false } as Source<Meeting>)
18const prs = atom({ plugin: 'glance', key: 'prs' } as const, { items: [], fetchedAt: 0, isFailed: false } as Source<Pr>)
19const issues = atom({ plugin: 'glance', key: 'issues' } as const, { items: [], fetchedAt: 0, isFailed: false } as Source<Issue>)
20const dms = atom({ plugin: 'glance', key: 'dms' } as const, { items: [], fetchedAt: 0, isFailed: false } as Source<Dm>)
21const triedAt = atom({ plugin: 'glance', key: 'triedAt' } as const, 0)
22const minute = atom({ plugin: 'glance', key: 'minute' } as const, 0)
23
24let bandOrder: Promise<string[]> | undefined // read once per session: restart to apply
25
26export const register: Register = on => {
27 let timer: Timer | undefined // one minute timer, even if session.start fires again
28
29 on('session.start', async ($, e, next) => {
30 const result = await next(e)
31 await $.command.register({ name: 'glance', description: 'Refresh glance and list everything that needs you' }).catch(() => {}) // a name Claude Code already has is refused: start anyway
32 void refresh($, false).catch(() => {}) // in the background: a slow source never holds up the session
33 timer?.cancel()
34 timer = $.clock.every(TICK_MS, () => void tick($).catch(() => {}))
35 return result
36 })
37
38 on('command.run', { command: 'glance' }, async $ => {
39 await refresh($, true)
40 return { text: await details($) }
41 })
42
43 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
44 const rest = await next(e) // what other mods and Claude Code draw here stays
45 if (e.props.hasSurvey) return rest
46 await read($, minute) // redraw each minute, for the countdown
47 const now = await $.clock.now()
48 const [m, p, i, d] = [await read($, meetings), await read($, prs), await read($, issues), await read($, dms)]
49
50 const next1 = m.items.find(x => x.end > now)
51 const parts = [
52 dimmed(next1 && meetingPart(next1, now), m.isFailed),
53 dimmed(prPart(p.items), p.isFailed),
54 dimmed(issuePart(i.items), i.isFailed),
55 dimmed(dmPart(d.items), d.isFailed),
56 ]
57 if (parts.every(x => !x)) return rest
58
59 const texts = fit(parts, e.props.bodyColumns - 2)
60 const { Box, Text } = $.ui.resolve(e)
61 const shown = parts.map((part, k) => ({ part, text: texts[k] })).filter(x => x.part && x.text)
62 const mine = (
63 <Box flexDirection="row" paddingX={1}>
64 {shown.map(({ part, text }, k) => (
65 <Text key={String(k)} wrap="truncate" color={part!.isDim ? undefined : part!.color} dimColor={part!.isDim}>
66 {(k > 0 ? SEPARATOR : '') + text}
67 </Text>
68 ))}
69 </Box>
70 )
71 return stackBands(rest, 'glance', mine, 'above', await (bandOrder ??= readBandOrder($).catch(() => []))) // above what other mods draw, unless the band order says otherwise
72 })
73}
74
75// The band order file, as the claude-code-mods checklist saves it; [] on any error.
76async function readBandOrder($: EngineInterface): Promise<string[]> {
77 const file = bandsFile(await $.env.get('CLAUDE_CONFIG_DIR'), await $.env.get('HOME'))
78 return file && (await $.fs.exists(file)) ? parseOrder(await $.fs.read(file)) : []
79}
80
81// Forgets the cached band order, for tests.
82export function resetBandOrder() {
83 bandOrder = undefined
84}
85
86// A source that failed to refresh still shows its last answer, dimmed.
87function dimmed(part: Part | undefined, isFailed: boolean): Part | undefined {
88 return part && { ...part, isDim: isFailed }
89}
90
91async function tick($: EngineInterface) {
92 const now = await $.clock.now()
93 await update($, minute, () => now)
94 await refresh($, false)
95}
96
97// Every 5 minutes, unless /glance asked. Each source fails on its own and keeps its last answer.
98async function refresh($: EngineInterface, isForced: boolean) {
99 const now = await $.clock.now()
100 if (!isForced && (await read($, triedAt)) > 0 && now - (await read($, triedAt)) < EVERY_MS) return
101 await update($, triedAt, () => now)
102
103 const [m, p, i, d] = await Promise.all([
104 attempt(async () => meetingsFrom(await mcp($, 'claude.ai Google Calendar', 'list_events', { pageSize: 30, orderBy: 'startTime' }), now)),
105 attempt(async () => {
106 const { exitCode, stdout } = await $.process.run(['gh', 'api', 'graphql', '-f', `query=${PR_QUERY}`], { timeoutMs: 20_000 })
107 if (exitCode !== 0) throw new Error('gh failed')
108 return prsFrom(JSON.parse(stdout))
109 }),
110 attempt(async () =>
111 issuesFrom(await mcp($, 'claude.ai Linear', 'list_issues', {
112 assignee: 'me', state: 'started', limit: 25, fields: ['title', 'status', 'url', 'updatedAt'],
113 }))),
114 attempt(() => slack($, now)),
115 ])
116 await update($, meetings, s => settle(s, m, now))
117 await update($, prs, s => settle(s, p, now))
118 await update($, issues, s => settle(s, i, now))
119 await update($, dms, s => settle(s, d, now))
120}
121
122// Slack's search has no "mentions me" filter: to:me finds DMs, and a second
123// search for <@your-id> finds channel mentions. The id is looked up once and
124// kept in memory only. Without it, DMs alone still show.
125let slackId: string | undefined
126async function slack($: EngineInterface, now: number) {
127 const search = { after: String(Math.floor(now / 1000) - SLACK_WINDOW_S), sort: 'timestamp', limit: 10, include_bots: false, include_context: false, natural_language_query: '' }
128 slackId ??= await mcp($, 'claude.ai Slack', 'slack_read_user_profile', { response_format: 'detailed' }).then(slackIdFrom, () => undefined)
129 const [direct, mentions] = await Promise.all([
130 mcp($, 'claude.ai Slack', 'slack_search_public_and_private', { ...search, filters: 'to:me' }).then(dmsFrom),
131 slackId
132 ? mcp($, 'claude.ai Slack', 'slack_search_public_and_private', { ...search, keywords: [`<@${slackId}>`], channel_types: 'public_channel,private_channel' }).then(dmsFrom, () => [])
133 : [],
134 ])
135 return mergeDms(direct, mentions)
136}
137
138// The items, or undefined when the source failed.
139async function attempt<T>(get: () => Promise<T[]>): Promise<T[] | undefined> {
140 try {
141 return await get()
142 } catch {
143 return undefined
144 }
145}
146
147// A failed source keeps its last items and is marked, so the line dims it.
148function settle<T>(s: Source<T>, items: T[] | undefined, now: number): Source<T> {
149 return items ? { items, fetchedAt: now, isFailed: false } : { ...s, isFailed: true }
150}
151
152// A connector's answer is JSON in its first text block.
153async function mcp($: EngineInterface, server: string, tool: string, args: Record<string, unknown>) {
154 const result: McpToolResult = await $.mcp.call(server, tool, args)
155 const block = result.content.find(c => c.type === 'text') as { text?: string } | undefined
156 if (result.isError || !block?.text) throw new Error(`${server} ${tool} failed`)
157 return JSON.parse(block.text)
158}
159
160// What /glance prints: everything behind the line.
161async function details($: EngineInterface) {
162 const now = await $.clock.now()
163 const [m, p, i, d] = [await read($, meetings), await read($, prs), await read($, issues), await read($, dms)]
164 const stale = (s: Source<unknown>) => (s.isFailed ? (s.fetchedAt ? ` _(couldn't refresh, from ${clock(s.fetchedAt)})_` : " _(couldn't reach it)_") : '')
165 const lines: string[] = []
166
167 lines.push(`**📅 Meetings**${stale(m)}`)
168 const upcoming = m.items.filter(x => x.end > now).slice(0, 3)
169 if (upcoming.length === 0) lines.push('- nothing in the next 7 days')
170 for (const x of upcoming) lines.push(`- ${x.title}, ${when(x, now)}`)
171
172 lines.push('', `**🔀 PRs that need you**${stale(p)}`)
173 if (p.items.length === 0) lines.push('- none')
174 const reason = { review: 'review requested', ci: 'CI failing', changes: 'changes requested' }
175 for (const x of p.items) lines.push(`- [${x.repo}#${x.number}](${x.url}) ${x.title}: **${reason[x.reason]}**`)
176
177 lines.push('', `**📋 Linear in progress**${stale(i)}`)
178 if (i.items.length === 0) lines.push('- none')
179 for (const x of i.items) lines.push(`- [${x.id}](${x.url}) ${x.status}: ${x.title}`)
180
181 lines.push('', `**💬 Slack DMs and mentions, last 2 hours**${stale(d)}`)
182 if (d.items.length === 0) lines.push('- nothing new')
183 for (const x of d.items) lines.push(`- ${clock(x.at)} ${x.from}: ${x.text || '(no text)'}${x.url ? ` ([open](${x.url}))` : ''}`)
184
185 return lines.join('\n')
186}
187hooks/bands.ts 73 lines1// Band order: every band mod ships this same file (canonical copy: shared/bands.ts in the repo).
2// The order file, <configDir>/claude-code-mods/bands.json, lists mod names top to bottom
3// (the last sits right above the prompt). Each band mod wraps its band in a Box keyed
4// `band:<name>` and returns one column keyed `bands`; the next band mod unpacks that
5// column, adds its own band and sorts again, so the last one to draw sorts them all.
6// Edit shared/bands.ts, then copy it over every mod's hooks/bands.ts (a repo test checks).
7// Reading the file needs $, which Claude Code follows only within one file, so each mod
8// reads it in its own register file with bandsFile and parseOrder, once per session.
9import type { RenderElement, RenderNode } from 'claude-code'
10
11const COLUMN = 'bands'
12const PREFIX = 'band:'
13
14// Where the checklist saves the order: CLAUDE_CONFIG_DIR, or ~/.claude. Undefined with neither.
15export function bandsFile(configDir: string | undefined, home: string | undefined): string | undefined {
16 const dir = configDir ? configDir.replace(/\/+$/, '') : home ? `${home}/.claude` : ''
17 return dir ? `${dir}/claude-code-mods/bands.json` : undefined
18}
19
20// The names in an order file; [] when it is no JSON or not { order: string[] }.
21export function parseOrder(text: string): string[] {
22 try {
23 const order = (JSON.parse(text) as { order?: unknown } | null)?.order
24 return Array.isArray(order) && order.every(n => typeof n === 'string') ? order : []
25 } catch {
26 return []
27 }
28}
29
30/**
31 * One column of bands: `mine` wrapped in a Box keyed `band:<name>`, placed
32 * `at` (above or below) what `next(e)` returned, then sorted by `order`.
33 * With an order, items that are no band come first, then bands not in the
34 * order (in their current order), then the listed ones in file order. With
35 * no order nothing moves, so the screen looks as it did before.
36 */
37export function stackBands(rest: RenderElement | null | undefined, name: string, mine: RenderNode, at: 'above' | 'below', order: string[]): RenderElement {
38 const own: RenderElement = { type: 'Box', props: { key: PREFIX + name, flexDirection: 'column' }, children: [mine] }
39 const others = unpack(rest)
40 const items = at === 'above' ? [own, ...others] : [...others, own]
41 return { type: 'Box', props: { key: COLUMN, flexDirection: 'column' }, children: order.length ? sorted(items, order) : items }
42}
43
44// Another band mod's column gives up its items; anything else is one item.
45function unpack(rest: RenderElement | null | undefined): RenderNode[] {
46 if (!rest) return []
47 if (!isColumn(rest)) return [rest]
48 const kids = rest.children ?? []
49 const owner = rest.part?.plugin
50 // The engine stamped the column with its owner: that stamp belongs on the owner's own band.
51 return kids.map(k => (owner && typeof k !== 'string' && bandName(k) === owner && !('part' in k && k.part) ? { ...k, part: rest.part } : k))
52}
53
54function isColumn(el: RenderElement): el is RenderElement & { type: 'Box' } {
55 return el.type === 'Box' && el.props?.key === COLUMN
56}
57
58function bandName(node: RenderNode): string | undefined {
59 if (typeof node === 'string' || node.type !== 'Box') return undefined
60 const key = node.props?.key
61 return typeof key === 'string' && key.startsWith(PREFIX) ? key.slice(PREFIX.length) : undefined
62}
63
64function sorted(items: RenderNode[], order: string[]): RenderNode[] {
65 const rank = (n: RenderNode) => {
66 const name = bandName(n)
67 if (name === undefined) return -2 // not a band: first
68 const i = order.indexOf(name)
69 return i < 0 ? -1 : i // a band not in the order: on top of the listed ones
70 }
71 return items.map((n, i) => ({ n, i, r: rank(n) })).sort((a, b) => a.r - b.r || a.i - b.i).map(x => x.n)
72}
73hooks/pick.ts 280 lines1// Pure parts of glance: read each source's answer, rank it, and fit the line.
2import type { Dm, Issue, Meeting, Pr } from '../types'
3
4const MIN = 60_000
5const LONG_BLOCK = 3 * 60 * MIN // a block running now that's longer than this doesn't hide the next meeting
6const WEEKDAY = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
7
8// ---- Calendar ---------------------------------------------------------------
9
10type CalEvent = {
11 summary?: string
12 status?: string
13 eventType?: string
14 start?: { dateTime?: string; date?: string }
15 end?: { dateTime?: string; date?: string }
16 attendees?: { self?: boolean; responseStatus?: string }[]
17 htmlLink?: string
18}
19
20/**
21 * Timed events that haven't ended and that you haven't declined, soonest
22 * first. A long block already running (a workshop, "busy") is left out, so it
23 * can't hide the next meeting.
24 */
25export function meetingsFrom(answer: { events?: CalEvent[] }, now: number): Meeting[] {
26 return (answer.events ?? [])
27 .filter(e => e.status !== 'cancelled' && e.start?.dateTime && e.end?.dateTime) // all-day events have only a date
28 .filter(e => e.eventType === undefined || e.eventType === 'DEFAULT' || e.eventType === 'FROM_GMAIL')
29 .filter(e => e.attendees?.find(a => a.self)?.responseStatus !== 'declined')
30 .map(e => ({
31 title: e.summary?.trim() || '(no title)',
32 start: Date.parse(e.start!.dateTime!),
33 end: Date.parse(e.end!.dateTime!),
34 url: e.htmlLink ?? '',
35 }))
36 .filter(m => m.end > now)
37 .filter(m => !(m.start <= now && m.end - m.start > LONG_BLOCK))
38 .sort((a, b) => a.start - b.start)
39}
40
41// ---- GitHub -----------------------------------------------------------------
42
43// One call: reviews asked of you, and your own open PRs with their CI and review state.
44export const PR_QUERY = `query {
45 review: search(query: "is:open is:pr review-requested:@me archived:false", type: ISSUE, first: 20) {
46 nodes { ... on PullRequest { number title url repository { name } } }
47 }
48 mine: search(query: "is:open is:pr author:@me archived:false", type: ISSUE, first: 50) {
49 nodes { ... on PullRequest { number title url isDraft reviewDecision repository { name }
50 commits(last: 1) { nodes { commit { statusCheckRollup { state } } } } } }
51 }
52}`
53
54type PrNode = {
55 number?: number
56 title?: string
57 url?: string
58 isDraft?: boolean
59 reviewDecision?: string | null
60 repository?: { name: string }
61 commits?: { nodes: { commit: { statusCheckRollup: { state: string } | null } }[] }
62}
63
64/** PRs that need you: reviews asked of you, then yours with failing CI (drafts last), then yours with changes requested. */
65export function prsFrom(answer: { data?: { review?: { nodes: PrNode[] }; mine?: { nodes: PrNode[] } } }): Pr[] {
66 const pr = (n: PrNode, reason: Pr['reason']): Pr => ({
67 repo: n.repository?.name ?? '',
68 number: n.number ?? 0,
69 title: n.title ?? '',
70 url: n.url ?? '',
71 reason,
72 })
73 const mine = (answer.data?.mine?.nodes ?? []).filter(n => n.number)
74 const ciState = (n: PrNode) => n.commits?.nodes[0]?.commit.statusCheckRollup?.state
75 const isFailing = (n: PrNode) => ciState(n) === 'FAILURE' || ciState(n) === 'ERROR'
76 const out = [
77 ...(answer.data?.review?.nodes ?? []).filter(n => n.number).map(n => pr(n, 'review')),
78 ...mine.filter(n => isFailing(n) && !n.isDraft).map(n => pr(n, 'ci')),
79 ...mine.filter(n => isFailing(n) && n.isDraft).map(n => pr(n, 'ci')),
80 ...mine.filter(n => !isFailing(n) && n.reviewDecision === 'CHANGES_REQUESTED').map(n => pr(n, 'changes')),
81 ]
82 const seen = new Set<string>()
83 return out.filter(p => !seen.has(p.url) && seen.add(p.url))
84}
85
86// ---- Linear -----------------------------------------------------------------
87
88type LinearIssue = { id?: string; title?: string; status?: string; url?: string; updatedAt?: string }
89
90/** Your started issues (In Progress, In Review), most recently touched first. */
91export function issuesFrom(answer: { issues?: LinearIssue[] }): Issue[] {
92 return (answer.issues ?? [])
93 .filter(i => i.id)
94 .map(i => ({ id: i.id!, title: i.title ?? '', status: i.status ?? '', url: i.url ?? '', updatedAt: Date.parse(i.updatedAt ?? '') || 0 }))
95 .sort((a, b) => b.updatedAt - a.updatedAt)
96}
97
98// ---- Slack ------------------------------------------------------------------
99
100/**
101 * Messages from Slack's search answer, newest first. The connector answers in
102 * markdown, one "### Result" block per message with From, Message_ts,
103 * Permalink and Text lines.
104 */
105export function dmsFrom(answer: { results?: string }): Dm[] {
106 const blocks = (answer.results ?? '').split(/^### Result /m).slice(1)
107 const out: Dm[] = []
108 for (const block of blocks) {
109 const from = /^From: (.+?)(?: <[^>]*>)?(?: \(ID: [^)]*\))?\s*$/m.exec(block)?.[1]?.trim()
110 const ts = Number(/^Message_ts: ([\d.]+)/m.exec(block)?.[1])
111 if (!from || !ts) continue
112 const url = /^Permalink: \[[^\]]*\]\(([^)]+)\)/m.exec(block)?.[1] ?? ''
113 const at = block.search(/^Text:/m)
114 const body = at < 0 ? '' : block.slice(at).replace(/^Text: */, '').split(/\n---/)[0] ?? ''
115 const text = body
116 .split('\n')
117 .map(line => plain(line).replace(/:[a-z0-9_+-]+:/gi, '').replace(/\s+/g, ' ').trim())
118 .find(line => line !== '') ?? ''
119 out.push({ from, text, at: Math.round(ts * 1000), url })
120 }
121 return out.sort((a, b) => b.at - a.at)
122}
123
124/** Slack markup as read: <@U1|name> is @name, <url|label> is label. */
125function plain(line: string) {
126 return line
127 .replace(/<@[A-Z0-9]+\|([^>]+)>/g, '@$1')
128 .replace(/<@[A-Z0-9]+>/g, '@someone')
129 .replace(/<#[A-Z0-9]+\|([^>]*)>/g, '#$1')
130 .replace(/<(?:https?:|mailto:)[^|>]*\|([^>]+)>/g, '$1')
131 .replace(/<((?:https?:|mailto:)[^>]+)>/g, '$1')
132}
133
134/** DMs and mentions together, newest first, each message once. */
135export function mergeDms(...lists: Dm[][]): Dm[] {
136 const seen = new Set<string>()
137 return lists
138 .flat()
139 .sort((a, b) => b.at - a.at)
140 .filter(d => {
141 const key = d.url || `${d.from}@${d.at}`
142 return !seen.has(key) && !!seen.add(key)
143 })
144}
145
146/** The signed-in user's id from Slack's detailed profile answer. */
147export function slackIdFrom(answer: { result?: string }) {
148 return /^User ID: ([A-Z0-9]+)$/m.exec(answer.result ?? '')?.[1]
149}
150
151// ---- The line ---------------------------------------------------------------
152
153/** One part of the line: its texts from fullest to shortest. */
154export type Part = { levels: string[]; color?: string; isDim?: boolean }
155
156/** Clock time as 24-hour HH:MM in the machine's time zone. */
157export function clock(ms: number) {
158 const d = new Date(ms)
159 return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
160}
161
162function dayKey(ms: number) {
163 const d = new Date(ms)
164 return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`
165}
166
167/** When a meeting is, said the shortest way that's still clear. */
168export function when(m: Meeting, now: number) {
169 if (m.start <= now) return `now until ${clock(m.end)}`
170 const mins = Math.ceil((m.start - now) / MIN)
171 if (mins < 60) return `in ${mins} min`
172 if (dayKey(m.start) === dayKey(now)) return `at ${clock(m.start)}`
173 if (dayKey(m.start) === dayKey(now + 86_400_000)) return `tomorrow ${clock(m.start)}`
174 return `${WEEKDAY[new Date(m.start).getDay()]} ${clock(m.start)}`
175}
176
177export function meetingPart(m: Meeting, now: number): Part {
178 const w = when(m, now)
179 const isNow = m.start <= now
180 const isSoon = !isNow && m.start - now <= 15 * MIN
181 const say = (title: string) => (isNow ? `📅 now: ${title} until ${clock(m.end)}` : `📅 ${title} ${w}`)
182 return {
183 levels: [say(m.title), say(cut(m.title, 16)), `📅 ${w}`],
184 color: isNow ? 'cyan' : isSoon ? 'yellow' : undefined,
185 }
186}
187
188const REASON: Record<Pr['reason'], string> = { review: 'review requested', ci: 'CI failing', changes: 'changes requested' }
189
190export function prPart(prs: Pr[]): Part | undefined {
191 const [top] = prs
192 if (!top) return undefined
193 const more = prs.length > 1 ? ` +${prs.length - 1}` : ''
194 return {
195 levels: [
196 `🔀 ${top.repo}#${top.number}: ${REASON[top.reason]}${more}`,
197 `🔀 #${top.number} ${REASON[top.reason]}${more}`,
198 `🔀 ${prs.length} PR${prs.length === 1 ? '' : 's'}`,
199 ],
200 color: top.reason === 'ci' ? 'red' : top.reason === 'review' ? 'yellow' : undefined,
201 }
202}
203
204export function issuePart(issues: Issue[]): Part | undefined {
205 const [top] = issues
206 if (!top) return undefined
207 const more = issues.length > 1 ? ` +${issues.length - 1}` : ''
208 return {
209 levels: [
210 `📋 ${top.id} ${top.status}: ${cut(top.title, 28)}${more}`,
211 `📋 ${top.id} ${top.status}${more}`,
212 `📋 ${issues.length} active`,
213 ],
214 }
215}
216
217export function dmPart(dms: Dm[]): Part | undefined {
218 const [top] = dms
219 if (!top) return undefined
220 const more = dms.length > 1 ? ` +${dms.length - 1}` : ''
221 const name = top.from.split(' ')[0]
222 return {
223 levels: [
224 top.text ? `💬 ${name}: "${cut(top.text, 30)}"${more}` : `💬 ${name}${more}`,
225 `💬 ${dms.length} new`,
226 ],
227 }
228}
229
230export const SEPARATOR = ' · '
231
232/**
233 * Shrinks the parts until the line fits `columns`. Parts are in line order
234 * (meeting, PRs, Linear, Slack); Slack gives way first and the meeting last.
235 * Returns each part's chosen text, in order.
236 */
237export function fit(parts: (Part | undefined)[], columns: number): (string | undefined)[] {
238 const level = parts.map(() => 0)
239 const text = () => parts.map((p, i) => p && p.levels[Math.min(level[i] ?? 0, p.levels.length - 1)])
240 const width = () => text().filter(Boolean).reduce((sum, t, i) => sum + cells(t!) + (i > 0 ? SEPARATOR.length : 0), 0)
241 // Each step shortens one part by one level: Slack, then Linear and PRs, then all three again, then the meeting.
242 const steps = [3, 2, 1, 3, 2, 1, 0, 0]
243 for (const i of steps) {
244 if (width() <= columns) break
245 level[i] = (level[i] ?? 0) + 1
246 }
247 return text()
248}
249
250/** Terminal cells a string takes: wide characters count two, variation selectors none. */
251export function cells(s: string) {
252 let n = 0
253 for (const ch of s) {
254 const c = ch.codePointAt(0)!
255 if (c === 0xfe0f || c === 0x200d) continue
256 n += isWide(c) ? 2 : 1
257 }
258 return n
259}
260
261// Emoji, and East Asian wide and fullwidth letters (Hangul, CJK, kana, fullwidth forms).
262function isWide(c: number) {
263 return (
264 c >= 0x1f000 ||
265 (c >= 0x2600 && c <= 0x27bf) ||
266 (c >= 0x1100 && c <= 0x115f) ||
267 (c >= 0x2e80 && c <= 0xa4cf) ||
268 (c >= 0xac00 && c <= 0xd7a3) ||
269 (c >= 0xf900 && c <= 0xfaff) ||
270 (c >= 0xfe30 && c <= 0xfe4f) ||
271 (c >= 0xff00 && c <= 0xff60) ||
272 (c >= 0xffe0 && c <= 0xffe6)
273 )
274}
275
276export function cut(s: string, max: number) {
277 const chars = [...s]
278 return chars.length <= max ? s : `${chars.slice(0, max - 1).join('').trimEnd()}…`
279}
280types/index.d.ts 26 lines1// What glance keeps per source: the items that need you, ranked, and how the last fetch went.
2export type Meeting = { title: string; start: number; end: number; url: string }
3export type Pr = { repo: string; number: number; title: string; url: string; reason: 'review' | 'ci' | 'changes' }
4export type Issue = { id: string; title: string; status: string; url: string; updatedAt: number }
5export type Dm = { from: string; text: string; at: number; url: string }
6
7export type Source<T> = {
8 items: T[]
9 // When the last good answer came in (0: never), and whether the latest try failed.
10 fetchedAt: number
11 isFailed: boolean
12}
13
14declare module 'claude-code' {
15 interface PluginState {
16 glance: {
17 meetings: Source<Meeting>
18 prs: Source<Pr>
19 issues: Source<Issue>
20 dms: Source<Dm>
21 triedAt: number
22 minute: number
23 }
24 }
25}
26