Automatic compaction after completed work

Settings → Auto compact is shared by TUI, browser and desktop. Automatic compaction is off by default. A user's global defaults can be overridden for a Project, then for an individual Claude, Codex or Antigravity session. Each field inherits independently; Inherit all removes the selected override.

The controller stores the policies, and the execution host evaluates them in its independent live-session observer. Closing the console or disconnecting the laptop does not stop this automation. The controller and host-agent must be reachable. Saving a policy does not restart a provider process or recreate its container.

When it runs

devctrl needs both of these signals from the same provider process generation:

  1. The session calls its existing report_session_handoff MCP tool with outcome: "completed". This is an explicit agent report that the task is finished with no pending question or blocker. The other outcomes are waiting_for_input and blocked; older callers can omit the field, in which case this report does not establish completion. Alternatively, a fresh host observation of the same account/conversation/generation's native goal with status: complete establishes completion. A checklist at 100%, an active goal or stale telemetry does not. An explicit current-turn question/blocker report takes precedence over a completed native goal.
  2. The root provider's native Stop event confirms that the same turn ended. Its generation-scoped turnStartedAt must precede the report. A completed report from an earlier turn cannot authorize compaction after a newer prompt.

The default idle interval is 30 seconds and the default cooldown is 30 minutes. These settings can be overridden at each scope. A native Stop alone, quiet terminal output or a running-but-idle process is never interpreted as task completion. The agent's ordinary final prose is not classified by a regex or sent to Decisions API for this purpose.

Remaining idle after compaction does not schedule another command. One completed task report is consumed at most once. A confirmed native/manual compaction also covers older task reports and starts the same cooldown, even when devctrl did not submit it. New work must finish and report completion before another attempt. Long idle time does not invalidate a completed turn: the host must still confirm the same native state, identity and process, but completion itself has no five-minute expiry. This also allows enabling automation for an already-idle eligible session.

Compaction is held while:

The host rechecks native evidence immediately before delivery. A single account-UID process then checks the exact session HOME, provider identity, process generation, native Stop record, tmux attachment and empty composer inside the container. It submits only the official /compact command. It does not send Escape, interrupt work or stop the process.

Submission, failures and history

The controller persists a receipt before touching the terminal. The container also records a private receipt before paste/Enter. One completed report can produce at most one attempt; an uncertain transport or process crash does not cause a blind retry. Later completed tasks become eligible after the cooldown. Receipts in a session HOME are bounded to the most recent 128.

Open Settings → Auto compact → Compaction history (h) to inspect the controller's durable history. Highlight or enter a repository to read all its sessions, including while editing one session's policy. Choose Session filter explicitly (f in the TUI) to narrow it. Entries stay in server time order; ↑/↓ selects an entry, n/p pages and r refreshes. Browser and desktop use the same view. See lifecycle history (source access required) for record details.

Each entry includes the date, trigger, delivery/native completion state, provider process generation, context tokens before and after, source timestamps, and the context reduction in tokens and percent. These are context occupancy, not billed tokens or subscription savings. Missing, stale or mismatched native telemetry is displayed as unavailable, never zero. A completed compaction can have an unavailable after sample until the CLI reports newer official telemetry. For Claude, the execution host also reads numeric preTokens and postTokens from root compact_boundary.compactMetadata records in the owned canonical transcript. These populate history with source claude-compact-boundary, even when statusline counters reset after /compact; no extra model request is sent. The scan is incremental, limited to 2 MiB per observation, caches only bounded metadata and never sends summaries or prompts. Matching completed entries can receive corrected measurements after an account transfer without changing their original generation, trigger or completion state. Missing postTokens remains unavailable. Older CLI formats and statusline-only observations still work. Claude can reset its last-request counters to zero after compaction. This is displayed as unavailable context, never as a 100% reduction; older history is corrected when read. Settings reconcile the last submitted attempt with native history, so successful compaction is shown as completed rather than remaining on submitted.

A held entry explains why automation has not run: for example a missing explicit completed-task report, active work, a question, unknown children or quota. Repeated identical checks update the current status without adding an entry on every poll. The agent is instructed to report its outcome after a completed task, blocker or handoff; the user does not need to call MCP manually. A quiet terminal alone still cannot establish that work is complete.

History is stored separately from /state, fetched lazily in pages of at most 50 entries, isolated per owner, and retained for 90 days with a 5,000-entry limit per user. Session last-attempt receipts remain available for compatibility:

State Meaning
reserved The controller admitted an attempt and is waiting for the host result.
submitted /compact was submitted to the existing CLI; this does not claim its summary finished successfully.
skipped A final native safety check declined to submit the command.
uncertain Delivery could not be confirmed; devctrl will not replay the command.

Claude native PreCompact / PostCompact hook records retain compact boundaries between host polls. Codex's bounded canonical rollout supplies its native compacted / context_compacted boundaries without assuming that older Codex releases support compact hooks. Content-bearing summaries are discarded. A submitted command is marked completed only after correlated native evidence; replayed observations update the same record. An unconfirmed command becomes uncertain after 15 minutes instead of displaying endless progress. Conversation identity and process generation fence both history and token samples. A failed compaction does not become a fake completed task. Compaction may consume model tokens and retains the provider's normal failure, confirmation and context-management behavior. devctrl never acknowledges an unexpected CLI confirmation automatically.

This feature applies to managed Claude, Codex and Antigravity root sessions with updated native hooks and confirmed task completion. It does not compact arbitrary external-agent CLIs or independently submit commands to subagent composers. Native provider auto-compaction settings remain separate.

Antigravity

Antigravity uses the same Global → Project → Session policies, server-side queue, input lock, cooldown and durable receipts. Updated native hooks retain the root turn's first invocation. A successful Stop with fullyIdle: true and terminationReason: model_stop is required; errors, step limits, native questions, permissions and unfinished background tasks do not qualify. The native all-idle signal establishes zero active children, not a detailed child inventory.

The container rechecks the exact root identity, Stop, generation, process and native footer before typing. It verifies /compact in native autocomplete and sends Enter separately. It never sends Escape or cancels work. Missing or incompatible hooks leave automation held rather than inventing an idle event.

The host incrementally reads the owned canonical brain/<conversationId>/.system_generated/logs/transcript.jsonl, at most 2 MiB per poll. Only CHECKPOINT / SYSTEM / DONE records confirm completion; summaries never leave the host. Initial history catch-up finishes before admitting a new command, so an existing checkpoint can start the cooldown. Native manual and automatic checkpoints lack a trigger field in the observed format and are labelled unknown; a correlated devctrl request retains completed-task. The reader does not open or copy the conversation's SQLite database.

Antigravity's checkpoint records do not expose exact before/after token counters. Those history fields remain unavailable; the rounded /context panel is not parsed as exact telemetry and a token drop alone never proves completion.

Verified in a live CLI 1.4.0 session: slash-command autocomplete advertises /compact even though the inspected /help and published reference omit it. Submitting the native command completed in 15 seconds, summarized 227 steps, and reported context changing from 150.4k to approximately 20k tokens. A subsequent /context confirmed approximately 20k tokens and one additional checkpoint. These are rounded CLI measurements, not exact token counts or billing savings. The official slash-command reference, context management and hook reference describe context management; their command lists alone are not sufficient to rule out a native command. The SDK's own compaction APIs are not evidence of control over an already-running native CLI conversation.

API and MCP

Authenticated operator APIs:

The existing operator MCP operation catalog discovers these APIs. The session tool get_auto_compact_history reads this repository by default; scope:"session" narrows it to the authenticated session. Its limit (1–50) and cursor page the same records without selecting another owner or project. Reading history does not compact a conversation or change its policy. The session-scoped report_session_handoff schema exposes the optional outcome field; agents cannot enable their own compaction policy through that report. The authenticated host-only reserve/complete route applies independent admission checks and cannot target sessions placed on another host. Host-only compaction telemetry additionally accepts bounded claudeBoundaries numeric records. Reconciliation can only enrich an existing completed record for the same native conversation and boundary time; it cannot invent an older generation's compaction event.

Upstream command semantics: Claude commands, Claude hooks, and Codex developer commands.