SLOPSHOPPER

relay

Role buttons above the prompt: check or adversarially review the working tree with Codex, hand a task over to Codex, or verify with a second Claude model. A…

panebandcommandtoastprocesstimer
v0.1.5MITupdated 2026-10-20hal-9/claude-mods/mods/relay
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · relay
│ ┃ relay ✕ › fix the failing auth test and add an audit log call │ ┃ No runs yet. Press c, a, h or v in the band, │ ┃ or /relay. ⏺ Read(src/auth.ts) │ ⎿ Read 6 lines │ ⏺ 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 │ │ › /relay │ ⎿ relay: relay: check | adversarial | hand <task> | verify │ │ ▾ relay [ check ] [ adversarial ] [ hand over ] [ verify ] ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
▾ relay [ check ] [ adversarial ] [ hand over ] [ verify ]
Pane · relay
No runs yet. Press c, a, h or v in the band, or /relay.
README

relay

Role buttons for Claude Code: let the model that writes the code hand parts of the job to other models, Pi-style, from a band above the prompt.

ButtonHotkeyWhat runs
checkccodex-companion review on the working tree, in the background
adversarialacodex-companion adversarial-review (challenges the design, not just defects)
hand overhfills the composer with /relay hand so you type the task; runs codex-companion task --write
verifyva Claude subagent on the verifyModel (default opus) that reviews and runs tests, read-only

A pane (relay) lists the last three runs: elapsed time and the Codex log tail while running; the verdict, summary and findings when done. Each finding has fix (submits a prompt to the main agent with the finding and Codex's recommendation) and dismiss; fix all sends every finding at once. A task's or verifier's output gets pull into Claude.

/relay check | adversarial | hand <task> | verify does the same from the prompt.

Install

/plugin install relay --marketplace hal-9/claude-mods

Requirements

  • The openai-codex plugin installed and codex set up (/codex:setup). relay drives its scripts/codex-companion.mjs and shares its job state, so /codex:status and /codex:result see relay's runs too.
  • node on PATH.

Settings

  • codexPluginRoot: folder holding scripts/codex-companion.mjs; empty means ~/.claude/plugins/marketplaces/openai-codex/plugins/codex.
  • codexModel: passed as --model; empty means Codex's default.
  • verifyModel: Claude alias or id for the verify subagent.

Develop

Validate and test with the engine build the types came from (the desktop app's binary, not necessarily the claude on PATH):

claude plugin validate <folder>
claude plugin test <folder>

Hotkeys work while the band or pane holds the focus (ctrl+x tab, or a click).

Source 2 files
hooks/register.tsx 329 lines
1import type { EngineInterface, PluginOptions, Register } from 'claude-code'
2
3import type { Finding, Job, Role } from '../types'
4
5const JOBS = { plugin: 'relay', key: 'jobs' } as const
6const COLLAPSED = { plugin: 'relay', key: 'collapsed' } as const
7
8const PANE = 'relay'
9const POLL_MS = 2500
10const LOG_TAIL = 1200
11const PROMPT_CAP = 8000
12
13type $ = EngineInterface
14
15const LABEL: Record<Role, string> = {
16  check: 'codex review',
17  adversarial: 'codex adversarial',
18  hand: 'codex task',
19  verify: 'claude verify',
20}
21
22const VERIFY_PROMPT = `You are the verifier of another agent's work. Review the uncommitted changes in this working tree (git status, git diff, untracked files) against what they appear to be meant to do. Run the tests that cover the touched code when they exist.
23Do not edit any file.
24Reply with: VERDICT: pass or fail, one line why; then one line per problem as "severity | file:line | title | why | suggested fix".`
25
26const minutes = (ms: number) => `${Math.floor(ms / 60_000)}:${String(Math.floor((ms % 60_000) / 1000)).padStart(2, '0')}`
27
28const fixPrompt = (job: Job, list: Finding[]) =>
29  `[relay] ${LABEL[job.role]} found ${list.length} issue${list.length === 1 ? '' : 's'} in the working tree. Fix ${list.length === 1 ? 'it' : 'them'}, then say what you changed.\n\n` +
30  list
31    .map(f => `- (${f.severity}) ${f.file}${f.line_start ? `:${f.line_start}` : ''}: ${f.title}\n  ${f.body}${f.recommendation ? `\n  Suggested: ${f.recommendation}` : ''}`)
32    .join('\n')
33
34const pullPrompt = (job: Job) =>
35  `[relay] Result of ${LABEL[job.role]}. Read it, then continue the work in this working tree accordingly.\n\n${(job.output ?? '').slice(0, PROMPT_CAP)}`
36
37let companion: string[] = []
38let env: Record<string, string> = {}
39let opts: PluginOptions = {}
40
41// Helpers take $ and may only spell $.noun.method on it, so they use $.state directly; the hooks use read/update.
42async function getJobs($: $): Promise<Job[]> {
43  return (await $.state.get(JOBS)).value ?? []
44}
45
46async function setJob($: $, id: string, patch: Partial<Job>) {
47  const list = await getJobs($)
48  await $.state.set(JOBS, list.map(j => (j.id === id ? { ...j, ...patch } : j)))
49}
50
51async function removeJob($: $, id: string) {
52  await $.state.set(JOBS, (await getJobs($)).filter(j => j.id !== id))
53}
54
55async function addJob($: $, job: Job) {
56  const list = await getJobs($)
57  await $.state.set(JOBS, [job, ...list].slice(0, 20))
58  void $.ui.open({ id: PANE, title: 'relay' })
59}
60
61async function run($: $, args: string[], timeoutMs = 60_000) {
62  const { exitCode, stdout, stderr } = await $.process.run([...companion, ...args, '--json'], { env, timeoutMs })
63  if (exitCode !== 0) throw new Error(stderr.trim() || `codex-companion exited ${exitCode}`)
64  return JSON.parse(stdout) as Record<string, any>
65}
66
67// Collapsed or not, remembered across sessions.
68async function setCollapsed($: $, isCollapsed: boolean) {
69  await $.state.set(COLLAPSED, isCollapsed)
70  await $.store.set('collapsed', isCollapsed)
71}
72
73const toastError = ($: $, error: unknown) => $.ui.toast(`relay: ${error instanceof Error ? error.message : String(error)}`)
74
75// A review runs inside the companion's own process until it is done (`--background` only queues tasks), so the
76// call is left running for up to ten minutes and the job is adopted from the companion's listing once it is on disk.
77async function adopt($: $, role: 'check' | 'adversarial', known: Set<string>) {
78  try {
79    const { running } = (await run($, ['status'])) as { running?: { id: string; logFile?: string }[] }
80    const fresh = (running ?? []).find(j => !known.has(j.id))
81    if (!fresh) return $.ui.toast(`relay: ${LABEL[role]} did not start`)
82    await addJob($, { id: fresh.id, role, status: 'running', startedAt: await $.clock.now(), log: '', logFile: fresh.logFile })
83  } catch (error) {
84    toastError($, error)
85  }
86}
87
88async function startCodex($: $, role: 'check' | 'adversarial' | 'hand', extra: string[]) {
89  const model = String(opts.codexModel ?? '')
90  const modelArgs = model ? ['--model', model] : []
91  if (role === 'hand') {
92    try {
93      const payload = await run($, ['task', '--background', ...modelArgs, ...extra])
94      await addJob($, { id: String(payload.jobId), role, status: 'running', startedAt: await $.clock.now(), log: '' })
95    } catch (error) {
96      toastError($, error)
97    }
98    return
99  }
100  const known = new Set((await getJobs($)).map(j => j.id))
101  void run($, [role === 'check' ? 'review' : 'adversarial-review', ...modelArgs, ...extra], 600_000).catch(error => toastError($, error))
102  $.clock.after(1500, () => void adopt($, role, known))
103}
104
105async function startVerify($: $) {
106  const { agentId, deny } = await $.agent.spawn({
107    prompt: VERIFY_PROMPT,
108    description: 'relay verify',
109    subagentType: 'general-purpose',
110    model: String(opts.verifyModel || 'opus'),
111  })
112  if (deny !== undefined || agentId === undefined) {
113    $.ui.toast(`relay: verify refused: ${deny ?? 'no agent'}`)
114    return
115  }
116  await addJob($, { id: agentId, role: 'verify', status: 'running', startedAt: await $.clock.now(), log: '' })
117}
118
119async function finish($: $, job: Job) {
120  const { storedJob } = await run($, ['result', job.id])
121  const parsed = storedJob?.result?.result
122  const output: string = storedJob?.result?.rawOutput || storedJob?.result?.codex?.stdout || storedJob?.rendered || ''
123  await setJob($, job.id, {
124    status: 'done',
125    verdict: parsed?.verdict,
126    summary: parsed?.summary ?? storedJob?.result?.parseError,
127    findings: parsed?.findings,
128    output,
129  })
130  const n = parsed?.findings?.length
131  $.ui.toast(`relay: ${LABEL[job.role]} done${n === undefined ? '' : `, ${n} finding${n === 1 ? '' : 's'}`}`)
132}
133
134// The engine's own PATH may lack a version-managed node (nvm, asdf): ask the login shell once.
135async function nodePath($: $): Promise<string> {
136  try {
137    await $.process.run(['node', '--version'])
138    return 'node'
139  } catch {}
140  const shell = (await $.env.get('SHELL')) || '/bin/zsh'
141  try {
142    const { exitCode, stdout } = await $.process.run([shell, '-lic', 'command -v node'])
143    if (exitCode === 0 && stdout.trim()) return stdout.trim().split('\n').pop() ?? 'node'
144  } catch {}
145  return 'node'
146}
147
148// ponytail: one poll loop over the companion's status; a log-file watch if polling ever feels slow.
149let isPolling = false
150async function poll($: $) {
151  if (isPolling) return
152  isPolling = true
153  try {
154    const running = (await getJobs($)).filter(j => j.status === 'running' && j.role !== 'verify')
155    for (const job of running) {
156      try {
157        const { job: snap } = await run($, ['status', job.id])
158        const logFile: string | undefined = snap?.logFile ?? job.logFile
159        let log = job.log
160        if (logFile) {
161          try {
162            log = (await $.fs.read(logFile)).slice(-LOG_TAIL)
163          } catch {}
164        }
165        if (snap?.status === 'completed') await finish($, { ...job, logFile })
166        else if (snap?.status === 'failed' || snap?.status === 'cancelled') {
167          await setJob($, job.id, { status: 'failed', log, summary: snap.errorMessage ?? snap.status })
168          $.ui.toast(`relay: ${LABEL[job.role]} ${snap.status}`)
169        } else await setJob($, job.id, { log, logFile })
170      } catch (error) {
171        await setJob($, job.id, { status: 'failed', summary: error instanceof Error ? error.message : String(error) })
172      }
173    }
174  } finally {
175    isPolling = false
176  }
177}
178
179export const register: Register = (on, options) => {
180  opts = options
181
182  on('session.start', async ($, e, next) => {
183    const home = (await $.env.get('HOME')) ?? ''
184    const root = String(options.codexPluginRoot || '') || `${home}/.claude/plugins/marketplaces/openai-codex/plugins/codex`
185    companion = [await nodePath($), `${root}/scripts/codex-companion.mjs`]
186    env = { CLAUDE_PLUGIN_DATA: `${home}/.claude/plugins/data/codex-openai-codex` }
187    await $.state.set(COLLAPSED, (await $.store.get('collapsed')) === true)
188    await $.command.register({ name: 'relay', description: 'relay check | adversarial | hand <task> | verify | pane' })
189    $.clock.every(POLL_MS, () => void poll($))
190    return next(e)
191  })
192
193  on('command.run', { command: 'relay' }, async ($, e) => {
194    const [verb, ...rest] = (e.args ?? '').trim().split(/\s+/)
195    const task = rest.join(' ')
196    if (verb === 'check' || verb === 'adversarial') void startCodex($, verb, [])
197    else if (verb === 'hand' && task) void startCodex($, 'hand', ['--write', task])
198    else if (verb === 'verify') void startVerify($)
199    else {
200      await $.ui.open({ id: PANE, title: 'relay' })
201      return { text: 'relay: check | adversarial | hand <task> | verify' }
202    }
203    return { text: `relay: ${verb} started.` }
204  })
205
206  on('turn.complete', async ($, e, next) => {
207    if (e.agentId !== undefined) {
208      const job = (await getJobs($)).find(j => j.id === e.agentId && j.status === 'running')
209      if (job) {
210        await setJob($, job.id, { status: 'done', output: e.answer, verdict: /VERDICT:\s*pass/i.test(e.answer) ? 'pass' : 'fail' })
211        $.ui.toast(`relay: claude verify done`)
212      }
213    }
214    return next(e)
215  })
216
217  // The desktop drops a press whose handler runs past ~10 s, and a Codex start can take that long: presses only schedule the work.
218  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
219    if (e.props.hasSurvey) return next(e)
220    const ui = $.ui.resolve(e)
221    const { Box, Button, Text } = ui
222    const now = await $.clock.now()
223    const running = (await getJobs($)).filter(j => j.status === 'running')
224    const { value: isCollapsed = false } = await $.state.get(COLLAPSED)
225    // Another mod's band (cache-meter) rides along above the buttons; the engine's own band is empty.
226    const below = await next(e)
227    const isDesktop = e.surface !== 'terminal' && 'Svg' in ui
228    const w = Math.max(180, Math.min(1600, (e.props.bodyColumns || 100) * 8 - 96))
229    // A hairline between that band and the buttons; 9px tall with the line centred, since a 1px image scaled to the slot rounds away.
230    const divider = isDesktop ? (
231      <ui.Svg
232        source={`<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="9" viewBox="0 0 ${w} 9" preserveAspectRatio="none"><style>rect{fill:#00000026}@media (prefers-color-scheme: dark){rect{fill:#ffffff38}}</style><rect y="4" width="${w}" height="1"/></svg>`}
233        alt="separator"
234        width={w}
235        height={9}
236      />
237    ) : (
238      <Text dimColor>{'─'.repeat(Math.max(8, (e.props.bodyColumns || 100) - 2))}</Text>
239    )
240
241    return (
242      <Box flexDirection="column" gap={isDesktop ? 'sm' : 'xs'}>
243        {below.type !== 'engine' && below}
244        {below.type !== 'engine' && divider}
245      <Box key="band" hover={{ backgroundColor: '#8080801a' }}>
246        <Button
247          key="toggle"
248          plain
249          dimColor
250          hover={{ dimColor: false, bold: true }}
251          label={`${isCollapsed ? '▸' : '▾'} relay${isCollapsed && running.length ? ` · ${running.length} running` : ''} `}
252          onPress={() => void setCollapsed($, !isCollapsed)}
253        />
254        {!isCollapsed && running.map(j => (
255          <Text key={j.id}>
256            {LABEL[j.role]} <Text dimColor>{minutes(now - j.startedAt)}</Text>{' '}
257          </Text>
258        ))}
259        {!isCollapsed && [
260          <Button key="check" hotkey="c" label="check" dimColor onPress={() => $.clock.after(0, () => void startCodex($, 'check', []))} />,
261          <Text key="gap-0"> </Text>,
262          <Button key="adversarial" hotkey="a" label="adversarial" dimColor onPress={() => $.clock.after(0, () => void startCodex($, 'adversarial', []))} />,
263          <Text key="gap-1"> </Text>,
264          <Button key="hand" hotkey="h" label="hand over" dimColor onPress={() => $.prompt.fill({ text: '/relay hand ', mode: 'insert' })} />,
265          <Text key="gap-2"> </Text>,
266          <Button key="verify" hotkey="v" label="verify" dimColor onPress={() => $.clock.after(0, () => void startVerify($))} />,
267        ]}
268      </Box>
269      </Box>
270    )
271  })
272
273  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
274    const { Box, Button, Text } = $.ui.resolve(e)
275    const list = await getJobs($)
276    const now = await $.clock.now()
277    const rows = Math.max(6, (e.viewport?.rows ?? 24) - 6)
278
279    const dismiss = (job: Job, f: Finding) =>
280      setJob($, job.id, { findings: (job.findings ?? []).filter(x => x !== f) })
281
282    return (
283      <Box flexDirection="column">
284        {list.length === 0 && <Text dimColor>No runs yet. Press c, a, h or v in the band, or /relay.</Text>}
285        {list.slice(0, 3).map(job => (
286          <Box key={job.id} flexDirection="column" marginBottom={1}>
287            <Box>
288              <Text bold>{LABEL[job.role]}</Text>
289              <Text dimColor>
290                {' '}{job.status === 'running' ? minutes(now - job.startedAt) : job.status}
291                {job.verdict ? ` · ${job.verdict}` : ''}
292              </Text>
293              <Text> </Text>
294              {job.status === 'running' && job.role !== 'verify' && (
295                <Button key={`cancel-${job.id}`} label="cancel" dimColor onPress={() => $.clock.after(0, () => void run($, ['cancel', job.id]).catch(() => undefined))} />
296              )}
297              {job.status !== 'running' && (
298                <Button key={`clear-${job.id}`} label="clear" dimColor onPress={() => removeJob($, job.id)} />
299              )}
300            </Box>
301            {job.status === 'running' && job.log && (
302              <Text dimColor>{job.log.split('\n').slice(-rows).join('\n')}</Text>
303            )}
304            {job.summary && <Text>{job.summary}</Text>}
305            {(job.findings ?? []).map((f, i) => (
306              <Box key={`${job.id}-${i}`}>
307                <Text color={/critical|high/.test(f.severity) ? 'red' : /medium/.test(f.severity) ? 'yellow' : undefined}>{f.severity}</Text>
308                <Text> {f.file}{f.line_start ? `:${f.line_start}` : ''} {f.title} </Text>
309                <Button key={`fix-${job.id}-${i}`} label="fix" onPress={() => $.prompt.submit({ text: fixPrompt(job, [f]) })} />
310                <Text> </Text>
311                <Button key={`drop-${job.id}-${i}`} label="dismiss" dimColor onPress={() => dismiss(job, f)} />
312              </Box>
313            ))}
314            {job.status === 'done' && (job.findings?.length ?? 0) > 1 && (
315              <Button key={`fixall-${job.id}`} variant="primary" label="fix all" onPress={() => $.prompt.submit({ text: fixPrompt(job, job.findings ?? []) })} />
316            )}
317            {job.status === 'done' && !job.findings && job.output && (
318              <Box flexDirection="column">
319                <Text dimColor>{job.output.slice(-LOG_TAIL)}</Text>
320                <Button key={`pull-${job.id}`} variant="primary" label="pull into Claude" onPress={() => $.prompt.submit({ text: pullPrompt(job) })} />
321              </Box>
322            )}
323          </Box>
324        ))}
325      </Box>
326    )
327  })
328}
329
types/index.d.ts 37 lines
1/** The role a run plays, in Pi's words. */
2export type Role = 'check' | 'adversarial' | 'hand' | 'verify'
3
4export type Finding = {
5  severity: string
6  title: string
7  body: string
8  file: string
9  line_start: number | null
10  recommendation: string
11}
12
13/** One run of a role: a Codex companion job or a Claude verifier subagent. */
14export type Job = {
15  /** Companion job id, or the subagent's agentId. */
16  id: string
17  role: Role
18  status: 'running' | 'done' | 'failed'
19  startedAt: number
20  /** Last lines of the Codex log while running. */
21  log: string
22  /** Review results, once done. */
23  verdict?: string
24  summary?: string
25  findings?: Finding[]
26  /** A task's or verifier's final text, once done. */
27  output?: string
28  /** Path of the companion's log file, polled while running. */
29  logFile?: string
30}
31
32declare module 'claude-code' {
33  interface PluginState {
34    relay: { jobs: Job[]; collapsed: boolean }
35  }
36}
37