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 shows a compact summary: the live context size (the tokens the model currently reads each turn) against the context limit, and the estimated session cost once it passes a tenth of a cent, for example 98.5K/272.0K ctx · ~$1.8402. The limit is the model's context window, or your auto-compact window when that is smaller. A ~ before a number means it is estimated rather than reported by the provider.
The status line deliberately leaves out the session's cumulative token count. /status shows it, as input (with the share served from the prompt cache) and output.
For the full breakdown, run /cost:
Token Usage:
Input: 1.1M tokens (640.2K served from the prompt cache)
Output: 85.3K tokens
Turns: 42
Estimated cost: $1.8402Costs 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 rolls up into the session totals as it happens, so /cost reflects everything the session spent, delegated work included.
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:
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.
/help lists the built-in commands only. Type / to see everything, including skills, custom commands, and MCP prompts.
Context Compaction
As a conversation grows, every turn sends more history to the model. When the live context passes the compaction threshold, pw code compacts the conversation: 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 so a later resume sees the compacted history.
When Compaction Runs
The threshold follows the model's context window: the window minus a reserve of 20% of it, at most 100,000 tokens. A 272K-token window compacts at about 218K; a 1M-token window at 900K. For a model whose window is unknown (such as a custom provider), the threshold is 102,400 tokens.
Compaction is checked at the end of every turn, and also between tool calls in the middle of a long turn, so a turn that reads many files does not run out of room before it finishes. If a request is rejected because the context is too long, pw code compacts and retries it.
Before summarizing, pw code first trims old tool output (large file reads and command output from earlier in the conversation), keeping the start and end of each and leaving the newest output untouched. When that frees enough room, no summary is needed.
Compacting Manually
Run /compact at any time to compact now and see the summary it produced. Add a focus to steer what the summary keeps:
/compact keep the list of failing tests and the fix we agreed onA compaction runs while you can keep typing. Press Ctrl+C or Esc to cancel it.
Changing the Threshold
/autocompact sets a context limit for auto-compaction across all models and sessions, saved as the autoCompactWindow setting:
/autocompact 200k # size compaction as if the window were 200K tokens
/autocompact auto # use each model's own window (the default)
/autocompact # show the current valueThe limit is capped by the model's own window and appears as the ctx limit in the status line. The threshold is then computed from it the same way as above.
For an exact token count instead, set compactAt in your settings. When the model's window is known, compactAt cannot be higher than the threshold computed from it, so it can only make compaction happen earlier:
{
"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:
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.
{
"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 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 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: Feature overview and quick start
- Non-Interactive Mode: Usage and cost fields in JSON output
- Subagents: How delegated work is counted
- Sessions & Resume: Where compacted history is stored
- Settings:
compactAt,autoCompactWindow,maxTurnTokens, and other options - Models & Allocations: Budget allocations for organization providers
- AI Usage: Account-level usage reporting