Throwaway probe for the factory loop: can an agent a mod spawns from a timer call that mod's own tool?

A software factory that runs inside a single Claude Code session.
How it works · Architecture · Docs · Releases
<img alt="The factory as a session in the Claude app: the loop asks the model whether to cut a release, and the session title shows the issues queued, in flight and merged" src="docs/images/hero-light.svg" width="744"> <sub>The session title is a live status board: Q queued · D in flight · M merged</sub>
Label a GitHub issue ready. The factory designs it, builds it, reviews it and merges it. When it needs a decision, it asks you - on the issue, or in the Claude app on your phone.
Most agent factories put a program in charge and call Claude for each task. Others hand one model the whole job and let it improvise. This one puts the program inside the Claude session.
/factory pause, priority or drop.flowchart LR
you(["You"])
gh["GitHub<br/>issues, pull requests, CI"]
app["Claude app<br/>phone, desktop, terminal"]
you ==>|"create issues, label them ready"| gh
you -.->|"optional: ask, steer, answer"| app
subgraph factory["The factory: one Claude Code session"]
loop["Loop (code)<br/>plans and acts every minute"]
model["Model<br/>judgment and owner chat"]
agents["Agents<br/>design, build, review, fix"]
loop -->|wakes| model
loop --> agents
end
gh <-->|"claims issues, merges PRs"| loop
app <-.-> model
Writing issues is enough: the factory picks up anything labelled ready and comes back with a merged pull request. The Claude app is there for when you want to talk to it.
<img alt="The line: an issue moves from queued through design, build, review and the merge queue to merged; review sends changes to fix and back, and a stuck issue is parked with a question for you, then requeued when you answer" src="docs/images/pipeline-light.svg" width="744">
| Command | What it does | ||
|---|---|---|---|
status | The last pass and the directives in force | ||
pause <N> / unpause <N> | No action at all on an issue, though its claim still renews | ||
skip <N> / noskip <N> | Never claim an issue | ||
priority <N...> | Claim these first, in order | ||
only <N...> | Claim only these, in order | ||
| `serial on\ | off` | One issue in flight at a time | |
| `new on\ | off` | Off starts no new claims, designs or implementations | |
resume <N> | Release a hold on an issue or a run | ||
retry <N> | Let an issue's exhausted actions run again | ||
drop <N> | Abandon an issue and stop its agents | ||
| `note [<N>] <text>\ | off` | An instruction the next agent prompts carry; a newer note replaces the older one, off clears it | |
| `mode off\ | observe\ | act` | Switch the loop off, to watching only, or to acting |
| `trace on\ | off` | Detailed per-pass timing records |
The full list, with every option, is in the factory loop README.
plan(state, config) does no I/O and reads no clock, so recorded days of events can be replayed through it.[!NOTE] A factory runs in a Coder workspace built from this repo's
orchestrator-looptemplate: the base image, a factory database and the factory-loop plugins.Where we're heading is simpler: install a plugin, type one command, and the session you're in becomes the factory. Set up a factory.
This evolved from my own setup, which relies heavily on Coder, a Docker swarm to run the workloads, and a few other things. I hope to soon have the capacity to make it more general, and I'm open to learning how someone else would want to run it.
| Page | Read it for |
|---|---|
| Factory loop | Running and steering the loop, /factory commands |
| Factory loop v2 spec | States, steps, failure handling, the merge queue |
| Onboarding | Making a repo a dev-system repo |
| Architecture | Layers, versioning, the runtime map |
| Base image | The environment every workspace runs |
| Factory database and metrics | Standing up the database; measuring the factory |
| Releasing | Cutting a release |
hooks/register.ts 65 lines1// Throwaway probe for the factory loop (docs/factory-loop/v2/SPEC.md 13.13, #560, #561): can an agent
2// that a mod spawns with $.agent.spawn call that mod's own tool? The loop's passes run from its
3// timer, so its agents are spawned from a $.clock callback; on Claude Code 2.1.296 and 2.1.299
4// such an agent's call fails in milliseconds with "<plugin> registered the tool ... but no
5// tool.call hook answered this call" and the hook never runs, while the same spawn made inside a
6// command.run hook works. That is why the loop's agents answer through the checked answer script
7// (config answerChannel `script`, a temporary workaround) and not through the registered answer
8// tools (`tool`, the intended design).
9//
10// Run it on each Claude Code upgrade, in a throwaway session:
11//
12// claude --plugin-dir docs/factory-loop/probes/timer-spawn-probe
13// /timer-spawn-probe
14//
15// It spawns one agent inside the command's own hook (`hook`, the control) and one from a
16// $.clock.after callback (`timer`, the loop's case); each loads the probe's tool with ToolSearch,
17// calls it and replies with its result. Every observation is one JSON line in
18// ${CLAUDE_CONFIG_DIR:-~/.claude}/timer-spawn-probe/log.jsonl: `spawned` per case, `called` when
19// the tool hook runs (with the caller's agentId), and `answered` with each agent's reply.
20// answerChannel can go back to `tool` once the timer agent's reply is `pong` and its `called`
21// line is there. On 2.1.299 (2026-10-14) the timer agent replied with the engine's refusal above,
22// and no `called` line came.
23import type { EngineInterface, Register } from 'claude-code'
24
25const ASK = 'Use ToolSearch with query select:mcp__timer-spawn-probe__ping, then call mcp__timer-spawn-probe__ping with {} and reply with the exact tool result text only.'
26const cases = new Map<string, string>()
27
28async function log($: EngineInterface, check: string, fields: Record<string, unknown> = {}) {
29 const dir = `${(await $.env.get('CLAUDE_CONFIG_DIR')) || `${(await $.env.get('HOME')) || '~'}/.claude`}/timer-spawn-probe`
30 const line = JSON.stringify({ at: new Date(await $.clock.now()).toISOString(), check, ...fields }) + '\n'
31 await $.process.run(['sh', '-c', 'mkdir -p "$(dirname "$1")" && cat >> "$1"', 'sh', `${dir}/log.jsonl`], { stdin: line, timeoutMs: 10_000 }).catch(() => undefined)
32}
33
34async function spawn($: EngineInterface, via: 'hook' | 'timer') {
35 const r = await $.agent.spawn({ subagentType: 'timer-spawn-probe:pinger', description: `ping probe (${via})`, prompt: ASK })
36 if (r.agentId !== undefined) cases.set(r.agentId, via)
37 await log($, 'spawned', { via, agentId: r.agentId ?? null, deny: r.deny ?? null })
38}
39
40export const register: Register = on => {
41 on('session.start', async ($, e, next) => {
42 const r = await next(e)
43 await $.tool.register({ name: 'ping', description: 'Answers pong. Call it when asked.', inputSchema: { type: 'object', properties: {} } })
44 await $.command.register({ name: 'timer-spawn-probe', description: 'spawn one agent from this hook and one from a timer; each calls the probe tool' })
45 return r
46 })
47
48 on('tool.call', { tool: 'mcp__timer-spawn-probe__ping' }, async ($, e) => {
49 await log($, 'called', { agentId: e.agentId ?? null, via: e.agentId === undefined ? null : (cases.get(e.agentId) ?? 'unknown') })
50 return { result: 'pong' }
51 }).catch(() => ({ deny: 'timer-spawn-probe: the hook failed' }))
52
53 on('command.run', { command: 'timer-spawn-probe' }, async $ => {
54 await spawn($, 'hook')
55 $.clock.after(500, () => void spawn($, 'timer').catch(err => log($, 'spawned', { via: 'timer', error: String(err) })))
56 return { text: 'timer-spawn-probe: one agent spawned from this hook, one from a timer; see log.jsonl' }
57 })
58
59 on('turn.complete', async ($, e, next) => {
60 const r = await next(e)
61 if (e.agentId !== undefined && cases.has(e.agentId)) await log($, 'answered', { via: cases.get(e.agentId), agentId: e.agentId, answer: e.answer.slice(0, 500) })
62 return r
63 }).catch(($, e, next) => next(e))
64}
65