aiellie

Search

Find a component, template or page

GitHub
Components

Context Breakdown

What fills a model's context window: one bar split into the system prompt, tools, files and conversation, with a legend of token counts and what's free, sliding as parts grow or are compacted.

Context158.4K / 200K79%
  • System prompt8.2K
  • Tools21.6K
  • Files46.9K
  • Conversation81.7K
  • Free41.6K
Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/context-breakdown"

shadcn needs the @aiellie registry in components.json first. npx aiellie add context-breakdown adds it on its first run, then installs the same way.

Context Breakdown shows what fills a model's context window: one bar split into its parts, like the system prompt, tools, files and the conversation, with a legend of token counts and what's left free. Hovering a row in the legend picks out its part of the bar.

When a part changes, its width slides to the new size, so compacting a conversation reads as the conversation shrinking. For a single number, use Meter.

Getting started

  1. Pass the parts

    max is the model's whole window. The parts fill it in the order given, darkest first.

    components/context.tsx
    import { ContextBreakdown } from "@/components/aiellie/context-breakdown"
    
    export function Context({ usage }: { usage: Usage }) {
      return (
        <ContextBreakdown
          max={200_000}
          segments={[
            { key: "system", label: "System prompt", tokens: usage.system },
            { key: "tools", label: "Tools", tokens: usage.tools },
            { key: "conversation", label: "Conversation", tokens: usage.messages },
          ]}
        />
      )
    }

Anatomy

<div data-slot="context-breakdown">
  <div /> {/* the label, tokens used of the window, and the percent */}
  <div role="meter">
    <span data-dim /> {/* one per part */}
  </div>
  <ul /> {/* the legend, then what's free */}
</div>

The bar is a meter, so a screen reader hears how much of the window is used. The fills are shades of foreground, so the parts read as one whole in both themes. formatTokens is exported too: 820, 46.9K, 1.2M.

Examples

Colour a part

A part's className replaces its fill in the bar and the legend, like bg-destructive for a conversation that's about to need compacting.

Context · compact soon121.5K / 128K95%
  • System prompt4.1K
  • Conversation117.4K
  • Free6.5K

API reference

ContextBreakdown

PropTypeDefaultDescription
segmentsContextSegment[]requiredThe parts, in the order they fill it.
maxnumberrequiredThe whole window, in tokens.
labelReactNode"Context"

All other div props are forwarded.

ContextSegment

FieldTypeDefaultDescription
key, labelstringrequired
tokensnumberrequired
classNamestringa shade of foregroundIts fill.