Skip to content

Context gauge

How much of the model's context window the conversation uses, as a bar or a ring that warns before the window is full and opens on what fills it.

  • <aparte-context>
On this page
Open

A model reads a limited number of tokens, and a long conversation reaches the limit before anyone notices. <aparte-context> shows how much is used, out of the current model’s window. The bar takes the width it is given; variant="ring" takes none, for a toolbar.

It needs nothing from your code. The reading is the size of the last request as the provider reported it; when the conversation has changed since — a new message, a summary written, a Restore — it is an estimate of the next request, prefixed with ~, calibrated on what the provider reported last. The window comes from the model (a provider’s model list fills in contextWindow) or from the window attribute. Before the first turn, or without a window, it shows nothing. A conversation loaded from storage shows the usage its last reply recorded, and a new chat starts empty.

Click the reading, or focus it and press Enter, to open what fills the window: the system prompt, the tools, the summary, the messages, what is free, and “other” — what the provider counted that the page did not send, such as a server’s own instructions. The parts are estimates; the total is the provider’s figure. With @aparte/plugin-compaction set up, the panel says how much compacting now would free, with Compact now; while a compaction runs, and when one failed, the gauge says so (data-compact="running" or "failed"), and the panel offers Retry. Escape or a click outside closes it.

Open

At 75% of the window the gauge turns warn, at 90% danger (warn and danger attributes move them). It reflects the level in data-level and fires aparte-context-threshold when it changes. A request the model refused as over its window turns it danger until the next reply reports.

html
<aparte-context data-empty=""></aparte-context>
js
el.addEventListener('aparte-context-threshold', (e) => use(e.detail));

Installation and the framework-specific traps: React · Vue · Svelte · Angular.

The gauge measures; @aparte/plugin-compaction decides when to summarise the older turns, past 80 % of the window by default (see Long conversations). The gauge never asks for a compaction itself: the plugin compacts on its own once it is set up.

VariableWhat it sets
--aparte-context-ring-sizeThe ring’s diameter.

The bar wears the progress recipe, and its colours follow the level; the panel wears the popover recipe.

<aparte-context> · class AparteContext

Attributes

AttributeDescription
windowThe context window, in tokens. Overrides the current model’s contextWindow.
warnFraction of the window at which the level turns warn. Default 0.75.
dangerFraction at which it turns danger. Default 0.9.
targetThe id of the <aparte-chat> to watch, when the element is not under it.
variantbar (default) or ring: a progress bar with the reading beside it, or a ring with the percentage.
usedTokens in use before a turn of this page has reported any: a restored conversation’s last usage. The next turn’s usage replaces it.
data-levelReflected BY the element: ok, warn or danger. Read-only.
data-emptyReflected BY the element while it has nothing to show. Read-only.
data-compactReflected BY the element while this chat is being compacted (running) and after a compaction failed (failed). Read-only.

Properties

PropertyTypeDescription
usednumber | nullWrites the used attribute: a reading for a conversation restored without a turn of this page, which had nothing to report until the next one. null clears it.
windownumber | nullWrites the window attribute; null gives the model’s own window back. The setter has to exist: React 19 and Svelte assign the PROPERTY whenever the element has one of that name, so <aparte-context window={8000}> — a spelling both wrappers type as valid — hit a getter alone and threw.
level (readonly)AparteContextLevel | nullThe current level, or null while nothing is shown.
measure (readonly)AparteContextMeasure | nullThe reading drawn now, parts and all, or null while nothing is shown.

Events

EventTypeDescription
aparte-context-thresholdCustomEvent<AparteContextThresholdEventDetail>The level changed. Bubbles.
aparte-compactCustomEvent<AparteCompactEventDetail>Dispatched on window by Retry in the panel when no compactor is registered. @aparte/plugin-compaction answers it; with no listener nothing happens.

CSS variables

VariableDefaultDescription
--aparte-context-ring-size22pxDiameter of the ring variant.
  • The gauge is a meter with its minimum, maximum and current value, named from the contextLabel key (“Context window”) followed by the reading.
  • The reading is a button with aria-expanded that opens the panel; it never opens on hover alone.
  • The level is written, not only coloured: the reading says how full the window is.