# Context meter

Inspect supplied token usage, response reserve and remaining context capacity.

Access: pro. Category: Data. Kind: composite.

## When to use

- Use it when a page needs inspect supplied token usage, response reserve and remaining context capacity.
- Choose it when the data structure, labels, and state are supplied by the application and must remain consumer controlled.

## Alternatives

- Choose data-table instead when sortable column controls, native row selection and a scrollable table is the actual interface need, rather than context meter.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Context meter

```sh
npx shadcn@latest add @tidal-pro/context-meter
```

Stylesheets: `components/ui/tidal.css`, `components/ui/context-meter.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/context-meter.css";
import{TidalContextMeter}from"./components/ui/context-meter";
export default()=><div className="tidal-scope"><TidalContextMeter capacity={1} used={1}/></div>;
```

## Structured props

- `TidalContextMeter.capacity: number`: Required capacity value accepted by this exported component.
- `TidalContextMeter.used: number | null`: Required used value accepted by this exported component.
- `TidalContextMeter.breakdown?: ReadonlyArray<TidalContextPart> | undefined` (default []): Optional breakdown value accepted by this exported component.
- `TidalContextMeter.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalContextMeter.formatTokens?: ((tokens: number) => string) | undefined` (default (v) => decimal.format(v)): Optional format tokens value accepted by this exported component.
- `TidalContextMeter.headingLevel?: "h2" | "h3" | "h4" | "h5" | "h6" | undefined` (default "h2"): Optional heading level value accepted by this exported component.
- `TidalContextMeter.labels?: Partial<{ used: string; limit: string; reserve: string; remaining: string; unknown: string; unavailable: string; invalid: string; breakdown: string; unattributed: string; available: string; nearLimit: string; overLimit: string; exceeded: (tokens: string) => string; measurement: (used: string, capacity: string) => string; }> | undefined`: Optional labels value accepted by this exported component.
- `TidalContextMeter.meterRef?: Ref<HTMLMeterElement> | undefined`: Optional meter ref value accepted by this exported component.
- `TidalContextMeter.reserved?: number | undefined` (default 0): Optional reserved value accepted by this exported component.
- `TidalContextMeter.title?: ReactNode` (default "Context window"): Optional title value accepted by this exported component.
- `TidalContextMeter.warningRatio?: number | undefined` (default 0.85): Optional warning ratio value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/context-meter.tsx) | [Manifest](https://tidalui.com/examples/context-meter.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useState } from "react";

import { TidalContextMeter } from "./components/ui/context-meter";

import "./components/ui/context-meter.css";

import "./components/ui/meter.css";



const tidalExampleStyles = ".tidal-scope .context-meter-demo {\n  width: 100%;\n  max-width: 540px;\n  min-width: 0;\n}\n.tidal-scope .context-meter-demo-options {\n  display: flex;\n  gap: 6px;\n  flex-wrap: wrap;\n  justify-content: center;\n  margin-top: 16px;\n}\n.tidal-scope .context-meter-demo-options button {\n  min-width: 44px;\n  min-height: 44px;\n  padding: 8px 12px;\n  border: 1px solid var(--t-border);\n  border-radius: 9px;\n  font-size: 11px;\n  font-family: inherit;\n  line-height: 1.5;\n  color: var(--t-muted);\n  background: var(--t-surface);\n  cursor: pointer;\n  max-width: 100%;\n  overflow-wrap: anywhere;\n}\n.tidal-scope .context-meter-demo-options button[aria-pressed=\"true\"] {\n  background: var(--t-ink);\n  color: var(--t-surface);\n  border-color: var(--t-ink);\n}\n.tidal-scope .context-meter-demo-options button:focus-visible {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}\n.tidal-scope .context-meter-demo > p {\n  font-size: 11px;\n  line-height: 1.6;\n  color: var(--t-muted);\n  text-align: center;\n  margin: 12px 8px 0;\n}";

const snapshots = [
  { name: "Typical request", used: 12480, reserved: 4096 },
  { name: "Near capacity", used: 27400, reserved: 4096 },
  { name: "Over capacity", used: 30720, reserved: 4096 },
];

export function ContextMeterDemo() {
  const [selected, setSelected] = useState(0);
  const current = snapshots[selected];
  return (
    <div className="context-meter-demo">
      <TidalContextMeter
        title="Research conversation"
        description="Track supplied input counts and the space reserved for a response."
        used={current.used}
        capacity={32768}
        reserved={current.reserved}
        breakdown={[
          { id: "instructions", label: "Instructions", tokens: 1840 },
          { id: "conversation", label: "Conversation", tokens: 5440 },
          { id: "sources", label: "Attached sources", tokens: 5200 },
        ]}
      />
      <div
        role="group"
        aria-label="Sample context counts"
        className="context-meter-demo-options"
      >
        {snapshots.map((s, i) => (
          <button
            type="button"
            key={s.name}
            aria-pressed={selected === i}
            onClick={() => setSelected(i)}
          >
            {s.name}
          </button>
        ))}
      </div>
      <p>
        Fixed sample counts. No text is tokenized and no model is contacted.
      </p>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <ContextMeterDemo />
    </div>
  );
}

```

## Gotchas

- Supply truthful data and labels; the component does not fetch, aggregate, or persist records.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Consumer-supplied safe integer used/capacity/reserved counts, unknown usage as null, optional warningRatio and token breakdown. The native Meter shows exact used counts with a capacity-saturated visual; the reserved response allowance is separate, and remaining input capacity subtracts both. Overflow is explained numerically. Breakdown IDs are unique and sums cannot exceed known usage; residual usage is labelled Other context. Unknown usage requires an empty breakdown. Known status remains visible when title is omitted. Optional title/description and h2-h6 heading level, token formatter, localized labels, root section props/ref and native meterRef are supported. Native details reveals the breakdown. Invalid counts show a configuration alert. No tokenization, model discovery, pricing, request, provider call, persistence or estimation is bundled.
