SLOPSHOPPER

prompt-runner

Claude Run: an endless-runner game above the prompt. Jump Claude over bugs and duck under hallucination moths.

panecommandtoast
v0.1.0MITupdated 2026-10-10yurmix/prompt-runner
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · prompt-runner
│ ┃ Claude Run ✕ › fix the failing auth╭────────────────────────────────────────────╮ │ ┃ ▣ client module ./runner.tsx │ prompt-runner │ │ ⏺ Read(src/auth.ts) │ Claude Run: press ctrl+x g to play while │ │ ⎿ Read 6 lines │ you wait. │ │ ⏺ Update(src/auth.ts) ╰────────────────────────────────────────────╯ │ ⎿ Added 2 lines, removed 1 line │ ⏺ Bash(bun test) │ ⎿ 3 pass, 1 fail │ │ ● Done. refresh now rejects expired claims and logs an audit event. │ │ ✻ Worked for 42s · done 4:20 PM │ │ › /prompt-runner │ ⎿ prompt-runner: Claude Run is open. Space or a tap jumps. Esc put │ │ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Pane · Claude Run
▣ client module ./runner.tsx
README

Claude Run

A one-button endless-runner game for Claude Code. It's like the browser's offline dinosaur game, but you play as a pixel Claude. It stays hidden until you call it up, for example while Claude works through a long prompt. The only move is a jump: jump over bugs and stacks of failing tests, and time it so you don't jump into a hallucination moth.

 ▄▄▄▄                                          HI 00412  00187
▀▀▀▀▀▀▀                              ▄▄▄▄
     █▀██▀█
    ▀██████▀                  ▀▄██▄▀
     █▀  ▀█                   ▀█▀▀█▀
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Install

Type this at the prompt of a Claude Code terminal session:

/plugin install prompt-runner --marketplace yurmix/prompt-runner

Answer y to add the marketplace, then press Enter to pick the user scope. The plugin is active right away, in the terminal and in the desktop app's Code tab.

Play

Run /prompt-runner to open the game, even while Claude is working. Run it again, or press Esc, to put the game away and get your prompt back.

The game opens in a pane. On the regular screen it sits above the prompt. In fullscreen mode, a terminal at least 110 columns wide shows it beside the transcript instead. Claude Code picks the spot, not the plugin.

Once the game is open, there is one button. It jumps, and it starts the next run after a crash.

  • Keyboard: Space
  • Mouse or touch: click or tap anywhere on the game

If you were typing in the prompt when the game opened, the keyboard stays with the prompt. The game pauses until you click it or press ctrl+x tab, so Space doesn't type spaces into your message. The same thing happens whenever you switch back to the prompt in the middle of a run.

Your best score is saved between sessions.

Open it with one key

The first time the plugin loads, it binds ctrl+x g to /prompt-runner in ~/.claude/keybindings.json and shows a short notice. Claude Code doesn't use ctrl+x g for anything else. After that, ctrl+x g opens the game and closes it again.

It leaves your file alone if ctrl+x g is already taken, if you've already bound /prompt-runner to another key, or if the file isn't plain JSON (it has comments, for example). It only tries once, so if you remove or change the binding, it stays the way you left it.

To bind it yourself, or to pick another key, add this to ~/.claude/keybindings.json:

{
  "bindings": [
    {
      "context": "Chat",
      "bindings": { "ctrl+x g": "command:prompt-runner" }
    }
  ]
}

If the file already has a bindings list, add the block to it. ctrl+d won't work, because Claude Code reserves it for exit.

Obstacles

  • Bug: a small red bug. Jump over it.
  • Bug swarm: two bugs together. They start showing up once you're running fast.
  • Failing test stack: a grey stack, taller than a bug.
  • Hallucination moth: a purple moth. A low one skims the ground, so jump it like a bug. A high one flies over you, so don't jump until it has passed.

The game speeds up as you go, and the score flashes at every 100.

Where it runs

The game uses the Claude Code plugin API's Client element, which only the terminal and the Claude desktop app draw. On the mobile app and VS Code, /prompt-runner opens a note saying so instead.

Development

claude plugin validate .
claude plugin test .

hooks/register.tsx is the hooks module. It adds the /prompt-runner command, opens and closes the game's pane, and keeps the best score. hooks/runner.tsx is the game itself, drawn with half-block characters so each terminal cell holds two pixels.

License

MIT

Source 3 files
hooks/register.tsx 141 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4const isPlaying = atom({ plugin: 'prompt-runner', key: 'isPlaying' } as const, false)
5const best = atom({ plugin: 'prompt-runner', key: 'best' } as const, 0)
6
7const PANE = 'prompt-runner'
8const FOCUS_TRIES = 10
9const FOCUS_EVERY_MS = 100
10
11function openGame($: EngineInterface): Promise<unknown> {
12  return $.ui.open({ id: PANE, title: 'Claude Run', focus: true, closeOnEscape: true, rows: 8 })
13}
14
15// The shortcut the plugin binds for you, once, in ~/.claude/keybindings.json.
16const KEY = 'ctrl+x g'
17const ACTION = 'command:prompt-runner'
18
19type Block = { context?: unknown; bindings?: Record<string, unknown> }
20
21// Adds KEY -> ACTION to the person's keybindings file, unless the action is
22// bound already or KEY is taken in Chat. A file that is not plain JSON (it has
23// comments, say) is left alone. Resolves whether it wrote the binding.
24async function bindKey($: EngineInterface): Promise<boolean> {
25  const dir =
26    (await $.env.get('CLAUDE_CONFIG_DIR')) ??
27    `${(await $.env.get('HOME')) ?? (await $.env.get('USERPROFILE')) ?? ''}/.claude`
28  if (dir === '/.claude') return false
29  const path = `${dir}/keybindings.json`
30
31  let file: { bindings: Block[] } = { bindings: [] }
32  if (await $.fs.exists(path)) {
33    try {
34      const parsed = JSON.parse(await $.fs.read(path)) as { bindings?: unknown }
35      if (!Array.isArray(parsed?.bindings)) return false
36      file = parsed as { bindings: Block[] }
37    } catch {
38      return false
39    }
40  }
41
42  const blocks = file.bindings
43  if (blocks.some(b => Object.values(b?.bindings ?? {}).includes(ACTION))) return false
44  let chat = blocks.find(b => b?.context === 'Chat' && b.bindings && typeof b.bindings === 'object')
45  if (chat?.bindings && KEY in chat.bindings) return false
46  if (!chat) {
47    chat = { context: 'Chat', bindings: {} }
48    blocks.push(chat)
49  }
50  chat.bindings = { ...chat.bindings, [KEY]: ACTION }
51
52  await $.fs.write(path, `${JSON.stringify(file, null, 2)}\n`)
53  return true
54}
55
56export const register: Register = on => {
57  on('session.start', async ($, e, next) => {
58    await $.command.register({
59      name: 'prompt-runner',
60      description: 'Play Claude Run while you wait. Run it again, or press Esc, to put it away',
61      // Runs at once while Claude is working, which is when you want it.
62      immediate: true,
63    })
64    // Bind the shortcut the first time the plugin loads. Only once: if you
65    // remove or change it later, it stays the way you left it.
66    if ((await $.store.get('keyOffered')) !== true) {
67      await $.store.set('keyOffered', true)
68      const bound = await bindKey($).catch(() => false)
69      if (bound) $.ui.toast(`Claude Run: press ${KEY} to play while you wait.`)
70    }
71
72    const saved = Number((await $.store.get('best')) ?? 0)
73    if (Number.isFinite(saved) && saved > 0) {
74      await update($, best, n => Math.max(n ?? 0, saved))
75    }
76
77    return next(e)
78  })
79
80  // /prompt-runner opens the game with the keyboard on it, and closes it if
81  // it is already open. Bind it to a key ("command:prompt-runner") to make
82  // that one press.
83  on('command.run', { command: 'prompt-runner' }, async ($, e) => {
84    if (await read($, isPlaying)) {
85      await $.ui.close({ id: PANE })
86      return { text: 'Claude Run is put away.' }
87    }
88
89    await update($, isPlaying, () => true)
90    await openGame($)
91    // The surface hands a pane the keyboard only over an empty prompt, and the
92    // prompt may still hold the command as it runs. Ask again for a moment
93    // after this answer, until the pane has the keys.
94    void (async () => {
95      for (let i = 0; i < FOCUS_TRIES; i++) {
96        await $.clock.sleep(FOCUS_EVERY_MS)
97        const pane = (await $.ui.panes()).find(p => p.id === PANE)
98        if (!pane || pane.isFocused) return
99        await openGame($)
100      }
101    })().catch(() => {})
102
103    return { text: 'Claude Run is open. Space or a tap jumps. Esc puts it away.' }
104  })
105
106  on('ui.close', { id: PANE }, async ($, e, next) => {
107    await update($, isPlaying, () => false)
108    return next(e)
109  })
110
111  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
112    const top = await read($, best)
113    if (e.surface !== 'terminal' && e.surface !== 'desktop') {
114      const { Text } = $.ui.resolve(e)
115      return <Text dimColor>Claude Run plays in the terminal and the desktop app.</Text>
116    }
117    const { Client } = $.ui.resolve(e)
118
119    return (
120      <Client
121        key="game"
122        module="./runner.tsx"
123        width={e.props.bodyColumns}
124        props={{ best: top, columns: e.props.bodyColumns, autoStart: true, focused: e.props.isFocused }}
125      />
126    )
127  })
128
129  // The game posts { score } when a run ends; keep the best one.
130  on('ui.message', async ($, e, next) => {
131    const data = e.data as { score?: unknown } | null
132    const score = typeof data?.score === 'number' ? Math.floor(data.score) : NaN
133    if (Number.isFinite(score) && score > 0 && score > (await read($, best))) {
134      await update($, best, n => Math.max(n ?? 0, score))
135      await $.store.set('best', score)
136    }
137
138    return next(e)
139  })
140}
141
hooks/runner.tsx 432 lines
1import type { ClientModule, ClientSurface, RenderElement } from 'claude-code'
2
3// Claude Run: a one-button endless runner drawn with half-block characters,
4// so each terminal cell holds two square-ish pixels (top and bottom). The
5// only move is a jump: tap anywhere on touch, or press Space on a keyboard.
6
7type Props = { best?: number; columns?: number; autoStart?: boolean; focused?: boolean }
8
9type Kind = 'bug' | 'bugs' | 'stack' | 'moth' | 'mothHigh'
10type Obstacle = { kind: Kind; x: number; top: number; w: number; hgt: number }
11type Cloud = { x: number; y: number }
12
13type Game = {
14  mode: 'idle' | 'run' | 'over'
15  t: number
16  overAt: number
17  jump: number // pixels above the ground
18  vy: number
19  speed: number
20  dist: number
21  score: number
22  best: number
23  posted: boolean
24  obs: Obstacle[]
25  clouds: Cloud[]
26  gap: number
27  flash: number
28  away: boolean // the keyboard is elsewhere, so the run waits
29}
30
31const TICK_MS = 40
32const FIELD_H = 14 // pixels: 7 rows of cells
33const FEET = 11 // the avatar's lowest pixel row when on the ground
34const GROUND = 12
35const PEBBLES = 13
36const AV_X = 4
37const GRAVITY = 0.32
38const JUMP_V = 2.0
39
40// One character per pixel; '.' is empty.
41const COLORS: Record<string, string> = {
42  O: 'claude',
43  K: '#1b1a18',
44  R: 'error',
45  G: '#9b978f',
46  g: '#6e6a63',
47  P: '#a990f0',
48  c: 'subtle',
49  _: 'inactive',
50}
51
52const BODY = ['.OOOOOO.', '.OKOOKO.', 'OOOOOOOO', '.OOOOOO.']
53const BODY_BLINK = ['.OOOOOO.', '.OOOOOO.', 'OOOOOOOO', '.OOOOOO.']
54const BODY_DEAD = ['.OOOOOO.', '.OROORO.', 'OOOOOOOO', '.OOOOOO.']
55const LEGS_A = ['.OO..OO.', '.O....O.']
56const LEGS_B = ['.OO..OO.', '..O..O..']
57const LEGS_AIR = ['.OO..OO.', '........']
58
59const SPRITES: Record<Kind, string[][]> = {
60  bug: [['R.RR.R', '.RRRR.', 'RRRRRR', '.R..R.']],
61  bugs: [['R.RR.R.R.RR.R', '.RRRR...RRRR.', 'RRRRRR.RRRRRR', '.R..R...R..R.']],
62  stack: [['GGGG', 'gggg', 'GGGG', 'gggg', 'GGGG']],
63  moth: [
64    ['P.....P', '.PPPPP.', '..P.P..'],
65    ['.......', 'PPPPPPP', '..P.P..'],
66  ],
67  mothHigh: [
68    ['P.....P', '.PPPPP.', '..P.P..'],
69    ['.......', 'PPPPPPP', '..P.P..'],
70  ],
71}
72const CLOUD = ['..cccc..', 'cccccccc']
73const CLOUD_W = 8
74
75// The one button: Space, however the host names it.
76const BUTTON_KEYS = new Set([' ', 'space'])
77
78function fresh(best: number): Game {
79  return {
80    mode: 'idle',
81    t: 0,
82    overAt: 0,
83    jump: 0,
84    vy: 0,
85    speed: 1.5,
86    dist: 0,
87    score: 0,
88    best,
89    posted: false,
90    obs: [],
91    clouds: [],
92    gap: 0,
93    flash: 0,
94    away: false,
95  }
96}
97
98function start(g: Game, width: number): void {
99  g.mode = 'run'
100  g.t = 0
101  g.jump = 0
102  g.vy = 0
103  g.speed = 1.5
104  g.dist = 0
105  g.score = 0
106  g.posted = false
107  g.obs = []
108  g.clouds = [
109    { x: Math.floor(width * 0.3), y: 1 },
110    { x: Math.floor(width * 0.75), y: 3 },
111  ]
112  g.gap = width * 0.6
113  g.flash = 0
114}
115
116function makeObstacle(kind: Kind, x: number): Obstacle {
117  const art = SPRITES[kind][0] ?? []
118  const w = art[0]?.length ?? 0
119  const hgt = art.length
120  // A low moth skims the ground, so jump it like a bug. A high moth flies
121  // over a running Claude but meets a jumping one, so don't press.
122  const top = kind === 'moth' ? FEET - hgt : kind === 'mothHigh' ? 1 : FEET - hgt + 1
123  return { kind, x, top, w, hgt }
124}
125
126function pickKind(g: Game): Kind {
127  const roll = Math.random()
128  if (g.score > 150 && roll < 0.2) return Math.random() < 0.6 ? 'moth' : 'mothHigh'
129  if (g.speed > 2.2 && roll < 0.4) return 'bugs'
130  if (g.score > 40 && roll < 0.65) return 'stack'
131  return 'bug'
132}
133
134function avatarBox(g: Game): [number, number, number, number] {
135  const bottom = Math.round(FEET - g.jump)
136  return [AV_X + 1, bottom - 5, AV_X + 6, bottom]
137}
138
139function hits(g: Game, o: Obstacle): boolean {
140  const [ax0, ay0, ax1, ay1] = avatarBox(g)
141  const ox0 = Math.round(o.x) + 1
142  const ox1 = Math.round(o.x) + o.w - 2
143  const oy0 = o.top
144  const oy1 = o.top + o.hgt - 1
145  return ax0 <= ox1 && ax1 >= ox0 && ay0 <= oy1 && ay1 >= oy0
146}
147
148function jump(g: Game): void {
149  if (g.jump <= 0 && g.vy === 0) g.vy = JUMP_V
150}
151
152function step(g: Game, width: number): void {
153  g.t++
154  if (g.mode !== 'run') return
155
156  // Avatar
157  if (g.vy !== 0 || g.jump > 0) {
158    g.jump += g.vy
159    g.vy -= GRAVITY
160    if (g.jump <= 0) {
161      g.jump = 0
162      g.vy = 0
163    }
164  }
165
166  // World
167  g.speed = Math.min(3.6, 1.5 + g.score / 600)
168  g.dist += g.speed
169  const before = Math.floor(g.score / 100)
170  g.score = Math.floor(g.dist * 0.25)
171  if (Math.floor(g.score / 100) > before) g.flash = 24
172  if (g.flash > 0) g.flash--
173
174  for (const o of g.obs) o.x -= g.speed
175  g.obs = g.obs.filter(o => o.x + o.w > -2)
176  for (const c of g.clouds) {
177    c.x -= g.speed * 0.25
178    if (c.x < -CLOUD_W) {
179      c.x = width + Math.random() * 20
180      c.y = 1 + Math.floor(Math.random() * 3)
181    }
182  }
183
184  g.gap -= g.speed
185  if (g.gap <= 0) {
186    g.obs.push(makeObstacle(pickKind(g), width))
187    g.gap = g.speed * 14 + 10 + Math.random() * (g.speed * 22 + 24)
188  }
189
190  for (const o of g.obs) {
191    if (hits(g, o)) {
192      g.mode = 'over'
193      g.overAt = g.t
194      g.best = Math.max(g.best, g.score)
195      break
196    }
197  }
198}
199
200// Drawing ------------------------------------------------------------------
201
202type Pixels = { width: number; height: number; px: (string | undefined)[] }
203
204function canvas(width: number, height: number): Pixels {
205  return { width, height, px: new Array(width * height).fill(undefined) }
206}
207
208function blit(c: Pixels, art: string[], x: number, y: number): void {
209  const x0 = Math.round(x)
210  for (let r = 0; r < art.length; r++) {
211    const py = y + r
212    if (py < 0 || py >= c.height) continue
213    const line = art[r] ?? ''
214    for (let i = 0; i < line.length; i++) {
215      const color = COLORS[line[i] ?? '.']
216      const px = x0 + i
217      if (!color || px < 0 || px >= c.width) continue
218      c.px[py * c.width + px] = color
219    }
220  }
221}
222
223function avatarArt(g: Game): { art: string[]; y: number } {
224  if (g.mode === 'over') {
225    return { art: [...BODY_DEAD, ...LEGS_AIR], y: Math.round(FEET - g.jump) - 5 }
226  }
227  const blink = g.mode === 'idle' && g.t % 90 < 4
228  const body = blink ? BODY_BLINK : BODY
229  const legs =
230    g.mode === 'idle' ? LEGS_A : g.jump > 0 ? LEGS_AIR : Math.floor(g.t / 3) % 2 ? LEGS_A : LEGS_B
231  return { art: [...body, ...legs], y: Math.round(FEET - g.jump) - 5 }
232}
233
234function drawField(g: Game, width: number): Pixels {
235  const c = canvas(width, FIELD_H)
236  for (const cl of g.clouds) blit(c, CLOUD, cl.x, cl.y)
237  for (let x = 0; x < width; x++) {
238    c.px[GROUND * width + x] = COLORS._
239    if ((Math.imul(x + Math.floor(g.dist), 2654435761) >>> 0) % 19 === 0) c.px[PEBBLES * width + x] = COLORS._
240  }
241  for (const o of g.obs) {
242    const frames = SPRITES[o.kind]
243    blit(c, frames[Math.floor(g.t / 6) % frames.length] ?? [], o.x, o.top)
244  }
245  const a = avatarArt(g)
246  blit(c, a.art, AV_X, a.y)
247  return c
248}
249
250type Run = { text: string; fg?: string; bg?: string }
251
252function rowsOf(c: Pixels): Run[][] {
253  const rows: Run[][] = []
254  for (let y = 0; y < c.height; y += 2) {
255    const runs: Run[] = []
256    for (let x = 0; x < c.width; x++) {
257      const top = c.px[y * c.width + x]
258      const bot = y + 1 < c.height ? c.px[(y + 1) * c.width + x] : undefined
259      let ch = ' '
260      let fg: string | undefined
261      let bg: string | undefined
262      if (top && bot) {
263        if (top === bot) {
264          ch = '█'
265          fg = top
266        } else {
267          ch = '▀'
268          fg = top
269          bg = bot
270        }
271      } else if (top) {
272        ch = '▀'
273        fg = top
274      } else if (bot) {
275        ch = '▄'
276        fg = bot
277      }
278      const last = runs[runs.length - 1]
279      if (last && last.fg === fg && last.bg === bg) last.text += ch
280      else runs.push({ text: ch, fg, bg })
281    }
282    rows.push(runs)
283  }
284  return rows
285}
286
287function pad(n: number): string {
288  return String(Math.max(0, Math.floor(n))).padStart(5, '0')
289}
290
291function draw(g: Game, width: number, surface: ClientSurface<Game>): RenderElement {
292  const { Box, Text } = surface.elements
293
294  const paint = (runs: Run[]): RenderElement[] =>
295    runs.map(r =>
296      r.fg && r.bg ? (
297        <Text color={r.fg} backgroundColor={r.bg}>{r.text}</Text>
298      ) : r.fg ? (
299        <Text color={r.fg}>{r.text}</Text>
300      ) : (
301        <Text>{r.text}</Text>
302      ),
303    )
304
305  if (g.mode === 'idle') {
306    // A compact strip: Claude waiting on a patch of ground, and the hint.
307    const c = canvas(12, 8)
308    for (let x = 0; x < 12; x++) c.px[6 * 12 + x] = COLORS._
309    const a = avatarArt(g)
310    blit(c, a.art, 2, a.y - (FEET - 5))
311    const rows = rowsOf(c)
312    const hint =
313      width >= 70
314        ? 'Tap or press Space to play. One button: jump.'
315        : 'Tap or Space to play and jump'
316    return (
317      <Box flexDirection="row">
318        <Box flexDirection="column">
319          {rows.map(runs => (
320            <Box flexDirection="row">{paint(runs)}</Box>
321          ))}
322        </Box>
323        <Box flexDirection="column" paddingLeft={1}>
324          <Text> </Text>
325          <Text bold color="claude">Claude Run</Text>
326          <Text dimColor wrap="truncate-end">{hint}</Text>
327          <Text dimColor>{g.best > 0 ? `Best ${g.best}` : ' '}</Text>
328        </Box>
329      </Box>
330    )
331  }
332
333  const rows = rowsOf(drawField(g, width))
334  const showScore = g.flash === 0 || Math.floor(g.flash / 4) % 2 === 0
335  const scoreText = `HI ${pad(Math.max(g.best, g.score))}  ${showScore ? pad(g.score) : '     '}`
336  const left =
337    g.mode === 'over'
338      ? width >= 60
339        ? 'GAME OVER · tap or press Space to run again'
340        : 'GAME OVER · tap or Space'
341      : g.away
342        ? width >= 60
343          ? 'PAUSED · click here or press ctrl+x tab to play'
344          : 'PAUSED · click or ctrl+x tab'
345        : 'Tap or Space to jump'
346
347  return (
348    <Box flexDirection="column" width={width}>
349      <Box flexDirection="row" justifyContent="space-between">
350        {g.mode === 'over' || g.away ? (
351          <Text bold color="claude" wrap="truncate-end">{left}</Text>
352        ) : (
353          <Text dimColor wrap="truncate-end">{left}</Text>
354        )}
355        <Text color="text">{scoreText}</Text>
356      </Box>
357      {rows.map(runs => (
358        <Box flexDirection="row">{paint(runs)}</Box>
359      ))}
360    </Box>
361  )
362}
363
364const Runner: ClientModule<Props, Game> = (props, surface) => {
365  const width = Math.max(30, surface.columns > 0 ? surface.columns : (props?.columns ?? 60))
366  const known = Math.max(0, props?.best ?? 0)
367
368  let g = surface.state
369  if (g === undefined) {
370    g = fresh(known)
371    const s = surface
372    if (props?.autoStart) start(g, width)
373    s.setState(g)
374
375    // The one button: start, jump, or run again.
376    const press = (): void => {
377      const cur = s.state
378      if (!cur) return
379      const w = Math.max(30, s.columns > 0 ? s.columns : 60)
380      if (cur.mode === 'idle') {
381        start(cur, w)
382      } else if (cur.mode === 'over') {
383        if (cur.t - cur.overAt < 8) return // ignore the press that was mid-flight
384        start(cur, w)
385      } else {
386        jump(cur)
387      }
388      s.setState({ ...cur })
389    }
390
391    s.every(TICK_MS, () => {
392      const cur = s.state
393      if (!cur) return
394      const w = Math.max(30, s.columns > 0 ? s.columns : 60)
395      const wasRunning = cur.mode === 'run'
396      if (wasRunning && cur.away) return // wait for the keyboard to come back
397      step(cur, w)
398      if (cur.mode === 'run') {
399        s.setState({ ...cur })
400      } else if (wasRunning) {
401        // The run just ended: redraw once and report the score.
402        if (!cur.posted && cur.score > 0) {
403          cur.posted = true
404          s.post({ score: cur.score })
405        }
406        s.setState({ ...cur })
407      } else if (cur.mode === 'idle' && (cur.t % 90 === 0 || cur.t % 90 === 4)) {
408        s.setState({ ...cur }) // blink
409      }
410    })
411
412    s.onKey(ev => {
413      if (ev.ctrl || ev.meta) return
414      if (BUTTON_KEYS.has(ev.key.toLowerCase())) press()
415    })
416
417    s.onPointer(ev => {
418      if (ev.type === 'down') press() // a tap or click anywhere
419    })
420  }
421
422  if (known > g.best) g.best = known
423  // Without the keyboard, Space would land in the prompt, so pause the run.
424  g.away = props?.focused === false
425  return draw(g, width, surface)
426}
427
428export default Runner
429
430// Exposed for tests.
431export const _internal = { fresh, start, step, jump, hits, makeObstacle, FEET }
432
types/index.d.ts 14 lines
1/** A best score: whole points. */
2export type Score = number
3
4declare module 'claude-code' {
5  interface PluginState {
6    'prompt-runner': {
7      /** True while the game pane (from /prompt-runner) is open. */
8      isPlaying: boolean
9      /** Best score, also kept in $.store across sessions. */
10      best: Score
11    }
12  }
13}
14