Compact a Claude Code pane and bring it back to work: wait until it is idle, remember its /goal, send /compact, re-seed it with a prompt, then set the goal again.
The goal step exists because /compact clears an active /goal: a peer that is re-seeded with catchup alone finishes catchup, finds no task and stops.
WAITING FOR REST. A job must not type into a working turn, so every step
waits for rest first. A pane busy for ordinary reasons is read at a settled
idle (idle twice, :settle-ms apart); a pane under a /goal Stop hook is read
at its single turn boundary, because the hook restarts the next turn within
a poll and twice-in-a-row can never happen on it (friction 20261116185504:
30 min at :wait-idle, then 337k -> 469k tokens). poll/wait-rest is the one
waiter, so the choice holds across every step of a job.
THE GOAL LOOP (card 20261122170735-7c6f5ad3). Measured on Claude Code
2.1.330: a pane its /goal Stop hook keeps re-prompting shows NO rest at all
(the spinner and its timer run on across turns, running Stop hooks 1/2
at each turn end, then Goal not yet met… continuing), and a /compact
typed into it stays Queued through every re-prompt. A force-sent
(C-x C-s) /compact does run, but the goal stays active and the loop
resumes. So on a pane poll/goal-looping? reads, the job reads the goal
text, types /goal clear (taken in mid-turn, per the /goal docs and as
measured), waits for the settled idle the ended loop gives, compacts,
re-seeds with the goal text inside the re-seed prompt (goal-reseed), and
sets the goal again. :goal-loop false turns it off.
Strata:
Promote due? / ctx-drop / goal-after pure
Pipeline compact! / say! / goal! drive the steps through the host port
(waiting: poll; typing: composer)
Boundary start! / job / jobs one background job per pane
Every effect (tmux, transcript, clock, sleep) goes through the host port, so the whole sequence runs in a test against a scripted screen.
Compact a Claude Code pane and bring it back to work: wait until it is
idle, remember its /goal, send /compact, re-seed it with a prompt, then
set the goal again.
The goal step exists because /compact clears an active /goal: a peer that
is re-seeded with catchup alone finishes catchup, finds no task and stops.
WAITING FOR REST. A job must not type into a working turn, so every step
waits for rest first. A pane busy for ordinary reasons is read at a settled
idle (idle twice, :settle-ms apart); a pane under a /goal Stop hook is read
at its single turn boundary, because the hook restarts the next turn within
a poll and twice-in-a-row can never happen on it (friction 20261116185504:
30 min at :wait-idle, then 337k -> 469k tokens). `poll/wait-rest` is the one
waiter, so the choice holds across every step of a job.
THE GOAL LOOP (card 20261122170735-7c6f5ad3). Measured on Claude Code
2.1.330: a pane its /goal Stop hook keeps re-prompting shows NO rest at all
(the spinner and its timer run on across turns, `running Stop hooks 1/2`
at each turn end, then `Goal not yet met… continuing`), and a /compact
typed into it stays Queued through every re-prompt. A force-sent
(C-x C-s) /compact does run, but the goal stays active and the loop
resumes. So on a pane `poll/goal-looping?` reads, the job reads the goal
text, types `/goal clear` (taken in mid-turn, per the /goal docs and as
measured), waits for the settled idle the ended loop gives, compacts,
re-seeds with the goal text inside the re-seed prompt (`goal-reseed`), and
sets the goal again. :goal-loop false turns it off.
Strata:
Promote due? / ctx-drop / goal-after pure
Pipeline compact! / say! / goal! drive the steps through the host port
(waiting: `poll`; typing: `composer`)
Boundary start! / job / jobs one background job per pane
Every effect (tmux, transcript, clock, sleep) goes through the host port,
so the whole sequence runs in a test against a scripted screen.(after-compact-reason reason {:keys [during]})The :done reason of a compacted job that a later step stopped with REASON
and DATA (compacted-end): a pane that stayed busy (:timeout or :busy)
during step S reads :pane-busy-after-S; any other reason is kept.
The :done reason of a compacted job that a later step stopped with REASON and DATA (`compacted-end`): a pane that stayed busy (:timeout or :busy) during step S reads :pane-busy-after-S; any other reason is kept.
(blocking-view job)What an :already-running refusal says of the BLOCKING job value: its id, kind, status, the first 80 characters of its text, and the step that typed, if one did.
What an :already-running refusal says of the BLOCKING job value: its id, kind, status, the first 80 characters of its text, and the step that typed, if one did.
(boundary-seen before-count boundaries)Evidence from BOUNDARIES (panes/compact-boundaries of the transcript now)
that a compaction finished after the BEFORE-COUNT boundaries there were
when /compact was sent. {:by :compact-boundary :tokens post}, or nil.
Evidence from BOUNDARIES (`panes/compact-boundaries` of the transcript now)
that a compaction finished after the BEFORE-COUNT boundaries there were
when /compact was sent. {:by :compact-boundary :tokens post}, or nil.(cancel! job-id)(cancel! job-id reason)Cancel JOB-ID for REASON (:cancelled by default) if it has not typed yet
(cancel-verdict, decided inside the swap, so it cannot race the job's
first keystroke). The job ends :cancelled, which frees its pane's slot,
and its :on-end runs once with the cancelled job (the tmux-job sense).
{:cancelled? true :job job}, or {:cancelled? false :refuse kw ...} naming
why, e.g. :already-typed with the :step; nil when there is no such job.
Cancel JOB-ID for REASON (:cancelled by default) if it has not typed yet
(`cancel-verdict`, decided inside the swap, so it cannot race the job's
first keystroke). The job ends :cancelled, which frees its pane's slot,
and its :on-end runs once with the cancelled job (the tmux-job sense).
{:cancelled? true :job job}, or {:cancelled? false :refuse kw ...} naming
why, e.g. :already-typed with the :step; nil when there is no such job.(cancel-job job reason now-ms)JOB cancelled at NOW-MS for REASON, when cancel-verdict allows it; JOB
unchanged otherwise.
JOB cancelled at NOW-MS for REASON, when `cancel-verdict` allows it; JOB unchanged otherwise.
(cancel-verdict job)May JOB (a job value) be cancelled now? {:cancel? true}, or a refusal: :already-typed with the :step that typed first (a keystroke reached the pane, so cancelling would leave half a command there), :already-cancelled, or :not-active with the job's :status (it ended on its own).
May JOB (a job value) be cancelled now? {:cancel? true}, or a refusal:
:already-typed with the :step that typed first (a keystroke reached the
pane, so cancelling would leave half a command there), :already-cancelled,
or :not-active with the job's :status (it ended on its own).(cancelled? job)Has JOB been cancelled? Terminal: nothing the job's runner writes after
it may change its status (job-consistent?, the state atom's validator,
enforces it).
Has JOB been cancelled? Terminal: nothing the job's runner writes after it may change its status (`job-consistent?`, the state atom's validator, enforces it).
(claim-typing job step-key)JOB about to type its STEP-KEY step: records the first step that types
(:typed-step), after which cancel-verdict refuses. A cancelled JOB is
returned unchanged, and must not type.
JOB about to type its STEP-KEY step: records the first step that types (:typed-step), after which `cancel-verdict` refuses. A cancelled JOB is returned unchanged, and must not type.
(compact! h state ref opts)Compact the pane REF names, through host H, recording progress in STATE
(an atom). OPTS: see defaults, plus :force? (ignore the threshold),
:instructions (text after /compact), :goal (replace the goal) and
:goal-append (extend it). Returns STATE's final value.
The /compact step ends on proof that the compaction ran (send-and-compact!),
never on a screen marker. A compaction proven while the pane then stays busy
(someone else gave it work) is :done with :reason :pane-busy-after-compact
and the texts it did not type under :unsent: the recycle worked, and typing
into a working pane is what this job never does.
ONCE :compacted IS RECORDED THE JOB CANNOT FAIL. Every later wait for rest
is advisory (stop!, compacted-end): a pane still busy after the
re-seed, because the /goal is still in force and its Stop hook leaves no turn
boundary, ends :done :pane-busy-after-reseed. What the step would have
failed with is kept under :advisory, the texts not typed go under :unsent,
and :reseed-pending / :goal-pending say which (friction
20261121201539-4a5836cb: cc-04c4ee28 and cc-804a41e1 compacted 463k ->
151k, then ended failed timeout). A job that never compacted still
fails as before.
REST: see the namespace docstring. Nothing here lands on a running turn.
Compact the pane REF names, through host H, recording progress in STATE (an atom). OPTS: see `defaults`, plus :force? (ignore the threshold), :instructions (text after /compact), :goal (replace the goal) and :goal-append (extend it). Returns STATE's final value. The /compact step ends on proof that the compaction ran (`send-and-compact!`), never on a screen marker. A compaction proven while the pane then stays busy (someone else gave it work) is :done with :reason :pane-busy-after-compact and the texts it did not type under :unsent: the recycle worked, and typing into a working pane is what this job never does. ONCE :compacted IS RECORDED THE JOB CANNOT FAIL. Every later wait for rest is advisory (`stop!`, `compacted-end`): a pane still busy after the re-seed, because the /goal is still in force and its Stop hook leaves no turn boundary, ends :done :pane-busy-after-reseed. What the step would have failed with is kept under :advisory, the texts not typed go under :unsent, and :reseed-pending / :goal-pending say which (friction 20261121201539-4a5836cb: cc-04c4ee28 and cc-804a41e1 compacted 463k -> 151k, then ended `failed timeout`). A job that never compacted still fails as before. REST: see the namespace docstring. Nothing here lands on a running turn.
(compacted-end job reason stop)(compacted-end job reason stop last)JOB, which recorded :compacted, stopped by a LATER step: :done all the same, since the compaction is what the job is for (friction 20261121201539-4a5836cb). REASON says why the rest did not go out; STOP, what that step would have failed or skipped with, is kept under :advisory, never as an :error; LAST is the pane's screen state (else STOP's :last). The texts not typed are under :unsent, :reseed-pending and :goal-pending name which. A goal the pane shows active is not pending: it is in force.
JOB, which recorded :compacted, stopped by a LATER step: :done all the same, since the compaction is what the job is for (friction 20261121201539-4a5836cb). REASON says why the rest did not go out; STOP, what that step would have failed or skipped with, is kept under :advisory, never as an :error; LAST is the pane's screen state (else STOP's :last). The texts not typed are under :unsent, :reseed-pending and :goal-pending name which. A goal the pane shows active is not pending: it is in force.
(ctx-drop before row drop-ratio)Evidence from ROW that a compaction ran: its context fell below DROP-RATIO of BEFORE tokens. {:by :ctx-drop :tokens n}, or nil.
Evidence from ROW that a compaction ran: its context fell below DROP-RATIO
of BEFORE tokens. {:by :ctx-drop :tokens n}, or nil.(due? row threshold)Should ROW be compacted at THRESHOLD tokens?
Should ROW be compacted at THRESHOLD tokens?
(goal! h state ref opts)Set the /goal of the pane REF names without compacting it: OPTS :goal
replaces, :goal-append extends the pane's active goal (read from its
transcript). Claude Code takes /goal in while a turn runs, so the job
never waits for an idle (a busy /goal pane may never give one); a dialog
or an unreadable screen stops it, and text at the prompt is waited out up
to :input-timeout-ms (deliver!). :done only once the footer shows THIS
goal active (goal-confirmed?); else :failed :goal-unconfirmed.
Set the /goal of the pane REF names without compacting it: OPTS :goal replaces, :goal-append extends the pane's active goal (read from its transcript). Claude Code takes /goal in while a turn runs, so the job never waits for an idle (a busy /goal pane may never give one); a dialog or an unreadable screen stops it, and text at the prompt is waited out up to :input-timeout-ms (`deliver!`). :done only once the footer shows THIS goal active (`goal-confirmed?`); else :failed :goal-unconfirmed.
(goal-after {:keys [goal goal-append]} captured)The goal to set after the re-seed. GOAL (an override) wins over CAPTURED; APPEND is added to whichever applies. Nil when there is nothing to set.
The goal to set after the re-seed. GOAL (an override) wins over CAPTURED; APPEND is added to whichever applies. Nil when there is nothing to set.
(goal-command? text)Is TEXT a /goal ... command? Claude Code takes /goal in at once, even
while a turn runs, so it is the one send that needs no rest.
Is TEXT a `/goal ...` command? Claude Code takes /goal in at once, even while a turn runs, so it is the one send that needs no rest.
(goal-confirmed? goal before-row before-count row lines)Is GOAL proven set on ROW after the /goal send? The footer must show a goal active AND it must be the goal just sent: a /goal entry for it in the transcript after the BEFORE-COUNT lines there were at the send, or a footer age back to seconds where BEFORE-ROW showed no seconds-old goal (a busy pane may write the entry only when its turn ends). A footer that was already there proves nothing, and a busy pane is not an acknowledgement.
Is GOAL proven set on ROW after the /goal send? The footer must show a goal active AND it must be the goal just sent: a /goal entry for it in the transcript after the BEFORE-COUNT lines there were at the send, or a footer age back to seconds where BEFORE-ROW showed no seconds-old goal (a busy pane may write the entry only when its turn ends). A footer that was already there proves nothing, and a busy pane is not an acknowledgement.
(goal-free? row)May a /goal be typed into the pane of ROW now? It is a readable Claude
prompt (a context count is shown), with no one's text in the composer and
no dialog on screen. A working turn does not matter: /goal is accepted
while busy (the pane's footer shows /goal active (3s) at once).
May a /goal be typed into the pane of ROW now? It is a readable Claude prompt (a context count is shown), with no one's text in the composer and no dialog on screen. A working turn does not matter: /goal is accepted while busy (the pane's footer shows `/goal active (3s)` at once).
(goal-loop-on? opts)Does OPTS let a job take the goal-loop path (:goal-loop, default :auto)?
Does OPTS let a job take the goal-loop path (`:goal-loop`, default :auto)?
(goal-reseed reseed goal)The re-seed RESEED of a job that cleared a looping /goal to compact the pane, carrying the GOAL text, so the session reads what it was working toward even before the /goal is set again (the next send). RESEED alone when there is no goal; nil when there is no re-seed.
The re-seed RESEED of a job that cleared a looping /goal to compact the pane, carrying the GOAL text, so the session reads what it was working toward even before the /goal is set again (the next send). RESEED alone when there is no goal; nil when there is no re-seed.
(human-guard row)Why nothing may be typed into the pane of ROW now, for a human's sake, or
nil when nothing stops it (the human-draft guard, card
20261122160537-60f33c7a):
{:reason :open-dialog ...} a dialog is open (open-dialog?)
{:reason :human-typing :input text} someone's text stands at the prompt
Nothing lifts it: :force? skips a compaction's threshold, never a person,
and an interrupt holds on a draft too (interrupt/verdict). A job either
keeps waiting (queued, :waiting-on) or ends :skipped with this :reason.
Why nothing may be typed into the pane of ROW now, for a human's sake, or
nil when nothing stops it (the human-draft guard, card
20261122160537-60f33c7a):
{:reason :open-dialog ...} a dialog is open (`open-dialog?`)
{:reason :human-typing :input text} someone's text stands at the prompt
Nothing lifts it: :force? skips a compaction's threshold, never a person,
and an interrupt holds on a draft too (`interrupt/verdict`). A job either
keeps waiting (queued, :waiting-on) or ends :skipped with this :reason.Is ROW a Claude pane at rest? See poll/idle?.
Is ROW a Claude pane at rest? See `poll/idle?`.
(job job-id)The current state of JOB-ID, or nil.
The current state of JOB-ID, or nil.
(job-consistent? job)The job invariant a job's state atom validates: once cancelled (it carries :cancelled-at), a job stays :cancelled. A runner still waiting when its job was cancelled therefore cannot write a later status over it: the write is refused and the runner stops there.
The job invariant a job's state atom validates: once cancelled (it carries :cancelled-at), a job stays :cancelled. A runner still waiting when its job was cancelled therefore cannot write a later status over it: the write is refused and the runner stops there.
(job-text {:keys [kind opts]})The text JOB would type, as a supervisor reads it: the prompt of a say, the /goal of a goal, the /compact (with instructions) of a compaction.
The text JOB would type, as a supervisor reads it: the prompt of a say, the /goal of a goal, the /compact (with instructions) of a compaction.
(open-dialog? row)Is a dialog open on the pane of ROW? Its screen shows a menu or permission dialog (:dialog), or Claude Code's own session status is :waiting: the session waits on a human's answer. A :waiting pane shows no spinner, so it reads idle, and a job that trusted idle alone would type into the dialog.
Is a dialog open on the pane of ROW? Its screen shows a menu or permission dialog (:dialog), or Claude Code's own session status is :waiting: the session waits on a human's answer. A :waiting pane shows no spinner, so it reads idle, and a job that trusted idle alone would type into the dialog.
(record-step! pane-id step)Append an external STEP to the active job on PANE-ID, without starting or displacing it. Returns the updated job, or nil when the pane has no active job. Used by menu answers, which do not own the pane's job slot.
Append an external STEP to the active job on PANE-ID, without starting or displacing it. Returns the updated job, or nil when the pane has no active job. Used by menu answers, which do not own the pane's job slot.
(say! h state ref opts)Submit OPTS :text to the pane REF names as one prompt. Waits for a settled
idle first unless :wait-idle? is false (then a busy pane is skipped). Done
once the pane starts working on it, or settles: the reply itself can take
an hour, read it later with read. Text at the prompt stops the job at
once: a say is not queued behind someone's draft.
Submit OPTS :text to the pane REF names as one prompt. Waits for a settled idle first unless :wait-idle? is false (then a busy pane is skipped). Done once the pane starts working on it, or settles: the reply itself can take an hour, read it later with `read`. Text at the prompt stops the job at once: a say is not queued behind someone's draft.
(screen-state row)What a timeout reports of the pane's last ROW: enough for a supervisor to tell a slow pane from a stuck one without reading the screen itself.
What a timeout reports of the pane's last ROW: enough for a supervisor to tell a slow pane from a stuck one without reading the screen itself.
(start! ref {:keys [sync? on-end supersede?] :as opts})Start a background job on the pane REF names. OPTS :kind is :compact (default), :say or :goal. Returns the job map at once, or {:error ...} when that pane already has a running job. The job follows the pane by its tmux id, which /compact does not change. OPTS :on-end, a fn of the final job map, runs once when the job ends (how the watcher turns it into a sense). Pass :host in OPTS to use another port (tests); :sync? true runs in the caller.
A job cancelled (cancel!) before its first keystroke ends :cancelled:
its state refuses any later status (job-consistent?), its runner stops at
its next wait (cancellable-host), and :on-end runs once, from cancel!.
:already-running names the blocking job (blocking-view) and hints
supersede. OPTS :supersede? true cancels that job (reason :superseded) when
it has not typed, and takes the slot; one that typed refuses :already-typed
naming the step, and nothing is started.
Start a background job on the pane REF names. OPTS :kind is :compact
(default), :say or :goal. Returns the job map at once, or {:error ...} when
that pane already has a running job. The job follows the pane by its tmux
id, which /compact does not change. OPTS :on-end, a fn of the final job
map, runs once when the job ends (how the watcher turns it into a sense).
Pass :host in OPTS to use another port (tests); :sync? true runs in the
caller.
A job cancelled (`cancel!`) before its first keystroke ends :cancelled:
its state refuses any later status (`job-consistent?`), its runner stops at
its next wait (`cancellable-host`), and :on-end runs once, from `cancel!`.
:already-running names the blocking job (`blocking-view`) and hints
supersede. OPTS :supersede? true cancels that job (reason :superseded) when
it has not typed, and takes the slot; one that typed refuses :already-typed
naming the step, and nothing is started.(start-refusal kind opts row)Why a KIND job with OPTS would stop at once on the pane whose row is ROW,
without typing: {:reason kw ...}, or nil when it would go on to work.
The same cheap checks the runners make first (compact!, start-row,
say!), so a supersede cancels the blocking job only for a job that will
actually run.
Why a KIND job with OPTS would stop at once on the pane whose row is ROW,
without typing: {:reason kw ...}, or nil when it would go on to work.
The same cheap checks the runners make first (`compact!`, `start-row`,
`say!`), so a supersede cancels the blocking job only for a job that will
actually run.(unsent-after job)The sends JOB planned after its /compact (:sends-planned, [{:step k :text t}]) that no step records as sent: [[k text] ...], in order.
The sends JOB planned after its /compact (:sends-planned, [{:step k
:text t}]) that no step records as sent: [[k text] ...], in order.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |