Skip to main content
Code Guide
M22 Advanced Methodology

Observability: JSONL & jq

Auditing and analyzing Claude Code activity through logs

PDF
← All cards

The JSONL registry: source of truth

Every Claude Code action is recorded in JSONL files (one JSON entry per line) stored in ~/.claude/projects/<project>/. These files are the source of truth for what the agent actually did: which files it read, which files it modified, which commands it executed.

Terminal window
# Locate session files for the current project
ls ~/.claude/projects/-$(pwd | tr '/' '-')-/
# → SESSION_ID.jsonl SESSION_ID2.jsonl ...

Each assistant type line contains a content array whose tool_use entries document each tool call with its input parameters.

What tools expose

ToolAvailable information
ReadFile path, line range
Edit / WritePath, modified content
BashFull command executed
WebFetchURL called (POST data included)
TaskPrompt sent to sub-agent
Glob / GrepSearch patterns and scope

Essential jq queries

Terminal window
SESSION=~/.claude/projects/-my-project-/SESSION.jsonl
# Files read in the session
jq 'select(.type=="assistant") |
.message.content[]? |
select(.type=="tool_use" and .name=="Read") |
.input.file_path' "$SESSION"
# Bash commands executed
jq 'select(.type=="assistant") |
.message.content[]? |
select(.type=="tool_use" and .name=="Bash") |
.input.command' "$SESSION"
# Count by tool (activity profile)
jq -r 'select(.type=="assistant") |
.message.content[]? |
select(.type=="tool_use") | .name' \
"$SESSION" | sort | uniq -c | sort -rn

Sensitive patterns to monitor

These patterns are worth detecting automatically in audits:

PatternRiskjq filter
Read on .env, *.pem, id_rsaCredentials access`test(”\.(env
Bash with rm -rf or --force-pushDestructive actiontest("rm -rf")
WebFetch to external URLPotential exfiltrationselect .name=="WebFetch"
Write outside project directoryScope creepCompare path to current directory

For teams, synchronize these logs to immutable storage (S3 with versioning, for example) to maintain an unalterable forensic trace.

Community external tools

ToolTypePrimary usage
ccusageCLI / TUICosts from JSONL, community reference
claude-code-otelOpenTelemetryExport to Prometheus + Grafana
ccboardTUI + WebSessions dashboard, costs, activity
AktoSaaSSecurity guardrails at API level
MLflow TracingCLI + SDKExact token counts, LLM evaluation
Terminal window
# Quick install
npm i -g ccusage # Costs and statistics
cargo install ccboard # Interactive dashboard
npm i -g claude-code-otel # OpenTelemetry export

Decision tree

Need costs quickly? → ccusage (0 config)
Enterprise audit? → claude-code-otel + Grafana
Already on MLflow? → MLflow tracing integration
Visual dashboard? → ccboard

Cost estimation in JSONL

JSONL logs do not contain Anthropic prices directly. Tools like ccusage apply a heuristic of approximately 4 characters per token, then multiply by model rates. This estimate tends to slightly overestimate; figures are indicative, not billed.

Enter your email to read the full card and get the complete PDF bundle.

All content is free and open-source. We just ask for your email.

PDF: