Skip to main content

Analytics dashboard for Claude Code sessions

Project description

Claude Code Tracer - Backend

FastAPI-based analytics API for Claude Code sessions. Reads session data from ~/.claude/projects/ and provides endpoints for viewing metrics, messages, tool usage, and subagent activity.

Installation

# Using pip
pip install claude-code-tracer

# Using uv
uv tool install claude-code-tracer

# Run the dashboard
cctracer

Project Structure

src/claude_code_tracer/
├── main.py              # FastAPI app entry point
├── routers/
│   ├── sessions.py      # Session and message endpoints
│   ├── metrics.py       # Aggregated metrics endpoints
│   └── subagents.py     # Subagent-specific endpoints
├── models/
│   ├── entries.py       # Base data models (TokenUsage, ToolUse)
│   └── responses.py     # API response models
└── services/
    ├── database.py      # DuckDB connection, file discovery
    ├── log_parser.py    # JSONL session parsing
    ├── metrics.py       # Cost calculation, pricing
    └── queries.py       # DuckDB SQL queries

API Endpoints

Projects

Endpoint Description
GET /api/projects List all projects with aggregated metrics
GET /api/projects/{hash}/sessions List sessions for a project
GET /api/projects/{hash}/metrics Aggregated metrics across all sessions
GET /api/projects/{hash}/tools Tool usage across all sessions

Sessions

Endpoint Description
GET /api/sessions/{hash}/{id} Session details
GET /api/sessions/{hash}/{id}/messages Paginated messages (supports filtering)
GET /api/sessions/{hash}/{id}/messages/filters Available filter options
GET /api/sessions/{hash}/{id}/messages/{uuid} Single message detail
GET /api/sessions/{hash}/{id}/messages/by-index/{idx} Message by index
GET /api/sessions/{hash}/{id}/metrics Session metrics
GET /api/sessions/{hash}/{id}/tools Tool usage stats
GET /api/sessions/{hash}/{id}/subagents Subagents spawned
GET /api/sessions/{hash}/{id}/skills Skills invoked
GET /api/sessions/{hash}/{id}/code-changes File changes
GET /api/sessions/{hash}/{id}/errors Error entries
GET /api/sessions/{hash}/{id}/commands User commands

Subagents

Endpoint Description
GET /api/subagents/{hash}/{agent_id} Subagent details
GET /api/subagents/{hash}/{agent_id}/tools Subagent tool usage
GET /api/subagents/{hash}/{session_id}/{agent_id} Subagent within session context
GET /api/subagents/{hash}/{session_id}/{agent_id}/messages Subagent messages

Metrics

Endpoint Description
GET /api/metrics/pricing Current model pricing (from LiteLLM)
GET /api/metrics/daily/{hash} Daily metrics for a project
GET /api/metrics/aggregate Global or per-project aggregates

Health

Endpoint Description
GET / API info
GET /health Health check

CLI Usage

cctracer                  # Start server, opens browser at http://localhost:8420
cctracer --port 9000      # Custom port
cctracer --no-browser     # Don't auto-open browser
cctracer --reload         # Enable auto-reload for development

Development Setup

# Install dependencies
uv sync --all-extras

# Run development server
uv run uvicorn claude_code_tracer.main:app --reload --port 8420

# Or use the CLI with reload
uv run cctracer --reload

# API docs at http://localhost:8420/docs

Environment Variables

Variable Default Description
CLAUDE_DIR ~/.claude Claude data directory

Development

# Linting and formatting
uv run ruff check .
uv run ruff format .

# Type checking
uv run mypy src/

# Run tests
uv run pytest

Tech Stack

  • FastAPI - Web framework
  • DuckDB - In-memory SQL for querying JSONL files
  • Pydantic - Data validation and serialization
  • orjson - Fast JSON parsing
  • httpx - HTTP client for fetching pricing data

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_code_tracer-0.1.4.tar.gz (320.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_code_tracer-0.1.4-py3-none-any.whl (332.1 kB view details)

Uploaded Python 3

File details

Details for the file claude_code_tracer-0.1.4.tar.gz.

File metadata

  • Download URL: claude_code_tracer-0.1.4.tar.gz
  • Upload date:
  • Size: 320.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for claude_code_tracer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 39483575bf56422fec257e34e0b4c7ac3dc7727d80e91120c979cb53d265f4b0
MD5 f8d1a70bd58f36785081fd8aac048b3d
BLAKE2b-256 904a2cf8e968920256f147ec0df043b63a85fee6ca5e8a3af1c57053dca5fee7

See more details on using hashes here.

File details

Details for the file claude_code_tracer-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: claude_code_tracer-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 332.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for claude_code_tracer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0f857a1b81ffd0ffd8be93c00729e261e9200bfe561b38a15b7f10f387e6686a
MD5 f0d22b73af04335a9827505e7129c564
BLAKE2b-256 c3bea4c654f57bd3a049754391548caafc4d6586d68018f402aac94d41242780

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page