Skip to content

Usage Tracking

Reygent tracks cost, tokens, and duration for every agent invocation. Data flows from providers through UsageTracker to a summary displayed at the end of each run.

UsageInfo Fields

FieldTypeDescription
costUsdnumberTotal cost in USD
durationMsnumberWall-clock time of the invocation
inputTokensnumberPrompt/input token count
outputTokensnumberCompletion/output token count
numTurnsnumberNumber of agentic turns (Claude)

All fields are optional. Providers report what they can.

Provider Coverage

ProviderDurationInput TokensOutput TokensCostTurns
ClaudeYesYesYesYesYes
OpenRouterYesYesYesYes*No
GeminiYesBest-effortBest-effortNoNo
CodexYesBest-effortBest-effortNoNo

* OpenRouter cost depends on the upstream model reporting total_cost in the API response.

Gemini and Codex are CLI providers. Token counts depend on whether the CLI includes usage metadata in its JSON output. Duration is always available since it is measured client-side.

Data Flow

  1. Provider spawn() returns SpawnResult with optional usage: UsageInfo
  2. src/spawn.ts passes SpawnResult.usage to the caller
  3. src/implement.ts / src/gate.ts call UsageTracker.record(agent, stage, usage)
  4. src/commands/run.ts calls printUsageSummary(tracker) at the end of the run

UsageTracker API

  • record(agent, stage, usage) — store one entry
  • getTotalCost() — sum of all costUsd values
  • getByAgent() — aggregated stats per agent name
  • getEntries() — raw entry list

Summary Output

printUsageSummary() displays a table with total cost, duration, token counts, and per-agent breakdown. Always shown at the end of reygent run.

printVerboseUsage() shows every individual invocation with full detail including stage names, duration, turn count, input/output tokens, and cache metadata. Only shown when reygent run --verbose flag is passed.

Released under the Apache-2.0 License.