Skip to content
Star

Run cost

Live credit and token spend, with a cap that pauses the run. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.

$npx designme add run-cost
$npx shadcn@latest add https://designme.dev/r/shadcn/run-cost.json

Need this designed into your product? Book a call

Credits usedIdle
0 / 2,000
Input tokens0
Output tokens0
Tool calls0
01

Install

Add it to your project with the CLI.

HTML, CSS and JS

$npx designme add run-cost

React

$npx designme add run-cost --react

Astro

$npx designme add run-cost --astro

shadcn, React

$npx shadcn@latest add https://designme.dev/r/shadcn/run-cost.json

shadcn, Astro

$npx shadcn@latest add https://designme.dev/r/shadcn/astro/run-cost.json

The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.

02

About

What it is for and what it does.

Run cost shows how many credits an agent run has used against its budget, as a big number and a bar with a marker where the agent should pause. Under the bar it shows what the run used, as counts such as input tokens, output tokens and tool calls (not their share of the credits), and a switch turns the pause on or off.

  • When agent runs cost money or credits and people want to watch the spend while the run is going.
  • When a long run should stop at a set share of the budget and wait for someone to approve more.
  • When people ask what a run has used and you want to show the token and tool counts beside the credits.
03

Usage

Import it in React and drive it from your own state, or place it in an Astro page.

React

import { RunCost } from '@/components/designme/run-cost/RunCost';

React example

The demo above as a React component, 48 lines you can copy.

'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useEffect, useRef, useState } from 'react';
import { RunCost, type RunCostStatus } from './RunCost';
import { useTakeover } from '../lib/useScript';

/* ---------- Run cost: the run starts by itself and burns credits until the cap pauses it; raise the cap to finish ---------- */
const BUDGET = 2000;

export default function RunCostDemo() {
  const [status, setStatus] = useState<RunCostStatus>('idle');
  const [capOn, setCapOn] = useState(true);
  const [n, setN] = useState({ used: 0, input: 0, output: 0, tools: 0 });
  // the ticker reads these without restarting
  const live = useRef({ n, capOn });
  useEffect(() => { live.current = { n, capOn }; });

  useEffect(() => {
    if (status !== 'running') return;
    const id = setInterval(() => {
      const { n: p, capOn: cap } = live.current, limit = cap ? BUDGET * 0.9 : BUDGET;
      const next = { used: Math.min(BUDGET, p.used + 8 + Math.random() * 18), input: p.input + 120 + Math.random() * 220, output: p.output + 30 + Math.random() * 70, tools: p.tools + (Math.random() < 0.12 ? 1 : 0) };
      if (next.used >= limit) { next.used = limit; setStatus(limit < BUDGET ? 'paused' : 'spent'); }
      live.current.n = next; setN(next);
    }, 90);
    return () => clearInterval(id);
  }, [status]);

  // the run starts by itself once the card has settled, unless you take over first
  const ref = useRef<HTMLDivElement>(null), mine = useTakeover(ref);
  useEffect(() => { const t = setTimeout(() => { if (!mine()) setStatus(s => (s === 'idle' ? 'running' : s)); }, 1500); return () => clearTimeout(t); }, [mine]);

  const act = () => {
    if (status === 'running') return setStatus('stopped');
    // Raise cap turns the pause off and carries on to the full budget
    if (status === 'paused') { setCapOn(false); live.current.capOn = false; }
    if (n.used >= BUDGET) setN({ used: 0, input: 0, output: 0, tools: 0 });
    setStatus('running');
  };

  return (
    <div ref={ref} style={{ width: '100%' }}>
      <RunCost used={n.used} budget={BUDGET} capOn={capOn} onCapChange={setCapOn} status={status} onAction={act}
        rows={[{ label: 'Input tokens', value: n.input }, { label: 'Output tokens', value: n.output }, { label: 'Tool calls', value: n.tools }]} />
    </div>
  );
}

Astro

In a page in src/pages. It plays the demo above; change its run-cost.js to show your own data. Attributes like class go on its root element.

---
import RunCost from '../components/designme/run-cost/RunCost.astro';
---
<RunCost />
<RunCost data-style="soft" class="my-class" />
04

Props

Everything RunCost takes.

PropTypeWhat it does
usedrequirednumberCredits used so far
budgetrequirednumberThe whole budget, like 2000
capAtnumberWhere the agent pauses, as a percentage of the budget. Defaults to 90
capOnbooleanWhether the agent pauses at the cap. Leave it out to let the switch change it
defaultCapOnboolean
onCapChange(on: boolean) => void
statusRunCostStatusrunning is blue, paused (at the cap) amber, spent (the whole budget) red
statusLabelstringWords in the status tag. Defaults to Idle, Running, Stopped, "Paused at 90%" or "Budget used"
rowsRunCostRow[]The breakdown under the bar, like input tokens, output tokens and tool calls
actionLabelstringWords on the button. Defaults to Start run, Stop, Resume, Raise cap or Start over, by status
onAction() => voidCalled by the button. What it does is up to you: start, stop, resume, raise the cap
titlestring
barebooleanDraws its own container (the default, as on designme.dev). Set true to sit it flat in a chat thread
classNamestring
05

Code

The full source, as the CLI installs it.

RunCost.tsxReact · 103 lines
'use client';
import { useEffect, useRef, type RefObject } from 'react';
import { cx } from '../lib/cx';
import { useControllable, useReducedMotion } from '../lib/hooks';
import { Swap, Tip } from '../lib/motion';
import '../designme.css';
import './run-cost.css';

export type RunCostStatus = 'idle' | 'running' | 'stopped' | 'paused' | 'spent';

export interface RunCostRow {
  /** Like "Input tokens" */
  label: string;
  value: number;
}

export interface RunCostProps {
  /** Credits used so far */
  used: number;
  /** The whole budget, like 2000 */
  budget: number;
  /** Where the agent pauses, as a percentage of the budget. Defaults to 90 */
  capAt?: number;
  /** Whether the agent pauses at the cap. Leave it out to let the switch change it */
  capOn?: boolean;
  defaultCapOn?: boolean;
  onCapChange?: (on: boolean) => void;
  /** running is blue, paused (at the cap) amber, spent (the whole budget) red */
  status?: RunCostStatus;
  /** Words in the status tag. Defaults to Idle, Running, Stopped, "Paused at 90%" or "Budget used" */
  statusLabel?: string;
  /** The breakdown under the bar, like input tokens, output tokens and tool calls */
  rows?: RunCostRow[];
  /** Words on the button. Defaults to Start run, Stop, Resume, Raise cap or Start over, by status */
  actionLabel?: string;
  /** Called by the button. What it does is up to you: start, stop, resume, raise the cap */
  onAction?: () => void;
  title?: string;
  /** Draws its own container (the default, as on designme.dev). Set true to sit it flat in a chat thread */
  bare?: boolean;
  className?: string;
}


/** A button as wide as its words: when they change it eases to its new width, keeping no room for a longer word */
function useEaseWidth(ref: RefObject<HTMLElement | null>) {
  const reduce = useReducedMotion();
  useEffect(() => {
    const el = ref.current; if (!el || reduce || typeof ResizeObserver === 'undefined') return;
    let w = 0, busy: Animation | null = null;
    const ro = new ResizeObserver(() => {
      if (busy) return;
      const w1 = el.getBoundingClientRect().width;
      if (w && Math.abs(w1 - w) > .5) {
        busy = el.animate([{ width: w + 'px' }, { width: w1 + 'px' }], { duration: 340, easing: 'cubic-bezier(.23,1,.32,1)' });
        busy.finished.catch(() => {}).then(() => { busy = null; w = el.getBoundingClientRect().width; });
      }
      w = w1;
    });
    ro.observe(el);
    return () => ro.disconnect();
  }, [ref, reduce]);
}

const fmt = (n: number) => Math.round(n).toLocaleString('en-US');
const TONE: Partial<Record<RunCostStatus, string>> = { running: 'dm-b', paused: 'dm-warn', spent: 'dm-bad' };
const ACTION: Record<RunCostStatus, string> = { idle: 'Start run', running: 'Stop', stopped: 'Resume', paused: 'Raise cap', spent: 'Start over' };

/** Credits a run has used against its budget, with a cap the agent pauses at and the tokens behind the number. */
export function RunCost({ used, budget, capAt = 90, capOn, defaultCapOn = true, onCapChange, status = 'idle', statusLabel, rows, actionLabel, onAction, title = 'Credits used', bare = false, className }: RunCostProps) {
  const [cap, setCap] = useControllable(capOn, defaultCapOn, onCapChange);
  const go = useRef<HTMLButtonElement>(null);
  useEaseWidth(go);
  const label = statusLabel ?? { idle: 'Idle', running: 'Running', stopped: 'Stopped', paused: `Paused at ${capAt}%`, spent: 'Budget used' }[status];
  return (
    <div data-dm="" className={cx('dm-rc', !bare && 'dm-panel', className)} style={bare ? { paddingInline: 0 } : undefined}>
      <div className="dm-rc-h">
        <span className="dm-muted">{title}</span>
        <span className={cx('dm-rc-st dm-tag', TONE[status])}><span className="dm-dot" /><Swap className="dm-rc-stt dm-mx-w">{label}</Swap></span>
      </div>
      <div className="dm-rc-big"><span className="dm-rc-n dm-num">{fmt(used)}</span><span className="dm-muted"> / {fmt(budget)}</span></div>
      <div className="dm-rc-track" role="meter" aria-label={title} aria-valuemin={0} aria-valuemax={budget} aria-valuenow={Math.round(used)}>
        <div className="dm-rc-fill" style={{ width: Math.max(0, Math.min(100, used / budget * 100)) + '%', background: status === 'paused' ? 'var(--dm-warn-mark)' : 'var(--dm-accent-mark, var(--dm-accent))' }} />
        <Tip label="The agent pauses here"><div className="dm-rc-cap" style={{ left: capAt + '%', opacity: cap ? 1 : 0.2 }} /></Tip>
      </div>
      {rows && (
        <div className="dm-rc-rows">
          {rows.map(r => <div key={r.label}><span>{r.label}</span><span className="dm-num">{fmt(r.value)}</span></div>)}
        </div>
      )}
      <div className="dm-rc-f">
        <label className="dm-rc-cap-t" onClick={e => { e.preventDefault(); setCap(!cap); }}>
          <button type="button" className="dm-toggle" role="switch" aria-checked={cap} aria-label={`Pause at ${capAt} percent`} />
          <span>Pause at {capAt}%</span>
        </label>
        <button ref={go} type="button" className={cx('dm-pill dm-sm dm-rc-go', status === 'running' || status === 'stopped' ? 'dm-line' : 'dm-primary')} onClick={onAction}>
          <Swap>{actionLabel ?? ACTION[status]}</Swap>
        </button>
      </div>
    </div>
  );
}
run-cost.cssReact · 45 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Run cost ---------- */
/* the card's content sits 16px in from every edge (owner, 18 Nov); nothing in it grows or shrinks when it is pressed */
.dm-rc{padding:var(--dm-s-4)}
.dm-rc :is(.dm-pill,.dm-ib):active{transform:none}
.dm-rc-h{display:flex;align-items:center;justify-content:space-between;font-size:12.5px}
.dm-rc-st{transition:background .3s,color .3s}
/* the status dot is a mark: paused at the cap it takes the bright orange of the bar, while the words keep the darker text orange */
.dm-rc-st.dm-warn .dm-dot{background:var(--dm-warn-mark)}
.dm-rc-big{margin-top:6px;font-size:13px}
.dm-rc-n{font-size:14px;font-weight:500;letter-spacing:-.8px}
/* the track is the neutral rail; the fill is the accent's mark colour, and the warning mark at the cap */
.dm-rc-track{position:relative;height:6px;border-radius:var(--dm-r-xs);background:var(--dm-rail);margin:14px 0 var(--dm-s-4)}
.dm-rc-fill{height:100%;width:0;border-radius:var(--dm-r-xs);background:var(--dm-accent-mark,var(--dm-accent));transition:background .4s}
.dm-rc-cap{position:absolute;left:90%;top:-5px;bottom:-5px;width:2px;border-radius:1px;background:var(--dm-fg2);transition:opacity .3s}
.dm-rc-cap::before{content:"";position:absolute;inset:-6px -8px}
.dm-rc-rows{display:flex;flex-direction:column;gap:2px}
.dm-rc-rows div{display:flex;justify-content:space-between;padding:5px 0;font-size:13px;line-height:18px;color:var(--dm-fg2)}
.dm-rc-rows .dm-num{color:var(--dm-fg)}
.dm-rc-f{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:var(--dm-s-3);padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.dm-rc-cap-t{display:flex;align-items:center;gap:9px;font-size:13px;color:var(--dm-fg2);cursor:pointer}
.dm-rc-go{overflow:hidden;justify-content:flex-start}
/* Studio (owner, 17 and 18 Nov): a round card with its hairline, its content 16px in from every edge; the status chip in its
   status colours; a 6px grey rail with the accent fill (the warning mark at the cap) and an ink budget line. The rows are
   plain text (nothing to press, so no hover fill). The foot strip holds the controls 16px from the card's edges and its hairline (owner, 23 Nov): the cap's
   switch is a quiet control whose switch sits on the content's 16px edge, its hover round it, and the button a 28px pill,
   concentric with the card's corner */
:root[data-style="studio"] .dm-rc,:root [data-style="studio"] .dm-rc,:root [data-style="studio"].dm-rc{padding:16px 16px 0}
:root[data-style="studio"] .dm-rc-h,:root [data-style="studio"] .dm-rc-h,:root [data-style="studio"].dm-rc-h{font-size:12.5px}
:root[data-style="studio"] .dm-rc-big .dm-muted,:root [data-style="studio"] .dm-rc-big .dm-muted,:root [data-style="studio"].dm-rc-big .dm-muted{font-size:13px}
:root[data-style="studio"] .dm-rc-track,:root [data-style="studio"] .dm-rc-track,:root [data-style="studio"].dm-rc-track{height:6px;border-radius:var(--dm-r-tiny,3px);background:var(--dm-rail);margin:12px 0 10px}
:root[data-style="studio"] .dm-rc-fill,:root [data-style="studio"] .dm-rc-fill,:root [data-style="studio"].dm-rc-fill{border-radius:var(--dm-r-tiny,3px)}
:root[data-style="studio"] .dm-rc-cap,:root [data-style="studio"] .dm-rc-cap,:root [data-style="studio"].dm-rc-cap{background:var(--dm-fg)}
:root[data-style="studio"] .dm-rc-f,:root [data-style="studio"] .dm-rc-f,:root [data-style="studio"].dm-rc-f{margin:11px -16px 0;padding:var(--dm-strip-y) 16px;border-top:1px solid var(--dm-line);background:var(--dm-strip);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .dm-rc-cap-t,:root [data-style="studio"] .dm-rc-cap-t,:root [data-style="studio"].dm-rc-cap-t{height:28px;padding:0 10px 0 8px;border-radius:var(--dm-r-pill);gap:8px;transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .dm-rc-cap-t:hover,:root [data-style="studio"] .dm-rc-cap-t:hover,:root [data-style="studio"].dm-rc-cap-t:hover{background:var(--dm-row);color:var(--dm-fg)}}
/* (owner, 22 Nov: "foot buttons aligned") the switch itself sits on the content's 16px column, where Credits used starts, its
   hover pill reaching 8px out round it */
:root[data-style="studio"] .dm-rc-cap-t,:root [data-style="studio"] .dm-rc-cap-t,:root [data-style="studio"].dm-rc-cap-t{margin-left:-8px}
/* the running chip is the accent's tint with its words in the accent's text colour: blue in light mode, white in dark (owner,
   22 Nov: Studio dark's accents are white) */
:root[data-style="studio"] .dm-rc-st.dm-b,:root [data-style="studio"] .dm-rc-st.dm-b,:root [data-style="studio"].dm-rc-st.dm-b{background:var(--dm-accent-bg);color:var(--dm-accent-fg,var(--dm-accent))}
:root[data-style="studio"] .dm-rc-go,:root [data-style="studio"] .dm-rc-go,:root [data-style="studio"].dm-rc-go{transition:transform var(--dm-t-fast) var(--dm-ease),box-shadow var(--dm-t-fast) var(--dm-ease),background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (prefers-reduced-motion:reduce){:root[data-style="studio"] .dm-rc-cap-t,:root [data-style="studio"] .dm-rc-cap-t,:root [data-style="studio"].dm-rc-cap-t{transition:none}}
RunCost.astroAstro · 37 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Run cost: Live credit and token spend, with a cap that pauses the run.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change run-cost.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './run-cost.css';

export interface Props extends HTMLAttributes<'div'> {
  /** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
  'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', className]} data-c="run-cost" {...rest}>
  <div class="stage-in"><Fragment is:raw>
<div class="rc panel">
  <div class="rc-h"><span class="muted">Credits used</span><span class="rc-st tag"><span class="dot"></span><span class="rc-stt mx-w">Idle</span></span></div>
  <div class="rc-big"><span class="rc-n num">0</span><span class="muted"> / 2,000</span></div>
  <div class="rc-track"><div class="rc-fill"></div><div class="rc-cap" data-tip="The agent pauses here"></div></div>
  <div class="rc-rows">
    <div><span>Input tokens</span><span class="num rc-in">0</span></div>
    <div><span>Output tokens</span><span class="num rc-out">0</span></div>
    <div><span>Tool calls</span><span class="num rc-tools">0</span></div>
  </div>
  <div class="rc-f">
    <label class="rc-cap-t"><button class="toggle" role="switch" aria-checked="true" aria-label="Pause at 90 percent"></button><span>Pause at 90%</span></label>
    <button class="pill primary sm rc-go">Start run</button>
  </div>
</div>
  </Fragment></div>
</div>
<script>
  import './run-cost.js';
</script>
run-cost.htmlHTML · 19 lines
<div class="card" data-c="run-cost">
  <div class="stage-in">
    <div class="rc panel">
      <div class="rc-h"><span class="muted">Credits used</span><span class="rc-st tag"><span class="dot"></span><span class="rc-stt mx-w">Idle</span></span></div>
      <div class="rc-big"><span class="rc-n num">0</span><span class="muted"> / 2,000</span></div>
      <div class="rc-track"><div class="rc-fill"></div><div class="rc-cap" data-tip="The agent pauses here"></div></div>
      <div class="rc-rows">
        <div><span>Input tokens</span><span class="num rc-in">0</span></div>
        <div><span>Output tokens</span><span class="num rc-out">0</span></div>
        <div><span>Tool calls</span><span class="num rc-tools">0</span></div>
      </div>
      <div class="rc-f">
        <label class="rc-cap-t"><button class="toggle" role="switch" aria-checked="true" aria-label="Pause at 90 percent"></button><span>Pause at 90%</span></label>
        <button class="pill primary sm rc-go">Start run</button>
      </div>
    </div>
  </div>
</div>
run-cost.cssHTML · 44 lines
/* ---------- Run cost ---------- */
/* the card's content sits 16px in from every edge (owner, 18 Nov); nothing in it grows or shrinks when it is pressed */
.rc{padding:var(--dm-s-4)}
.rc :is(.pill,.ib):active{transform:none}
.rc-h{display:flex;align-items:center;justify-content:space-between;font-size:12.5px}
.rc-st{transition:background .3s,color .3s}
/* the status dot is a mark: paused at the cap it takes the bright orange of the bar, while the words keep the darker text orange */
.rc-st.warn .dot{background:var(--dm-warn-mark)}
.rc-big{margin-top:6px;font-size:13px}
.rc-n{font-size:14px;font-weight:500;letter-spacing:-.8px}
/* the track is the neutral rail; the fill is the accent's mark colour, and the warning mark at the cap */
.rc-track{position:relative;height:6px;border-radius:var(--dm-r-xs);background:var(--dm-rail);margin:14px 0 var(--dm-s-4)}
.rc-fill{height:100%;width:0;border-radius:var(--dm-r-xs);background:var(--dm-accent-mark,var(--dm-accent));transition:background .4s}
.rc-cap{position:absolute;left:90%;top:-5px;bottom:-5px;width:2px;border-radius:1px;background:var(--dm-fg2);transition:opacity .3s}
.rc-cap::before{content:"";position:absolute;inset:-6px -8px}
.rc-rows{display:flex;flex-direction:column;gap:2px}
.rc-rows div{display:flex;justify-content:space-between;padding:5px 0;font-size:13px;line-height:18px;color:var(--dm-fg2)}
.rc-rows .num{color:var(--dm-fg)}
.rc-f{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:var(--dm-s-3);padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.rc-cap-t{display:flex;align-items:center;gap:9px;font-size:13px;color:var(--dm-fg2);cursor:pointer}
.rc-go{overflow:hidden;justify-content:flex-start}
/* Studio (owner, 17 and 18 Nov): a round card with its hairline, its content 16px in from every edge; the status chip in its
   status colours; a 6px grey rail with the accent fill (the warning mark at the cap) and an ink budget line. The rows are
   plain text (nothing to press, so no hover fill). The foot strip holds the controls 16px from the card's edges and its hairline (owner, 23 Nov): the cap's
   switch is a quiet control whose switch sits on the content's 16px edge, its hover round it, and the button a 28px pill,
   concentric with the card's corner */
:root[data-style="studio"] .rc,:root [data-style="studio"] .rc,:root [data-style="studio"].rc{padding:16px 16px 0}
:root[data-style="studio"] .rc-h,:root [data-style="studio"] .rc-h,:root [data-style="studio"].rc-h{font-size:12.5px}
:root[data-style="studio"] .rc-big .muted,:root [data-style="studio"] .rc-big .muted,:root [data-style="studio"].rc-big .muted{font-size:13px}
:root[data-style="studio"] .rc-track,:root [data-style="studio"] .rc-track,:root [data-style="studio"].rc-track{height:6px;border-radius:var(--dm-r-tiny,3px);background:var(--dm-rail);margin:12px 0 10px}
:root[data-style="studio"] .rc-fill,:root [data-style="studio"] .rc-fill,:root [data-style="studio"].rc-fill{border-radius:var(--dm-r-tiny,3px)}
:root[data-style="studio"] .rc-cap,:root [data-style="studio"] .rc-cap,:root [data-style="studio"].rc-cap{background:var(--dm-fg)}
:root[data-style="studio"] .rc-f,:root [data-style="studio"] .rc-f,:root [data-style="studio"].rc-f{margin:11px -16px 0;padding:var(--dm-strip-y) 16px;border-top:1px solid var(--dm-line);background:var(--dm-strip);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .rc-cap-t,:root [data-style="studio"] .rc-cap-t,:root [data-style="studio"].rc-cap-t{height:28px;padding:0 10px 0 8px;border-radius:var(--dm-r-pill);gap:8px;transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .rc-cap-t:hover,:root [data-style="studio"] .rc-cap-t:hover,:root [data-style="studio"].rc-cap-t:hover{background:var(--dm-row);color:var(--dm-fg)}}
/* (owner, 22 Nov: "foot buttons aligned") the switch itself sits on the content's 16px column, where Credits used starts, its
   hover pill reaching 8px out round it */
:root[data-style="studio"] .rc-cap-t,:root [data-style="studio"] .rc-cap-t,:root [data-style="studio"].rc-cap-t{margin-left:-8px}
/* the running chip is the accent's tint with its words in the accent's text colour: blue in light mode, white in dark (owner,
   22 Nov: Studio dark's accents are white) */
:root[data-style="studio"] .rc-st.b,:root [data-style="studio"] .rc-st.b,:root [data-style="studio"].rc-st.b{background:var(--dm-accent-bg);color:var(--dm-accent-fg,var(--dm-accent))}
:root[data-style="studio"] .rc-go,:root [data-style="studio"] .rc-go,:root [data-style="studio"].rc-go{transition:transform var(--dm-t-fast) var(--dm-ease),box-shadow var(--dm-t-fast) var(--dm-ease),background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (prefers-reduced-motion:reduce){:root[data-style="studio"] .rc-cap-t,:root [data-style="studio"] .rc-cap-t,:root [data-style="studio"].rc-cap-t{transition:none}}
run-cost.jsHTML · 37 lines
DM.def('run-cost', (r, c) => {
  // the label crossfades on its own span, so the button itself never blurs
  const go = $('.rc-go', r); go.innerHTML = '<span class="rc-gl">Start run</span>'; const gl = () => $('.rc-gl', go);
  // the button is as wide as its words and eases to its new width when they change, keeping no room for a longer one (owner, 18 Nov)
  const easeW = el => { let w = 0, busy = null; const ro = new ResizeObserver(() => { if (busy) return; const w1 = el.getBoundingClientRect().width;
    if (!REDUCE && w && Math.abs(w1 - w) > .5){ busy = el.animate([{ width:w + 'px' }, { width:w1 + 'px' }], { duration:340, easing:'cubic-bezier(.23,1,.32,1)' }); busy.finished.catch(() => {}).then(() => { busy = null; w = el.getBoundingClientRect().width; }); } w = w1; });
    ro.observe(el); c.offs.push(() => ro.disconnect()); };
  easeW(go);
  const tg = $('.toggle', r), cap = $('.rc-cap', r), fill = $('.rc-fill', r), st = $('.rc-st', r), stt = $('.rc-stt', r);
  let used = 0, inT = 0, outT = 0, tools = 0, running = false, limit = 1800, loop = 0;
  const fmt = n => Math.round(n).toLocaleString('en-US');
  const paint = () => { $('.rc-n', r).textContent = fmt(used); fill.style.width = (used / 2000 * 100) + '%'; $('.rc-in', r).textContent = fmt(inT); $('.rc-out', r).textContent = fmt(outT); $('.rc-tools', r).textContent = tools; };
  const status = (t, cls) => { st.className = 'rc-st tag ' + (cls || ''); swap(stt, t); };
  const capOn = () => tg.getAttribute('aria-checked') === 'true';
  $('.rc-cap-t', r).onclick = e => { e.preventDefault(); tg.setAttribute('aria-checked', !capOn()); cap.style.opacity = capOn() ? 1 : .2; limit = capOn() ? 1800 : 2000; if (!running && used < limit && used > 0) go.disabled = false; };
  function stop(t, cls){ running = false; clearInterval(loop); status(t, cls); }
  go.onclick = () => {
    if (running){ stop('Stopped'); swap(gl(), 'Resume'); return; }
    if (used >= 2000){ used = inT = outT = tools = 0; paint(); }
    running = true; status('Running', 'b'); swap(gl(), 'Stop'); go.className = 'pill line sm rc-go'; fill.style.background = 'var(--dm-accent-mark,var(--dm-accent))';
    loop = c.every(90, () => {
      used = Math.min(2000, used + 8 + Math.random() * 18); inT += 120 + Math.random() * 220; outT += 30 + Math.random() * 70; if (Math.random() < .12) tools++;
      paint();
      if (used >= limit){
        used = limit; paint();
        if (limit < 2000){ stop('Paused at 90%', 'warn'); fill.style.background = 'var(--dm-warn-mark)'; swap(gl(), 'Raise cap'); go.className = 'pill primary sm rc-go'; go.onclick2 = true; }
        else { stop('Budget used', 'bad'); swap(gl(), 'Start over'); go.className = 'pill primary sm rc-go'; }
      }
    });
  };
  const orig = go.onclick;
  go.addEventListener('click', e => { if (go.onclick2 && !running){ go.onclick2 = false; e.stopImmediatePropagation(); tg.setAttribute('aria-checked','false'); cap.style.opacity = .2; limit = 2000; orig(); } }, true);
  paint();
  // the run starts by itself once the card has settled, so the spend can be seen climbing to the cap
  c.auto(1500, () => { if (!running && !used) go.click(); });
});
06

Questions

What people ask about it.

Does the component pause the agent when it reaches the cap?
No. It shows the cap and whether it is on. Your code compares used with the cap, stops the agent and sets status to 'paused'.
What should the button do?
Whatever fits the status, through onAction. Its label suggests the usual move, for example Stop while running or Raise cap when paused. The demo turns the cap off and runs on to the full budget when Raise cap is pressed.
Can I show money instead of credits?
The numbers are shown as whole numbers with thousands separators and no currency sign. You can change title to name the unit, for example "Cents used".
07

More in Agent status

Show what the agent is doing, how far along it is, and what it is working with.

ThinkingThe live trace, written as the agent works, then folded away.
Reasoning trailThe agent's plan, notes, sources and edits, after it thinks.
Parallel agentsSeveral agents working in parallel, each with its own lane and hand-offs.
Delegation treeAn orchestrator and its sub-agents, with cost rolled up per branch.
Approval queueEvery run that needs you, is running or is done, in one list.
Trace viewOne agent run as a waterfall of spans, with latency and tokens.
Web searchThe agent's searches as a trail: what it asked, what came back, what it read or skipped, and the answer with its sources.
Agent run timelineEvery model and tool step of a run on one time axis.
All 15 in Agent status →