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.
How It Works
Section titled “How It Works”- Each pipeline stage records its input and output token counts
- Costs are calculated using model-specific pricing (Opus, Sonnet, Haiku)
- 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
- All cost entries are stored with timestamps for trend analysis
Quick Start
Section titled “Quick Start”# View 7-day cost summaryshipwright cost show
# 30-day breakdown by pipeline stageshipwright cost show --period 30 --by-stage
# Breakdown by GitHub issueshipwright cost show --by-issue
# Set a daily budget of $50shipwright cost budget set 50.00
# Check current budget usageshipwright cost budget show
# Estimate cost for a specific workloadshipwright cost calculate 50000 10000 opus# → 0.5000 (USD)Model Pricing
Section titled “Model Pricing”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.
Commands
Section titled “Commands”| 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 |
Pipeline Integration Commands
Section titled “Pipeline Integration Commands”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) |
Budget Enforcement
Section titled “Budget Enforcement”Set a daily budget to prevent unexpected spending:
# Set a $50/day limitshipwright cost budget set 50.00The 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.
Cost Dashboard
Section titled “Cost Dashboard”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.00Trend Analysis
Section titled “Trend Analysis”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% |
Cost Optimization Tips
Section titled “Cost Optimization Tips”- 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-stageto identify which stages consume the most tokens and optimize accordingly. - Track by issue — Use
--by-issueto understand cost per feature and estimate future work.
Intelligent Cost Prediction
Section titled “Intelligent Cost Prediction”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.