Skip to content

Cost Intelligence

Cost intelligence (shipwright cost) tracks every token spent across your pipelines, calculates costs by model, and enforces daily budgets to prevent runaway spending. It gives you full visibility into where your AI budget goes.

  1. Each pipeline stage records its input and output token counts
  2. Costs are calculated using model-specific pricing (Opus, Sonnet, Haiku)
  3. A daily budget gate checks spending before each pipeline starts. It warns at 80% of the daily budget and blocks a pipeline when today’s spend plus the estimated cost would exceed the budget
  4. All cost entries are stored with timestamps for trend analysis
Terminal window
# View 7-day cost summary
shipwright cost show
# 30-day breakdown by pipeline stage
shipwright cost show --period 30 --by-stage
# Breakdown by GitHub issue
shipwright cost show --by-issue
# Set a daily budget of $50
shipwright cost budget set 50.00
# Check current budget usage
shipwright cost budget show
# Estimate cost for a specific workload
shipwright cost calculate 50000 10000 opus
# → 0.5000 (USD)

Costs are calculated using per-model rates (USD per 1M tokens):

Model Input Output
Opus $5.00 $25.00
Sonnet $3.00 $15.00
Haiku $1.00 $5.00

These are the built-in defaults. Override them per machine with ~/.shipwright/model-pricing.json.

Command Description
shipwright cost show Show cost summary for the current period
shipwright cost show --period <days> Custom period (default: 7 days)
shipwright cost show --by-stage Breakdown by pipeline stage
shipwright cost show --by-issue Breakdown by GitHub issue
shipwright cost show --json JSON output for tooling
shipwright cost budget set <amount> Set daily budget in USD
shipwright cost budget show Show current budget and today’s usage

These are called automatically by the pipeline:

Command Description
shipwright cost record <in> <out> <model> <stage> [issue] Record token usage
shipwright cost calculate <in> <out> <model> Calculate cost without recording
shipwright cost check-budget [estimated_usd] Pre-flight budget check
shipwright cost remaining-budget Return remaining daily budget as a number (used by daemon auto-scaler)

Set a daily budget to prevent unexpected spending:

Terminal window
# Set a $50/day limit
shipwright cost budget set 50.00

The budget system has two thresholds:

Threshold Behavior
80% used Warning logged, pipeline continues
Projected over budget Pipeline blocked (today’s spend + estimate > budget), event emitted

The budget resets daily at midnight UTC.

shipwright cost show displays a summary with spending totals, token counts, and trend analysis. The block below is an example layout with illustrative numbers:

━━━ Cost Intelligence ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Period: last 7 day(s)
SPENDING SUMMARY
Total cost $42.18
Avg per pipeline $3.52
Max single pipeline $8.91
Entries 12
TOKENS
Input tokens 1,240,000
Output tokens 380,000
TREND
↓ 15% (decreasing)
DAILY BUDGET
████████████░░░░░░░░ 62%
$31.05 / $50.00

The dashboard compares spending in the first and second halves of the period to detect trends:

Trend Meaning
↑ N% (increasing) Spending grew by more than 10%
↓ N% (decreasing) Spending dropped by more than 10%
→ stable Change within 10%
  • Use Sonnet for most stages — At the default rates, Opus costs about 1.7x Sonnet per token ($5 vs $3 input, $25 vs $15 output).
  • Reserve Opus for the stages that need it — The cost-aware template routes plan and build to Sonnet and reserves Opus for review.
  • Use Haiku where the task is simple — The cost-aware template uses Haiku for intake, test, audit, and PR stages. Keep review on a stronger model.
  • Set budgets early — A daily budget prevents surprises during autonomous daemon operation.
  • Monitor by stage — Use --by-stage to identify which stages consume the most tokens and optimize accordingly.
  • Track by issue — Use --by-issue to understand cost per feature and estimate future work.

With the intelligence layer enabled, the intelligence_predict_cost function estimates token usage and cost before a pipeline runs, based on issue complexity and historical data. The intelligence_recommend_model function routes each stage to the cheapest model that can handle the task — using haiku for simple stages and opus only when complexity warrants it. See the Intelligence guide for details.