Skip to main content

Claude Code MLflow Tracing

PyPI version Python versions License: MIT CI codecov

A simple helper CLI to help you setup the MLFlow tracing in Claude Code in Databricks. While the MLFlow documentation already can set up claude code tracing for you with the command mlflow autolog claude this goes a step further in guiding you through the process such to make sure your experiments have the same naming convention as well as use the correct profile and prevent the use of a PAT.

Installation

uv add claudetracing

Or with pip:

pip install claudetracing

Quick Start

Run the interactive setup in your project directory:

traces init

This will:

  1. Authenticate with Databricks (or use existing credentials)
  2. Configure your experiment path (shared or personal)
  3. Create .claude/settings.json with the proper hooks
  4. Update .gitignore

Restart Claude Code after setup. Traces are automatically sent to Databricks when sessions end.

CLI Commands

traces init                      # Interactive setup
traces list                      # List available experiments
traces search                    # Search recent traces
traces search -e <experiment>    # Filter by experiment name
traces search --hours 24         # Last 24 hours
traces search --trace-id <id>    # Get specific trace
traces search -f json            # Output as JSON
traces search -f context         # LLM-optimized format

Enrichments

Enrichments add extra metadata to your traces. They are optional and can be enabled per-project. Multiple enrichments can be active simultaneously.

Available Enrichments

Name Description
git Adds git repository context: commit ID, branch, remote URL, repo name
files Adds list of files modified (written/edited) during the session
tokens Adds token usage statistics including cache metrics
model Adds the Claude model(s) that served the session

Managing Enrichments

traces enrichment list              # List available enrichments
traces enrichment info git          # Show details about an enrichment
traces enrichment add git files     # Enable multiple enrichments
traces enrichment remove tokens     # Disable an enrichment

After adding or removing enrichments, restart Claude Code to apply the changes.

Git Enrichment

Correlate traces with specific commits and branches:

  • git.commit_id - Full commit SHA
  • git.branch - Current branch name
  • git.remote_url - Origin remote URL
  • git.repo_name - Repository name (e.g., org/repo)

Files Enrichment

Track which files were modified during the session:

  • files.modified - JSON array of file paths that were written or edited

Tokens Enrichment

Monitor token consumption and cache efficiency:

  • tokens.input - Total input tokens
  • tokens.output - Total output tokens
  • tokens.cache_read - Tokens read from prompt cache
  • tokens.cache_creation - Tokens written to prompt cache
  • tokens.total - Total tokens (input + output)

Model Enrichment

See which Claude model(s) served the session:

  • model - Comma-separated distinct models seen in the transcript
  • model.primary - Model with the most assistant messages

MLflow tracing for Claude Code sessions with Databricks integration. Automatically captures conversations, tool usage, and session metadata.

Why Trace Claude Code Sessions?

When Claude Code becomes part of your development workflow, visibility into how it's being used becomes valuable:

  • Review past sessions - What did Claude do while you were away? Search and replay any session to understand decisions made.
  • Team insights - See how your team uses Claude Code across projects. Identify patterns, common tasks, and areas for improvement.
  • Debug failures - When something goes wrong, trace data shows exactly which tools were called, in what order, and what inputs/outputs were involved.
  • Cost awareness - Track token usage and session duration to understand resource consumption.
  • Compliance & audit - Maintain records of AI-assisted code changes for regulated environments.

Prerequisites

  • Python 3.10+
  • Databricks CLI installed
  • Access to a Databricks workspace

What Gets Traced

  • User prompts and Claude responses
  • Tool usage (Read, Write, Edit, Bash, etc.)
  • Execution timing per operation
  • Session metadata (user, working directory, git branch)

How It Works

  1. The traces init command creates a .claude/settings.json file
  2. This configures a Stop hook that runs when Claude Code sessions end
  3. The hook calls MLflow's built-in Claude Code tracing to capture the session
  4. Traces are uploaded to your Databricks MLflow experiment

FAQ

Why might my traces have different metadata than my teammate's?

Enrichment configuration is stored locally per-user in .claude/settings.json. If teammates configure different enrichments, their traces will have different tags. See ADR-001 for the design rationale.

What happens when I join an existing experiment?

During traces init, we check existing traces for enrichment patterns. If enrichments are detected, you'll see:

Enrichment mismatch detected
Existing traces use: files, git, tokens

Options:
  [1] Match existing enrichments (recommended)
  [2] Continue without enrichments
  [3] Cancel setup

Choosing option 1 automatically enables the matching enrichments.

Why warn instead of auto-configuring enrichments?

We chose advisory warnings over enforcement because:

  • Teams may intentionally use different enrichments for different use cases
  • Some users may not have all enrichments available (e.g., no git repo)
  • Respecting user autonomy while surfacing potential issues

License

MIT


Built with Claude Opus 4.5

Metadata

Release files for claudetracing 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for claudetracing 0.4.0
File Size Uploaded
claudetracing-0.4.0.tar.gz 342.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for claudetracing 0.4.0
File Interpreter ABI Platform
claudetracing-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 367.8 kB

Release files / claudetracing-0.4.0.tar.gz

Download URL claudetracing-0.4.0.tar.gz
Size 342.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3feec0bcc8736bbd4bbdbe535f86c43b665334e81bece10cd973ca796a42f769
BLAKE2b-256 checksum
How to use checksums
1e44c4686c3f2865c8e9daaa0a46071dc92f7c8e26f3c930e6c0dcd05b541ba5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / claudetracing-0.4.0-py3-none-any.whl

Download URL claudetracing-0.4.0-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
161154706b74acbb854f91f9f113ad5a6f6d030ac49b3e63b74b16c556f66df7
BLAKE2b-256 checksum
How to use checksums
b61ae8ac0bd5b8cc434826cab463d38a367e4dd7366836c0d706e666f2c1f478
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page