Run each chunk in its own tmux window, up to parallel-chunks at once, and mark a window that waits
CI / tests (pull_request) Failing after 2m56s

This commit is contained in:
2026-11-16 11:59:45 +01:00
parent 7fc64d860a
commit eecb0387ca
28 changed files with 883 additions and 209 deletions
-46
View File
@@ -1,46 +0,0 @@
"""The slot a loop holds in its project, so that loops of one project, each on its own chunk, run side by side, each in a session named after its slot."""
import dataclasses
import os
import pathlib
from failure import Failure
from machine_load.slots import first_free_slot
from loop_claude.loop.reload import LoopRun
from loop_state.paths import Paths
from transcript_archive.project_key import project_key
from claude_code.session import Session, session_named, session_open
# Under the home folder, a folder per project key holds a file per slot, which a running loop keeps locked with flock.
SLOTS = ".local/state/loop-claude"
# A bound no project reaches. Once todo.md item 375 lands, the project's config sets how many loops run at once.
MOST = 64
def held_slot(home: pathlib.Path, key: str, claude_code_transcripts: pathlib.Path) -> int | Failure:
"""The slot this loop takes, or why it could take none: the lowest free slot whose session is open, so that a rerun resumes a chunk left open, or else the lowest free slot. The loop holds it until it exits; a reload's exec keeps the lock."""
folder = home / SLOTS / key
order = sorted(range(MOST), key=lambda slot: not session_open(session_named(session_name(key, slot), claude_code_transcripts)))
try:
folder.mkdir(parents=True, exist_ok=True)
taken = first_free_slot(folder, order)
except OSError as failure:
return Failure(f"cannot take a slot in {folder}: {failure.strerror}")
if taken is None:
return Failure(f"{MOST} loops of this project are running already; `fuser {folder}/slot-*` names them")
slot, fd = taken
os.set_inheritable(fd, True)
return slot
def session_name(key: str, slot: int) -> str:
""""A " is the human's cue in the session picker that the session is the loop's. Slot 0 keeps the name every loop had before slots, so a chunk left open before slots resumes in it."""
return f"A {key} loop-claude" if slot == 0 else f"A {key} loop-claude {slot + 1}"
def slotted(loop_run: LoopRun, paths: Paths) -> tuple[LoopRun, Session] | Failure:
"""loop_run holding its slot, and the worker's session, named after the slot. A reloaded script keeps the slot it is handed."""
key = project_key(loop_run.root, paths.home)
slot = held_slot(paths.home, key, paths.claude_code_transcripts) if loop_run.slot is None else loop_run.slot
if isinstance(slot, Failure):
return slot
return dataclasses.replace(loop_run, slot=slot), session_named(session_name(key, slot), paths.claude_code_transcripts)
+11 -7
View File
@@ -7,6 +7,8 @@ from release_plan.release_standing import DefaultPlan, project_plan, UNSEEN_RELE
from loop_effects.effects import Effects, say
from failure import Failure
from loop_claude.routing import first_route, kept, routed_item
from loop_claude.loop.chunk_windows import held_beside, item_of
from chunk_preflight.main import ITEM
from plan_store.stores import held_at, Plan, store as plan_store
from release_plan.todo_table import Item
from model_routing.ladder import Ladder, Rung
@@ -61,15 +63,17 @@ def archived_route(archive_folder: pathlib.Path, loop: Loop) -> Route | None:
def chunk_start(loop: Loop) -> tuple[str, typing.Callable[[], Item | None]]:
"""The facts for a fresh worker's prompt, empty where the session is open, and the reader of the item that routes the chunk. The reader reads the default branch as last fetched: for a fresh chunk, by the preflight that runs first; for an open session, which runs none, by whatever fetched last."""
facts = "" if session_open(loop.session) else chunk_facts(loop)
return facts, lambda: plan_item(fetched_plan(loop), loop.effects)
return facts, lambda: plan_item(fetched_plan(loop), item_of(loop.window.name), loop.effects)
def chunk_facts(loop: Loop) -> str:
"""What `chunk-preflight --worktree` printed at the checkout root, for a fresh worker's prompt, or why it could not run."""
done = loop.effects.python([str(loop.launcher.with_name("chunk-preflight")), "--worktree"], loop.root)
"""What `chunk-preflight --worktree` printed at the checkout root, for a fresh worker's prompt, or why it could not run. The chunk of a window named for an item starts from that item, and the facts end with the items the project's other running chunks hold."""
item = item_of(loop.window.name)
done = loop.effects.python([str(loop.launcher.with_name("chunk-preflight")), "--worktree", *([] if item is None else [ITEM, str(item)])], loop.root)
if done.returncode:
return prompts.preflight_failed(done.stderr.strip() or f"it exited {done.returncode}")
return prompts.preflight_facts(done.stdout.strip())
held = held_beside(loop.window.name, loop.root, loop.paths, loop.effects)
return prompts.preflight_facts(done.stdout.strip()) + (prompts.held_by_others(held) if held else "")
def fetched_plan(loop: Loop) -> DefaultPlan | Failure:
@@ -83,13 +87,13 @@ def fetched_plan(loop: Loop) -> DefaultPlan | Failure:
return ref if isinstance(ref, Failure) else project_plan(config, ref, loop.root, loop.effects.git)
def plan_item(plan: DefaultPlan | Failure, effects: Effects) -> Item | None:
"""The item that routes a chunk, release_standing.chunk_item's pick from the default branch; None without one, so the chunk runs on the project's rung."""
def plan_item(plan: DefaultPlan | Failure, window_item: int | None, effects: Effects) -> Item | None:
"""The item that routes a chunk: the one its window is named for, or else release_standing.chunk_item's pick from the default branch; None without one, so the chunk runs on the project's rung."""
# It prints the reason itself, through effects, like the other loop-claude functions that print. todo.md item 51 moves them all to one injected effect, so changing this one alone would be undone.
if isinstance(plan, Failure):
item: Item | Failure | None = plan
else:
item = routed_item(plan.todo, plan.cut)
item = routed_item(plan.todo, plan.cut, window_item)
if isinstance(item, Failure):
say(f"routing on the project's rung: {item.reason}", effects)
return None
+138
View File
@@ -0,0 +1,138 @@
"""The chunks of one project that run at once, each in its own tmux window: which may start now, and how each starts (docs/decisions.md → `loop-claude: each chunk runs in its own tmux window`)."""
import contextlib
import fcntl
import pathlib
import re
import typing
from chunk_preflight.choices import planned
from chunk_preflight.gathered import NoItem, Plan
from claude_code.session import Session, session_named, transcript_file
from claude_code.transcript import read_transcript
from failure import Failure
from git_cli.git_repo import default_ref
from loop_claude import tmux
from loop_claude.cycle import chunk_items
from loop_claude.loop.reload import LoopRun
from loop_effects.effects import Effects, say
from loop_state.paths import Paths
from project_config.main import located
from release_plan.release_standing import project_plan
from touch_predictions.beside import Beside, chunks_beside
from transcript_archive.project_key import project_key
# Under the home folder, a folder per project key holds LOCK.
STATE = ".local/state/loop-claude"
# The file a loop keeps locked with flock while it lists the project's windows and starts new ones, so two loops whose chunks finish together start no chunk twice.
LOCK = "starting"
# loop-claude's own flag: the loop it starts in a window is told its chunk by it, as `--chunk item-372`. Nobody types it, so no panel picked it.
CHUNK_FLAG = "--chunk"
# The chunk of a plan that names no item for the next chunk: a release to plan, a release review, or a task outside the plan.
NO_ITEM = "no-item"
# Seconds a fetch of origin may take before a chunk starts; past them, the plan reads as last fetched.
FETCH_TIMEOUT = 60
# The variables loop-claude reads. A window gets the tmux server's environment, not the starting terminal's, so they are handed to each window by name.
HANDED = "LOOP_CLAUDE_"
def window_name(item_id: int) -> str:
return f"item-{item_id}"
def item_of(chunk: str) -> int | None:
"""The ID of the plan item a chunk starts from; None for NO_ITEM."""
named = re.fullmatch(r"item-([0-9]+)", chunk, re.ASCII)
return int(named[1]) if named else None
def chunk_session(key: str, chunk: str, claude_code_transcripts: pathlib.Path) -> Session:
"""The worker's session for a chunk. A rerun finds a chunk left open by this name. "A " is the human's cue in the session picker that the session is the loop's."""
return session_named(f"A {key} loop-claude {chunk}", claude_code_transcripts)
@contextlib.contextmanager
def starting(home: pathlib.Path, key: str) -> typing.Iterator[None]:
"""Holds the project's LOCK. Raises OSError where the file cannot be opened or locked."""
folder = home / STATE / key
folder.mkdir(parents=True, exist_ok=True)
with open(folder / LOCK, "a") as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
yield
def held_items(chunks: typing.Iterable[str], key: str, claude_code_transcripts: pathlib.Path) -> set[int]:
"""The plan items these chunks hold: the one each started from, and those its worker names on its latest `Chunk items:` line so far. A chunk whose transcript cannot be read holds the item it started from."""
held = set()
for chunk in chunks:
held.update(filter(None, [item_of(chunk)]))
transcript = transcript_file(chunk_session(key, chunk, claude_code_transcripts))
entries = read_transcript(transcript) if transcript else []
held.update([] if isinstance(entries, Failure) else chunk_items.named(entries))
return held
def may_start(plan: Plan | NoItem, running: list[str], held: set[int], limit: int) -> list[str]:
"""The chunks to start now, beside those running, whose items are held: the plan's next item and the items touch_predictions picks to run beside it, in the plan's order, less each a running chunk holds, up to limit chunks at once. A plan without an item starts NO_ITEM, and only alone."""
if isinstance(plan, NoItem):
return [] if running else [NO_ITEM]
beside = chunks_beside(plan.items, plan.first)
picked = [plan.first.id, *(beside.picked if isinstance(beside, Beside) else [])]
return [window_name(item_id) for item_id in picked if item_id not in held][: max(limit - len(running), 0)]
def next_plan(root: str, home: pathlib.Path, effects: Effects) -> Plan | NoItem | Failure:
"""The plan on the default branch, fetched now where origin answers, with its next item, as chunk-preflight reads it."""
config = located(root, home)
if isinstance(config, Failure):
return config
# A chunk that just merged left the plan on origin. A fetch that fails leaves the plan as last fetched, which chunk-preflight then reads too.
effects.git("fetch", "--quiet", "origin", cwd=root, timeout=FETCH_TIMEOUT)
ref = default_ref(root, FETCH_TIMEOUT, run=effects.git)
if isinstance(ref, Failure):
return ref
held = project_plan(config, ref, root, effects.git)
return planned(held.todo, held.cut, ref, config.branch, None if config.tracked("plan") else config.plan_label)
def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Mapping[str, str], launcher: pathlib.Path, effects: Effects) -> list[str] | Failure:
"""Starts a loop-claude in a new window for each chunk of loop_run's project that may start now, and returns the chunks started. leaving says that loop_run's own chunk finished, so its window no longer counts as running. A plan that cannot be read starts NO_ITEM, as a plan without an item does. A Failure says why none could start."""
config = located(loop_run.root, paths.home)
if isinstance(config, Failure):
return config
key = project_key(loop_run.root, paths.home)
session = tmux.session_name(key)
handed = {name: value for name, value in env.items() if name.startswith(HANDED)}
try:
with starting(paths.home, key):
windows = tmux.listed(session, effects.tmux)
running = [window.name for window in windows if not window.dead and not (leaving and window.name == loop_run.chunk)]
if len(running) >= config.parallel_chunks:
return []
plan = next_plan(loop_run.root, paths.home, effects)
if isinstance(plan, Failure):
# As in a checkout without a default branch. The chunk's worker is told why its preflight failed, and finds the facts itself.
say(f"starting a chunk without a plan item, since the plan cannot be read: {plan.reason}", effects)
plan = NoItem(plan.reason)
chunks = may_start(plan, running, held_items(running, key, paths.claude_code_transcripts), config.parallel_chunks)
for chunk in chunks:
# The window of a loop that failed stays, dead, until its chunk starts again.
stale = [window for window in windows if window.name == chunk and window.dead]
for window in stale:
tmux.close(window, effects.tmux)
windows = [window for window in windows if window not in stale]
command = [str(launcher), CHUNK_FLAG, chunk, loop_run.task]
if failed := tmux.start_window(tmux.Window(session, chunk, ""), loop_run.root, handed, command, not windows, effects.tmux):
return failed
windows.append(tmux.Listed(chunk, "", False))
return chunks
except OSError as failure:
return Failure(f"cannot lock {paths.home / STATE / key / LOCK}: {failure.strerror}")
def held_beside(chunk: str, root: str, paths: Paths, effects: Effects) -> list[int]:
"""The plan items that the project's other running chunks hold now, which a chunk starting as `chunk` leaves to them. It waits for a loop that is starting windows, so chunks started together see each other. Where the lock cannot be taken, it reads the windows without it."""
key = project_key(root, paths.home)
with contextlib.suppress(OSError), starting(paths.home, key):
pass
others = [window.name for window in tmux.listed(tmux.session_name(key), effects.tmux) if not window.dead and window.name != chunk]
return sorted(held_items(others, key, paths.claude_code_transcripts))
+45 -11
View File
@@ -20,7 +20,9 @@ from transcript_archive.project_key import project_key
from model_routing.ladder_file import project_ladder_file, read_ladder, SHIPPED
from loop_claude.project.premises import read_premises
from loop_claude.project.records import read_records
from loop_claude.loop.chunk_slot import slotted
from loop_claude.loop.chunk_windows import CHUNK_FLAG, chunk_session, start_chunks
from loop_claude import tmux
from loop_claude.verdicts import Finished
from loop_claude.stop import Stop
from loop_claude.direct_message import tell
@@ -35,8 +37,8 @@ def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
raise
if stop.reason:
say(stop.reason, effects, stdout=not stop.code)
# Every stop but the human's own Ctrl-C and the help is DMed where the project's config can be read and sets `env-file`, so a loop left overnight never ends unseen. A loop given no task prints the help.
if stop.code != 130 and stop.reason != HELP:
# Every stop with a reason, but the human's own Ctrl-C and the help, is DMed where the project's config can be read and sets `env-file`, so a loop left overnight never ends unseen. A loop given no task prints the help. One that started the project's windows, or whose chunk finished and handed on to the next, stops without a reason: the project's chunks go on.
if stop.code != 130 and stop.reason not in ("", HELP):
tell(f"loop-claude in {cwd} stopped: {stop.reason}", effects)
return stop.code
@@ -45,12 +47,18 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
loop_run = loop_run_from(argv, cwd, effects)
if isinstance(loop_run, Stop):
return loop_run
# Before anything starts: a worktree, a session or a window.
if reason := tmux.unusable(effects.tmux):
return Stop(1, reason)
if loop_run.chunk is None:
return windows_opened(loop_run, env, paths, launcher, effects)
pane = env.get("TMUX_PANE")
if not pane:
return Stop(1, f"{CHUNK_FLAG} is how loop-claude starts itself in a tmux window; run loop-claude <task>")
baseline = fingerprint(launcher)
held = slotted(loop_run, paths)
if isinstance(held, Failure):
return Stop(1, held.reason)
loop_run, session = held
loop = Loop(root=loop_run.root, session=session, paths=paths, env=env, launcher=launcher, effects=effects)
key = project_key(loop_run.root, paths.home)
window = tmux.Window(tmux.session_name(key), loop_run.chunk, pane)
loop = Loop(root=loop_run.root, session=chunk_session(key, loop_run.chunk, paths.claude_code_transcripts), window=window, paths=paths, env=env, launcher=launcher, effects=effects)
while True:
if stop := exec_if_edited(loop, baseline, loop_run):
return stop
@@ -68,6 +76,31 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
# Off the ladder the worker runs on the project's model itself, which its route names.
if stop := check_routing(archive_root(paths.home, env), cycle.project or cycle.route.rung, loop):
return stop
if isinstance(concluded.verdict, Finished):
return handed_on(loop_run, loop)
def windows_opened(loop_run: LoopRun, env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects) -> Stop:
"""What the loop-claude the human runs does: starts each chunk that may start now in a window of the project's tmux session, then puts that session on the terminal until the human detaches."""
started = start_chunks(loop_run, False, paths, env, launcher, effects)
if isinstance(started, Failure):
return Stop(1, started.reason)
session = tmux.session_name(project_key(loop_run.root, paths.home))
say(f"started {', '.join(started)} in the tmux session {session}" if started else f"the tmux session {session} runs every chunk that may run now", effects, stdout=True)
if not effects.on_terminal():
say(f"not on a terminal; see the chunks with `tmux attach -t ={session}`", effects, stdout=True)
return Stop(0, "")
shown = tmux.show(session, "TMUX" in env)
return Stop(1, f"`tmux {' '.join(shown)}` failed; the chunks go on in the session") if effects.tmux_on_terminal(shown) else Stop(0, "")
def handed_on(loop_run: LoopRun, loop: Loop) -> Stop:
"""The stop of a loop whose chunk finished, once it has started each chunk that may start now. Its window closes as it exits."""
started = start_chunks(loop_run, True, loop.paths, loop.env, loop.launcher, loop.effects)
if isinstance(started, Failure):
return Stop(1, f"the chunk finished, but the next could not start: {started.reason}")
say(f"the chunk finished; started {', '.join(started) or 'no other, since the chunks running fill what may run now'}", loop.effects, stdout=True)
return Stop(0, "")
def next_cycle(loop_run: LoopRun, loop: Loop) -> Cycle | Stop:
@@ -96,7 +129,7 @@ def next_cycle(loop_run: LoopRun, loop: Loop) -> Cycle | Stop:
if ladder_file != SHIPPED:
say(own_ladder(ladder_file, models.worker, project is None), loop.effects)
todo = fetched_todo(loop)
return Cycle(config=setup_version(loop.paths.claude_dir, loop.effects.git), effects=loop.effects, facts=facts, judge_model=models.judge, ladder=ladder, premises=premises, project=project, project_archive=archive_folder, records=records, root=loop.root, route=route, session=loop.session, task=loop_run.task, todo=todo, unfinished_evidence=loop_run.unfinished_evidence)
return Cycle(config=setup_version(loop.paths.claude_dir, loop.effects.git), effects=loop.effects, facts=facts, judge_model=models.judge, ladder=ladder, premises=premises, project=project, project_archive=archive_folder, records=records, root=loop.root, route=route, session=loop.session, task=loop_run.task, window=loop.window, todo=todo, unfinished_evidence=loop_run.unfinished_evidence)
def own_ladder(file: pathlib.Path, model: str, unrouted: bool) -> str:
@@ -107,11 +140,12 @@ def own_ladder(file: pathlib.Path, model: str, unrouted: bool) -> str:
def loop_run_from(argv: list[str], cwd: pathlib.Path, effects: Effects) -> LoopRun | Stop:
if argv[:1] != [RELOAD_FLAG]:
task = " ".join(argv)
chunk, words = (argv[1], argv[2:]) if len(argv) > 2 and argv[0] == CHUNK_FLAG else (None, argv)
task = " ".join(words)
if task in ("", "-h", "--help"):
return Stop(0 if task else 1, HELP)
root = checkout_root(cwd, effects)
return root if isinstance(root, Stop) else LoopRun(0, root, task, "")
return root if isinstance(root, Stop) else LoopRun(0, root, task, "", chunk=chunk)
loop_run = decode_handed(argv[1]) if len(argv) == 2 else None
if not (loop_run and loop_run.root and loop_run.task):
return Stop(1, f"the edited loop-claude cannot read the state the running one handed it, likely because the edit changed that handover; rerun loop-claude <task>. Handed: {' '.join(argv[1:])}")
+5 -3
View File
@@ -25,8 +25,8 @@ class LoopRun:
route: Route | None = None
# How many unfinished verdicts the chunk has had running; a finished chunk and a rerun each set it to 0. It stays apart from route and unfinished_evidence, though all three change together at each verdict: merging or renaming a field stops a running loop at its next reload.
unfinished_run: int = 0
# The project's slot this loop holds (chunk_slot.py); None until it takes one. A loop started before slots reloads with None, and so takes a slot then.
slot: int | None = None
# The chunk this loop runs in its tmux window, as chunk_windows names it: `item-372`, or `no-item`. None for the loop-claude the human started, which starts the windows; a loop started before chunks ran in windows reloads with None too, and so moves its chunk into one.
chunk: str | None = None
class Unreadable(Exception):
@@ -40,8 +40,10 @@ def decode_handed(handed: str) -> LoopRun | None:
except ValueError:
return None
# A loop started before 0.11.0 hands the items loop-inbox listed; dropping them keeps it running across its reload.
# One started before chunks ran in tmux windows hands the slot it held.
if isinstance(fields, dict):
fields.pop("items_taken_in", None)
fields.pop("slot", None)
try:
return LoopRun(**decoded_fields(fields, LOOP_RUN_FIELDS, "cycle_number", "root", "task", "unfinished_evidence"))
except Unreadable:
@@ -77,7 +79,7 @@ def decoded_route(value: object) -> Route | None:
# One decoder per field of LoopRun, which a test holds to the dataclass's fields: a field missing here stops a loop at the reload after it joined.
LOOP_RUN_FIELDS = {"cycle_number": exactly(int), "root": exactly(str), "task": exactly(str), "unfinished_evidence": exactly(str), "route": decoded_route, "unfinished_run": exactly(int), "slot": lambda value: None if value is None else exactly(int)(value)}
LOOP_RUN_FIELDS = {"cycle_number": exactly(int), "root": exactly(str), "task": exactly(str), "unfinished_evidence": exactly(str), "route": decoded_route, "unfinished_run": exactly(int), "chunk": lambda value: None if value is None else exactly(str)(value)}
def fingerprint(launcher: pathlib.Path) -> str:
+3
View File
@@ -5,6 +5,7 @@ import typing
from loop_effects.effects import Effects
from loop_state.paths import Paths
from claude_code.session import Session
from loop_claude.tmux import Window
@dataclasses.dataclass(frozen=True)
@@ -14,6 +15,8 @@ class Loop:
root: str
# The worker's session.
session: Session
# The tmux window the loop runs in.
window: Window
paths: Paths
env: typing.Mapping[str, str]
# The loop-claude script, whose edits reload the loop and beside which chunk-preflight lies.
+29 -11
View File
@@ -26,7 +26,9 @@ remaining. The next chunk starts a fresh session. Cycles continue until an exit
Words: ~/.claude/CLAUDE.md → "Vocabulary".
A question only the human can answer is an interrupt (bin/loop_claude/cycle/interrupt.py).
loop-claude prints the question on its terminal, where the human answers it:
loop-claude prints the question in the chunk's window and rings its bell. Until it is answered the
window's name ends in " ?", as in "item-372 ?", which tmux's status bar shows. The human answers
it there:
- A line of text: the worker resumes headless with it. The judge reads it as the human's, so the
chunk stays unfinished until the answer is recorded.
- /talk: opens the worker's session with `claude --resume` on the terminal, to read the diff or
@@ -34,20 +36,33 @@ loop-claude prints the question on its terminal, where the human answers it:
- Enter alone: stops the loop.
A release ready to cut opens that session on the terminal at once, since only the human may cut it.
While claude is open, Ctrl-C reaches it alone, and the loop goes on.
Where the project's config sets notifier, loop-claude also sends the human each question, each
release ready to cut and each stop as a DM, as bin/notify sends it. Two stops are
left out: Ctrl-C, and printing this help. A DM that fails is said on stderr, and the loop goes on.
Where the project's config sets notifier, loop-claude also sends the human each question, naming
its window as <session>:<window>, each release ready to cut and each stop as a DM, as bin/notify
sends it. Four stops are left out: Ctrl-C, printing this help, the loop-claude that started the
windows, and a loop whose chunk finished. A DM that fails is said on stderr, and the loop goes on.
As a chunk starts, before it is routed, loop-claude runs bin/chunk-preflight --worktree and quotes
what it prints in the first prompt (prompts.preflight_facts in bin/loop_claude/cycle/prompts.py);
chunk-preflight --help says what it finds and makes. A preflight that fails, or is still running
chunk-preflight --help says what it finds and makes. For a window named for an item it adds
--item <ID>. A preflight that fails, or is still running
after 600 s and is stopped, leaves the worker to find the facts itself.
Loops of one project run side by side, each on one chunk at a time. Each holds a slot of the
project, the file slot-<n> under ~/.local/state/loop-claude/<key>/, locked while the loop runs.
<key> is the checkout's path relative to ~/code, or to / outside it. A loop takes the lowest free
slot whose session is open, so a rerun resumes a chunk left open, or else the lowest free slot.
slot-0's session is named "A <key> loop-claude", and slot-<n>'s "A <key> loop-claude <n+1>".
Each chunk runs in its own window of one tmux session per project, named loop-<key>, such as
loop-claude-config. <key> is the checkout's path relative to ~/code, or to / outside it, with a
dash for each character tmux reads as a separator. loop-claude <task> starts the chunks that may
start now, then attaches to the session, or switches to it inside tmux; detaching leaves the chunks
running. Off a terminal it prints the command that attaches. Up to parallel-chunks chunks run at
once, a whole number the project's config sets, 1 by default. The first starts from the plan's next
item, and each other from an item whose `Touches:` prediction overlaps none before it
(touch-predictions --help). A window is named for the item its chunk starts from, as item-372; a
chunk without a plan item, such as planning a release or its release review, runs alone in the
window no-item. Each window runs a loop-claude for that one chunk, started with --chunk <window>,
which nobody types. As a chunk finishes, its loop starts each chunk that may start then and exits,
which closes its window. The window of a loop that failed stays, with its last lines, until its
chunk starts again. A chunk's session is named "A <key> loop-claude <window>", so a rerun resumes a
chunk left open. A fresh worker is told the items the other running chunks hold, each chunk's own
and those on its latest `Chunk items:` line, and leaves them out. loop-claude needs tmux 3.2 or
later, and checks it before it starts anything.
The session is deleted when its chunk finishes. At every
interrupt, and as every cycle ends, Ctrl-C and a failure included, the session's transcript is
copied into a folder per chunk under $LOOP_CLAUDE_TRANSCRIPTS/<key> (default root
@@ -116,7 +131,10 @@ loop-claude --help succeeds: the loop reloads into the edited script.
Exit 1, saying why, when:
- no task is given
- git cannot start or finds no checkout
- its slot in the project cannot be taken
- tmux is missing or older than 3.2
- --chunk is given outside a tmux window
- a chunk's window cannot be started, as when the plan or the project's config cannot be read
- the tmux session cannot be put on the terminal
- the goals file, or AGENTS.md, docs/decisions.md, ~/.claude/CLAUDE.md, ~/.claude/rules/*.md or
the project's review standards where they exist, cannot be read or is not UTF-8
- no config names the checkout, its config cannot be read, or the goals file holds no premises