Skip to content

feat: add --format json to report, today, and month commands - #53

Merged
AgentSeal merged 4 commits into
getagentseal:mainfrom
mallek:feature/json-output
Apr 16, 2026
Merged

AgentSeal merged 4 commits into
getagentseal:mainfrom
mallek:feature/json-output

Conversation

@mallek

@mallek mallek commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds --format json to the report, today, and month commands, outputting full dashboard data as structured JSON to stdout.

The existing JSON options (status --format json and export -f json) are limited — status only gives today/month cost+calls, and export writes to a file. This adds a comprehensive JSON output that mirrors everything in the TUI dashboard.

JSON structure

{
  "generated": "2026-04-16T...",
  "currency": "USD",
  "period": "Last 7 Days",
  "overview": { "cost", "calls", "sessions", "cacheHitPercent", "tokens": {...} },
  "daily": [{ "date", "cost", "calls" }],
  "projects": [{ "name", "path", "cost", "calls", "sessions" }],
  "models": [{ "name", "cost", "calls", "inputTokens", "outputTokens", ... }],
  "activities": [{ "category", "cost", "turns", "editTurns", "oneShotTurns", "oneShotRate" }],
  "tools": [{ "name", "calls" }],
  "mcpServers": [{ "name", "calls" }],
  "shellCommands": [{ "name", "calls" }]
}

Usage

codeburn report --format json             # 7-day JSON report
codeburn today --format json              # today as JSON
codeburn month --format json              # this month as JSON
codeburn report -p 30days --format json   # 30-day window
codeburn report --format json | jq '.projects'

Changes

  • src/cli.ts — buildJsonReport() function + --format option on report, today, month
  • README.md — documented JSON output with examples

Test plan

  • report --format json outputs valid JSON with all sections
  • today --format json works
  • month --format json works
  • Currency conversion applied to cost fields
  • Default --format tui still launches interactive dashboard
  • --help shows new option
  • Clean build with tsup

🤖 Generated with Claude Code

@mallek

mallek commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

How you could use this feature:

  1. Daily cost tracking/alerting — pipe today --format json | jq '.overview.cost' into a script, alert if it crosses a threshold
  2. Project budgeting — track per-project spend over time, set soft caps
  3. Model optimization — you're spending $XXX on Opus vs $XX on Sonnet. For some of those Exploration turns, Sonnet might be fine
  4. Activity audit — Conversation is $XX (9% of spend) for 703 turns. That's a lot of chat vs. code
  5. Grafana/dashboard — push daily JSON into a time-series store and build trend charts
  6. Weekly reports — automate a /session-report enrichment with cost data
  7. Cost-per-project-per-day — cross-reference daily + project data to spot which project is spiking on which days

Outputs full dashboard data as structured JSON to stdout, including:
overview, daily breakdown, projects, models with token counts,
activities with one-shot rates, core tools, MCP servers, and
shell commands.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@mallek
mallek force-pushed the feature/json-output branch from 273525c to 09139b1 Compare April 16, 2026 18:22

@AgentSeal AgentSeal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, it's a genuinely useful feature and moves codeburn from "TUI" to "data source you can pipe into CI, Slack bots, or custom dashboards". Structure is clean and the README update is thorough.

One real bug to fix before merge (inline comment below). Also a small style point: the section-label comments (// daily, // projects, // models, etc.) should come out, since the repo CLAUDE.md says "No comments unless the WHY is non-obvious".

Nice-to-haves for a follow-up, not this PR:

  • Expose a machine-readable period key alongside the display label (e.g. "periodKey": "week" next to "period": "Last 7 Days"). Easier for programmatic consumers to match on.
  • topSessions from the recent TUI addition isn't in the JSON yet, even though the description says the output mirrors the dashboard. Fine to add later.

Appreciate the contribution.

Comment thread src/cli.ts Outdated
}
const models = Object.entries(modelMap)
.sort(([, a], [, b]) => b.cost - a.cost)
.map(([name, d]) => ({ name, cost: convertCost(d.cost), ...d, cost_usd: undefined }))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currency bug: because ...d comes after cost: convertCost(d.cost), the spread resets cost back to d.cost (which is USD) and every models[].cost in the output ignores the selected currency. The two-step cost_usd strip on the next line is also dead code, there's no cost_usd key on d.

One-liner fix that matches the pattern used in projects and activities above:

.map(([name, d]) => ({ name, ...d, cost: convertCost(d.cost) }))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fad21f3 — destructured cost out before the spread so convertCost result is no longer overwritten. Collapsed the two-step map into one while I was at it since the cost_usd strip was dead code as noted.

Also addressed the style feedback (section-label comments removed) and went ahead and added both nice-to-haves in 7a061ea — periodKey alongside period, and topSessions (top 5 by cost, same logic as the TUI panel).

@AgentSeal

Copy link
Copy Markdown
Collaborator

heads up, your commit email ([email protected]) isn't linked to your github account so you're not showing up in the contributor graph even though the PRs are merging fine. you can add it as a verified email in github settings → emails and it'll backfill existing commits. or switch your git config user.email for this repo to an address already on your account. just wanted you to get the credit you're earning.

@mallek

mallek commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the heads up, I generally contribute with my personal email however my company has been looking to empower us to contribute to open source so this was my first step into the space on this account.

@AgentSeal AgentSeal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all three review items addressed, currency fix is correct. merging. the unused getCostColumnHeader import and the three near-identical json branches will get a small cleanup commit on main right after.

@AgentSeal
AgentSeal merged commit f3482de into getagentseal:main Apr 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants