# Usage & Costs

> Source: https://parallelworks.com/docs/ai/code/usage-and-costs

# Usage & Costs

`pw code` tracks token usage and estimated cost throughout a session, keeps long conversations within the model's context window through compaction (summarizing older messages to free context space), and lets you cap how much a single turn can consume.

## Session Usage: `/cost` and the Status Line

The status line at the bottom of the interface always shows a compact summary: the **live context size** (the tokens the model currently reads each turn), the **cumulative total** for the session, and the estimated cost once it is non-trivial, for example `98.5K ctx · 1.2M total (~$1.8402)`.

For the full breakdown, run `/cost`:

```text
Token Usage:
  Input:  1.1M tokens
  Output: 85.3K tokens
  Turns: 42
  Estimated cost: $1.8402
```

Costs are estimated from the per-token rates configured on the platform for each model, priced per model, so a session that switched models is costed against the model that produced each turn. Usage from [subagents](/docs/ai/code/subagents) rolls up into the session totals as it happens, so `/cost` reflects everything the session spent, delegated work included.

:::note Estimates depend on configured rates
Models with no configured rate, such as custom or session-tunnel providers, contribute nothing to the estimate. A session that used such a model can show a lower cost than it actually incurred.
:::

## Provider Quotas: `/usage`

Some providers report their own usage limits, most notably a connected ChatGPT/Codex subscription, which has rolling quota windows. For models from such a provider, `/usage` shows each window as a bar with its reset time:

```text
Provider usage (plus plan)

5-hour limit
  [████████░░░░░░░░░░░░] 41.0% used
  Resets Jul 19, 2026 at 6:00 PM CDT

Weekly limit
  [██░░░░░░░░░░░░░░░░░░] 12.5% used
  Resets Jul 23, 2026 at 9:00 AM CDT
```

`/usage` is only available when the selected model's provider reports usage information; otherwise the command is hidden from the palette and `/help`. This is the provider's own quota, separate from the platform cost estimate above.

## Context Compaction

As a conversation grows, every turn sends more history to the model. When the live context reaches the compaction threshold (**100,000 input tokens** by default), `pw code` automatically compacts the conversation at the end of the turn: older messages are replaced with a model-written summary, while the system prompt and the most recent messages are kept verbatim. The conversation continues seamlessly, the `ctx` figure in the status line drops, and the compaction is recorded in the [session file](/docs/ai/code/sessions) so a later resume sees the compacted history.

You can also compact manually at any time with `/compact`, which shows you the summary it produced.

The threshold is configurable with the `compactAt` setting (a token count) in your [settings](/docs/ai/code/settings):

```json
{
  "compactAt": 150000
}
```

## Per-Turn Budget: `maxTurnTokens`

The `maxTurnTokens` setting caps how many tokens (input plus output) a single turn may consume across all of its model requests. When a turn reaches the budget, it stops with a message in the transcript:

```text
Turn stopped: per-turn token budget of 200000 reached.
```

The session itself continues, and you can send the next message as usual. Unset (or `0`) means no per-turn limit. This is a useful guardrail for autonomous multi-step work, where a single prompt can otherwise fan out into many tool-calling iterations.

```json
{
  "maxTurnTokens": 200000
}
```

## Usage in Non-Interactive Runs

One-shot (non-interactive) runs report the same numbers. In text mode, the status-line summary is printed to stderr when the run completes; with `-o json`, the output object carries `usage.input_tokens`, `usage.output_tokens`, `usage.total_tokens`, and `estimated_cost`. See [Non-Interactive Mode](/docs/ai/code/non-interactive) for the full schema. Subagent usage is included in these totals; there is no per-subagent breakdown.

## Account-Level Usage

The estimates above are per-session. For metered spend and token reporting across your account (including Chat, AI keys, and allocation budgets), use the [AI Usage](/docs/ai/ai-usage) dashboard under **AI** > **AI Usage** in ACTIVATE. Organization admins can also see organization-wide usage there, grouped by model, user, or allocation.

## Related Documentation

- [pw code Overview](/docs/ai/code): Feature overview and quick start
- [Non-Interactive Mode](/docs/ai/code/non-interactive): Usage and cost fields in JSON output
- [Subagents](/docs/ai/code/subagents): How delegated work is counted
- [Sessions & Resume](/docs/ai/code/sessions): Where compacted history is stored
- [Settings](/docs/ai/code/settings): `compactAt`, `maxTurnTokens`, and other options
- [Models & Allocations](/docs/ai/code/models): Budget allocations for organization providers
- [AI Usage](/docs/ai/ai-usage): Account-level usage reporting
