Claude Code

Export Claude usage history

Export Claude Code usage from local JSONL logs to CSV. The columns to keep, the ones to drop, and how to handle cost.

Quick answer

Read each JSONL log under `~/.claude/projects`, keep the timestamp, session ID, model, and token fields, and drop message content. Write one row per assistant message to CSV. Cost is computed from tokens and current rates, not copied from the log.

Columns to keep

ColumnUseSensitive
timestampTrendNo
session_idGroupingNo
projectAttributionMildly
modelEfficiencyNo
input_tokensVolumeNo
cache_readDiscountNo
cache_writeFirst-turn costNo
output_tokensGenerationNo

Prompts and file contents are sensitive and unnecessary for a usage report.

Shape the export

for f in ~/.claude/projects/*/*.jsonl; do
  jq -c 'select(.type=="assistant") | {ts:.timestamp, session:.sessionId, model:.message.model, usage:.message.usage}' "$f"
done > claude-usage.ndjson

Field names vary by version. Inspect one line before assuming the paths.

Before sharing

  • Aggregate to daily rows for team reports.
  • Drop project paths if they reveal client names.
  • State the rate basis for computed cost.
  • Keep the raw logs private.

Export without exporting prompts

The session files contain full conversations. Any export for reporting should reduce them to tokens, model, timestamp, and project before it leaves your machine.

  1. Parse the JSONL files for the period.
  2. Keep the usage fields and drop message content.
  3. Write one row per assistant turn or per session.
  4. Record the source path and the export date.
  5. Store the export somewhere with the same access rules as the logs.

UsageAtlas shows the aggregates without a script, and the token report guide covers the field list.

Questions, answered

Does Claude Code have a CSV export?

Not a general one. The logs are JSONL, so export means parsing them or using a tracker.

Can I export chat usage?

Chat usage is not stored in the same local logs. Use the account usage view or billing export.

Is the export safe to share?

Only if it excludes prompts, file paths, and content. Token and cost fields alone are safe.

Browse by topic