Skip to content

feat(autopilot): hand off to a fresh session past a context size - #508

Merged
kalaspuff merged 8 commits into
mainfrom
fctl/1131-autopilot-hands-off
Nov 10, 2026
Merged

kalaspuff merged 8 commits into
mainfrom
fctl/1131-autopilot-hands-off

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An autopilot can now hand off to a fresh session once its own session's context reaches a size people choose: 150K, 250K or 400K tokens, or one of their own from 100K to 1M, besides the 12-hour shift it already had. The first wake that finds its session between turns with that much context starts a fresh one and stops the old one. The fresh session gets its briefing as before, then why it takes over ("You take over from your last session, shop#2: its context held 412K tokens, past the 400K…"), then the wake's news, and goes on from its plan, its log and fctl autopilot brief. This matters because each wake reads the whole conversation again, and after an hour's rest none of it is cached. A 770K-token session pays for 770K uncached tokens at nearly every check-in; a fresh one pays for its briefing.

So the old session's working knowledge isn't lost: once its context reaches three quarters of the size, each wake message tells it that a fresh session takes over at its next wake. It also asks it to write down in its plan and log what it's in the middle of, what it waits for and what it learned, while its cache is still warm. The briefing now says when a fresh session takes over, and asks it to keep its context lean: read what it needs of a session rather than whole transcripts, and hand long reading to a subagent.

  • People choose it in the autopilot's settings dialog (A fresh session takes over), with fctl autopilot set --handoff-at 250k|never, or in the API's PUT /api/v1/projects/{id}/autopilot (handoff_at, 0 for none). The tab's How it works card and fctl autopilot say when it hands off and how full its session is now.
  • Migration 0058 adds autopilots.handoff_at. The control plane reads the session's context from D1's session stats, and the wake's log entry says when a full context started a fresh session.
  • It builds on feat: choose the context size Claude compacts a project's sessions near #506 (merged), whose token sizes it uses.

Verified with unit tests (Rust and web) and cargo xtask check --quick, and in cargo xtask dev with fake-claude. I put the playground on autopilot with --handoff-at 100k. With its session's recorded context set to 80K, a wake told it in the same session that the handoff is near. At 120K, the next wake started playground#4 with the takeover message, stopped #2, and logged "Woke for someone waking it, session #3, in a fresh session: the last one's context held 120K tokens".

How it works, before and after:

before-card.png after-card.png

The settings dialog, before:

before-dialog.png

After, with a size of people's own:

after-dialog.png

The choices, in the dark theme:

after-dark-dialog.png

On a phone:

after-390-dialog.png

Related:

Worth confirming

  • Decision: There's no default: autopilots hand off only after 12 hours until someone chooses a size. A default such as 250K would save the most for everyone, but it would change how running autopilots work.
  • Decision: The sizes offered (150K, 250K, 400K) are smaller than the compaction choices in feat: choose the context size Claude compacts a project's sessions near #506. A fresh autopilot session starts at about 40K tokens (Claude Code's prompt, the briefing and the brief), and its plan and log carry the work.
  • Decision: Changing the handoff counts as changing how much the autopilot works. Someone other than its owner who changes it takes it over, unless the owner keeps it, as with its model.
  • Decision: A session at work never hands off mid-turn; the first wake after its turn does. A session that compacted back below the size carries on.
  • Decision: The briefing now also asks the autopilot to read only what it needs of its sessions and to hand long reading to subagents. This goes beyond the handoff itself, but it targets the same cost.
  • Assumption: Claude Code keeps a subscription's prompt cache for an hour (2.1.322 gives subscribers within their limits a 1-hour TTL), which is what "uncached after an hour's rest" says.

fctl session


Note

Medium risk. It changes when an autopilot's session is stopped and replaced, which every autopilot wake goes through, and adds a migration for a new handoff_at column.

What it does. Lets an autopilot hand off to a fresh session once its current session's context passes a chosen size (150K, 250K, 400K or a custom 100K to 1M tokens), besides the existing 12-hour limit. The old session is warned at three quarters of the size to write down its state, and the fresh one gets a briefing and the reason for the takeover. The size is set in the settings dialog, with fctl autopilot set --handoff-at, or in the API's handoff_at.

Migration 0058. Adds the autopilots.handoff_at column, which must be applied before the control plane that reads it is deployed.

fctl review's first look at f9cb4b2 · 20 files, +716 −58 · Review agent settings

fctl-sh Bot added 6 commits November 10, 2026 20:33
A project's settings choose where Claude compacts the conversation
(compact_window): 250K, 400K or 600K tokens, a size of the project's own
from 100K to 1M, or Claude's default, near the model's whole window.
The control plane passes it on with the project's variables as Claude
Code's CLAUDE_CODE_AUTO_COMPACT_WINDOW, so agents from before it pass it
to Claude too. Settings → Agents has a Context section for it, and
fctl projects set takes --compact-window.
An autopilot's settings choose the context size at which a fresh session
of its own takes over from the one it works in (handoff_at): 150K, 250K
or 400K tokens, a size of people's own, or none, which leaves only the
12-hour shift. The first wake that finds its session between turns with
that much context starts a fresh one, briefed and told why it takes over
and from what, and stops the old one. As the context nears it, wake
messages say so, so that the session writes down what its next one
needs while its cache is warm, and the briefing asks it to keep its
context lean.
@fctl-review

This comment has been minimized.

kalaspuff pushed a commit that referenced this pull request Nov 10, 2026
…ar (#506)

## Summary

A project now chooses the context size Claude compacts its sessions
near: 250K, 400K or 600K tokens, a size of its own from 100K to 1M, or
Claude's default (near the model's whole window, 967K of 1M for Opus
5.5). Each step of a session reads its whole context again, so long
sessions that compact sooner spend less of the plan. It's on Settings →
Agents (a new Context section, with a Tokens field for "Another size"),
in `fctl projects set --compact-window 400k|default`, in `fctl projects
show`, and in the API as `settings.compact_window`.

The control plane passes it to sessions with the project's variables, as
Claude Code's `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, so agents and hosts one
version behind pass it to Claude too. That variable takes precedence
over Claude's settings, a repository's included. Claude Code 2.1.322
accepts it as probed with `get_context_usage`: 250K compacts at 217K,
400K at 367K, sizes below 100K read as 100K, and sizes above the model's
window are capped at it. The session's Work section then shows the
context against that window. Review agents take their project's choice.
An update that leaves the field out, from an older CLI or web tab, keeps
what was stored. Verified with unit tests (Rust and web) and `cargo
xtask check --quick`, and in `cargo xtask dev`: the CLI set it, the API
refused 50K and kept it on an update without the field, and the
session's Claude process had `CLAUDE_CODE_AUTO_COMPACT_WINDOW=300000`.

Settings → Agents, before:


![before-light.png](https://app.fctl.sh/api/v1/published/jG3JmZ5QaD5Cp0TnfHciXWdL7sAWNE29ble9CCLGogr/before-light.png)

After, with a size of the project's own:


![after-light.png](https://app.fctl.sh/api/v1/published/M0Yhx4OO37nWRzf50kPQkCSzNqk6ReSBZK50KrNsc4V/after-light.png)

The choices, in the dark theme:


![after-dark-open.png](https://app.fctl.sh/api/v1/published/2Iz09FWCOgcMJyWUs99pm3eikjR3k2I4KB0QjhBQ8fn/after-dark-open.png)

On a phone:


![after-light-390.png](https://app.fctl.sh/api/v1/published/fQwkz9VYo6CTRcTWg2TeNmi9pzdwdES6Qr5XiyJLQ5V/after-light-390.png)

The design docs' description of the Agents page:

- hyperstructure/design#40

The autopilot's handoff to a fresh session, stacked on this one:

- #508

## Worth confirming

- **Decision:** The setting is Claude Code's auto-compact window, which
Claude compacts about 33K tokens before (367K for 400K), rather than an
exact threshold that fctl would turn into a window. Claude's buffer may
change between versions, and the session page shows the exact point.
- **Decision:** The bounds are 100K to 1M tokens, which is what Claude
Code itself takes. "Claude's default" stands in for the "max (1M)"
option, since it is the model's whole window.
- **Decision:** A project variable `CLAUDE_CODE_AUTO_COMPACT_WINDOW`
still applies where the project leaves the setting at Claude's default.
Where both are set, the setting wins.

[fctl session](https://app.fctl.sh/s/ses_01M73FHWT0DV6X1X2XQYKMHBVT)

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Medium risk.** It adds a project setting that changes the
environment every session of a project gets
(`CLAUDE_CODE_AUTO_COMPACT_WINDOW`) and extends the stored settings,
API, CLI and web app; it only takes effect where a project chooses a
size.
>
> **What it does.** Adds `compact_window` to project settings so a
project can choose the context size, from 100K to 1M tokens, that Claude
compacts its sessions near. The control plane passes it to sessions as
`CLAUDE_CODE_AUTO_COMPACT_WINDOW`, review agents take it too, and it is
set from a new Context section in Settings → Agents or with `fctl
projects set --compact-window`. An update that leaves the field out
keeps the stored value, and the API refuses sizes outside the bounds.
>
> **Precedence over project variables.** Where a project chooses a size,
it overrides a project variable of the same name; where it leaves
Claude's default, such a variable still applies.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M73KQCWDZB7W9WSVJ2R73Q2E)'s first
look at
[`8893c4d`](8893c4d)
· 19 files, +621 −16 · [Review agent
settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub>

<!-- /FCTL_REVIEW_SUMMARY -->

---------

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
Base automatically changed from fctl/1131-it-would-be-great-to-define-at-what-cont to main November 10, 2026 20:57
@kalaspuff
kalaspuff merged commit 804c41b into main Nov 10, 2026
13 checks passed
@kalaspuff
kalaspuff deleted the fctl/1131-autopilot-hands-off branch November 10, 2026 21:04
kalaspuff pushed a commit to hyperstructure/design that referenced this pull request Nov 10, 2026
#41)

## Summary

Describes when a fresh session takes over from an autopilot's own: the
*A fresh session takes over* Select and Tokens field in its settings
dialog, with their copy, and the line on the tab's *How it works* card
that says when, and how full its session is now.

- hyperstructure/fctl#508

[fctl session](https://app.fctl.sh/s/ses_01M73FHWT0DV6X1X2XQYKMHBVT)

<!-- FCTL_REVIEW_SUMMARY -->
---

> [!NOTE]
> **Low risk.** It only changes a design doc, adding copy and behavior
for a setting that the linked fctl pull request implements.
>
> **What it does.** Documents the new autopilot setting for when a fresh
session takes over from its own: the Select and Tokens field in the
settings dialog, their copy, and the line on the How it works card that
says when, and how full its session is now. It follows
hyperstructure/fctl#508, which builds the feature.
>
> <sub>[fctl
review](https://app.fctl.sh/s/ses_01M73KRTJQ812GBPRDMRQETGRJ)'s first
look at
[`be61c91`](be61c91)
· 1 file, +11 −1 · [Review agent
settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub>

<!-- /FCTL_REVIEW_SUMMARY -->

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant