# Usage limits

> What an agent has left: the context window split by what fills it, and each plan limit with its share and a live reset countdown.

People running agents keep asking two things: how full is the context, and how long until my limit resets. This card answers both in a small space. The context window is one bar split by what fills it (system prompt, tools, files, conversation), with a 2px gap between parts; the chevron folds the breakdown open underneath, and pointing at a part steps the others back. Below a hairline, each plan limit is a bar with its share and when it resets: under a day away it counts down, the minutes rolling down like a clock, and further out it gives the day and time. A bar turns amber past 80% and red at its limit, where "Limit reached" folds open beside the share. The first time it’s seen the bars grow from the left and every figure rolls up.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/usage-limits.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`
- Docs and live preview: https://hairlineui.com/ui/usage-limits
- Registry item (source): https://hairlineui.com/r/usage-limits.json

## Usage

```tsx
import { UsageLimits } from "@/components/usage-limits";

<UsageLimits
  plan="Max"
  context={{ limit: 1000000, parts: [{ id: "system", label: "System prompt", tokens: 14000 }, { id: "chat", label: "Conversation", tokens: 548000 }] }}
  limits={[{ id: "five-hour", label: "5-hour window", used: 38, limit: 100, resetsAt: resetTime }]}
/>
```

## From your usage API

Read the session’s token counts and the account’s limits on the server and pass them straight in; the countdown runs on its own.

```tsx
import { UsageLimits } from "@/components/usage-limits";
import { getUsage } from "@/lib/usage";

export async function LimitsPanel({ sessionId }: { sessionId: string }) {
  const usage = await getUsage(sessionId);
  return (
    <UsageLimits
      plan={usage.plan.name}
      context={{
        limit: usage.context.window,
        parts: [
          { id: "system", label: "System prompt", tokens: usage.context.system },
          { id: "tools", label: "Tools", tokens: usage.context.tools },
          { id: "files", label: "Files read", tokens: usage.context.files },
          { id: "chat", label: "Conversation", tokens: usage.context.messages },
        ],
      }}
      limits={usage.limits.map((l) => ({ id: l.id, label: l.name, used: l.used, limit: l.max, resetsAt: l.resetsAt }))}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `limits` | `PlanLimit[]` | – | { id, label, used, limit, resetsAt? } for each plan limit. |
| `context` | `{ limit; parts: ContextPart[] }` | – | The context window and what fills it, each part { id, label, tokens }; up to five colours. |
| `plan` | `string` | – | The plan’s name after "Plan limits". |
| `onPlanClick` | `() => void` | – | Makes the plan heading a button with an arrow, e.g. to billing. |
| `defaultOpen` | `boolean` | `false` | Start with the context breakdown open. |
| `locales` | `string \| string[]` | – | For numbers and the reset day. |

## States

- **arrive**: In view for the first time, every bar grows from the left (900ms, staggered) and every figure rolls up from zero.
- **breakdown**: The context heading is a disclosure: the chevron turns and the list of parts folds open (420ms) with each part’s tokens and share. Pointing at a part or its row dims the others.
- **countdown**: A reset under a day away reads "Resets in 2 h 46 min"; the clock ticks on each whole minute and the minutes roll down. Further away it reads "Resets Tue 3:00 pm".
- **status**: At 80% a bar and its share turn amber; at 100% they turn red and "Limit reached" folds open beside the share.

## What it handles

People who run agents keep asking two things: how full is the context, and how long until the limit resets. This answers both in a small card.

- **The context split by what fills it**: One bar shows the system prompt, tools, files and conversation, with a 2px gap between the parts.
- **A breakdown on demand**: The chevron folds the list of parts open with tokens and shares. Pointing at a part steps the others back.
- **Plan limits with reset times**: Under a day away it counts down, with the minutes rolling. Further out it gives the day and time.
- **It warns before it runs out**: A bar turns amber past 80% and red at the limit, where “Limit reached” opens beside the share.
- **Every figure is real text**: Tokens, shares and reset times are text for screen readers. The bars are decoration.
- **Safe on the server**: The countdown starts after mount, so a server render never shows a wrong time, and the card sizes to its own width.

## Replaces

a token breakdown, plan limit bars, a reset countdown, threshold colours, a context window gauge

## Where it fits

- **AI chat and coding products**: Show how full the context is and how much of the plan is left.
- **API platforms**: Quotas for requests or tokens, with the time they reset.
- **Billing and settings pages**: Usage against the plan, in one small card.
- **Agent dashboards**: What fills the context window for a running agent.

## Notes

- Every figure is real text: tokens, shares, reset times; the bars are hidden from assistive tech.
- The context heading is a button with aria-expanded controlling the breakdown, which is inert while folded.
- Amber and red always come with a figure, and "Limit reached" is spelled out.
- The countdown re-renders once a minute on the whole minute, and only after mounting, so a server render never shows a wrong time.
- Installs Number roll. It sizes to its own width; with reduced motion bars and figures change in place.

License: MIT (https://hairlineui.com/license#components)
