Skip to content

feat: show how full Claude's context is on the session page - #224

Merged
kalaspuff merged 4 commits into
mainfrom
fctl/149-in-the-work-section-in-the-right-sidebar
Oct 23, 2026
Merged

kalaspuff merged 4 commits into
mainfrom
fctl/149-in-the-work-section-in-the-right-sidebar

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The Work section of the session page now shows how much of Claude's context window the conversation fills, where Claude compacts it on its own, and how often it has, so people can see a session closing in on the limit or on a compaction. fctl show says the same.

What changed

  • The context. SessionDO counts it with the session's other counters (fctl_domain::events): the input of the conversation's latest API call, cached or not (input_tokens + cache_creation_input_tokens + cache_read_input_tokens), which is how Claude Code's status line counts it. Subagents' calls have contexts of their own and don't count. It moves with each call, as the response starts (message_start) or with the call's first stored message. A compaction (system/compact_boundary) sets it to what the compaction left (post_tokens) until the next call reports, and adds to a count of compactions.
  • The window and the threshold. Both depend on the model, Claude's settings and environment, and its experiments: Claude Code 2.1.308 gives Opus 5.5 a 1M window and compacts at 967K, so a guess from the model name would be badly wrong. fctl-agent asks Claude with the get_context_usage control request once Claude has started and after each turn, as it already does for the effort level. It passes detail: "summary", so Claude answers from the last call's usage and its own estimates, with no token-count API calls. fctl-agent reports maxTokens and autoCompactThreshold in the session state (ContextWindow). It reports no threshold when auto-compact is off, or when Claude leaves compaction to the API (autocompactSource: "auto", where Claude's own /context shows no buffer either). SessionDO keeps them in the session's stats (context_tokens, context_window, compact_at, compactions), so D1 has them without a migration.
  • The session page. A Context row (135K / 200K) under the Work section's counters, with a meter split where Claude compacts. The meter turns amber nine tenths of the way to the threshold (or to the end of the window, when there is no threshold). A line under it says where Claude compacts and how often it has. Hovering the numbers shows them exactly. The phone details sheet shows the same.
  • The CLI. fctl show has a context: line: 135k of 200k tokens (67%) · compacts at 167k.
  • fake-claude. Its context grows with each call, starting at 18K. Like Claude Code with a 200K window, it compacts on its own at 167K. It also compacts on compact (or /compact), context <tokens> fills its context, and it answers get_context_usage.
  • Docs. docs/architecture.md (how the context is counted and reported), docs/development.md (fake-claude's new words) and docs/getting-started.md.

Compatibility: SessionState.context is optional, and the new stats fields are optional or default to 0. Agents from before this change report no window, so the page shows the token count alone, without the meter. A Claude Code from before get_context_usage answers it with an error, which fctl-agent ignores.

Verification

  • Unit tests:
    • fctl-domain: the context follows the conversation's own calls, not subagents'; it is set once per call, from whichever report comes first; failed calls don't change it; compactions set it and are counted.
    • fctl-agent: a real 2.1.308 answer parses, the auto-compact-off and auto cases give no threshold, the session state carries the window, and a turn's end now sends get_context_usage after get_settings.
    • The CLI's context: line, fake-claude's context word, and the web helpers (contextUse, contextNote).
  • Real Claude Code 2.1.308, run against a stand-in Messages API on localhost with a dummy token: get_context_usage with detail: "summary" answered in 0.01–0.4 s with maxTokens: 1000000, autoCompactThreshold: 967000 and autocompactSource: "model-default" for Opus 5.5. Without detail it calls the token-count API, so the agent always passes it.
  • cargo xtask dev:
    • A session told context 120k, then explore showed 135k of 200k tokens (67%) · compacts at 167k in fctl show and on the page.
    • context 160k pushed it past the threshold. fake-claude compacted mid-turn (compacted once, back to 31.5K), and compact compacted it again (compacted twice).
    • In the browser, the row moved live as calls came: 18K to 85.5K in 13 s, a new value every 0.4–0.8 s.
  • cargo xtask check, and a session through the standalone control plane (cargo xtask serve, then cargo xtask dev --smoke --server http://localhost:8787): the smoke test passed, and fctl show there says context: 42k of 200k tokens (21%) · compacts at 167k.

Screenshots

At 3018dbc, against cargo xtask dev: the Work section of the session page, 1440 px wide.

Before After
Before: the Work section without the context, light After: Context 135K / 200K with the meter split at 167K and "Compacts at 167K", light
Close to the threshold, after two compactions, dark Opus 5.5's 1M window, light
158K / 200K: the meter and the line in amber, "Compacts at 167K · compacted twice" 412.3K / 1M with a thin last part from 967K, "Compacts at 967K"

The 1M shot sets the stats in the page (fake-claude's window is 200K) to what a session on Opus 5.5 reports.

At 390 px, in the details sheet, dark:

The details sheet on a phone, with the Work section's Context row, meter and line

Session: https://app.fctl.sh/s/ses_01M5JWQSGV55Z5F2CS1YYF67BF

fctl-sh Bot added 4 commits October 22, 2026 23:05
fctl-agent asks Claude Code for a summary of its context
(get_context_usage) once Claude has started and after each turn, and
reports the window and the auto-compact threshold in the session state.
SessionDO keeps them in the session's stats, with the context the
conversation's latest API call had (its input, cached or not, as Claude
Code's status line counts it) and the compactions Claude made.
The Work section of the session page shows the context against the
window, a meter split where Claude compacts the conversation, amber nine
tenths of the way there, and how often it compacted; fctl show says the
same. fake-claude grows its context with each call, compacts at 167K of
its 200K window or on 'compact', fills it on 'context <tokens>' and
answers get_context_usage.
…section-in-the-right-sidebar

# Conflicts:
#	crates/fake-claude/src/main.rs
#	docs/development.md
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner October 22, 2026 23:43
@kalaspuff
kalaspuff merged commit 8af5e31 into main Oct 23, 2026
11 checks passed
@kalaspuff
kalaspuff deleted the fctl/149-in-the-work-section-in-the-right-sidebar branch October 23, 2026 06:21
fctl-sh Bot added a commit that referenced this pull request Oct 23, 2026
#226 posts a review's summary as a comment before the review that holds
its findings on their lines. The findings fctl passes on to the session
that opened the pull request now link that summary, and say that findings
on lines the diff doesn't show are in it; the review's id, for finding each
comment, comes from the review posted after the summary.
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