Tracing Claude Code

MLflow Tracing provides automatic tracing for Claude Code:
- CLI tracing: Automatically trace interactive Claude Code CLI conversations
- SDK tracing: Trace Claude Agent SDK usage in Python applications
After setting up auto tracing, MLflow will automatically capture traces of your Claude Code conversations and log them to the active MLflow experiment. The trace automatically captures information such as:
- User prompts and assistant responses
- Tool usage (file operations, code execution, web searches, etc.)
- Conversation timing and duration
- Tool execution results
- Session metadata including working directory and user
Setup
Claude Code tracing can be configured using either CLI commands (for interactive use) or Python SDK imports (for programmatic use).
- CLI Tracing
- SDK Tracing
CLI Tracing Setup
Use CLI tracing to automatically capture your interactive Claude Code CLI conversations.
Requirements
- MLflow >= 3.4 (
pip install mlflow>=3.4) - Claude Code CLI installed and configured
Basic Setup
# Set up tracing in current directory
mlflow autolog claude
# Set up tracing in specific directory
mlflow autolog claude ~/my-project
# Check tracing status
mlflow autolog claude --status
# Disable tracing
mlflow autolog claude --disable
Configuration Examples
# Set up with custom tracking URI
mlflow autolog claude -u file://./custom-mlruns
mlflow autolog claude -u sqlite:///mlflow.db
# Set up with Databricks backend and a specific experiment ID
mlflow autolog claude -u databricks -e 123456789
# Set up with specific experiment
mlflow autolog claude -n "My AI Project"
How It Works
- Setup Phase: The
mlflow autolog claudecommand configures Claude Code hooks in a.claude/settings.jsonfile in your project directory - Automatic Tracing: When you use the
claudecommand in the configured directory, your conversations are automatically traced - View Results: Use the MLflow UI to explore your traces
Basic Example
# Set up tracing in your project
mlflow autolog claude ~/my-project
# Navigate to project directory
cd ~/my-project
# Use Claude Code normally - tracing happens automatically
claude "help me refactor this Python function to be more efficient"
# View traces in MLflow UI
mlflow ui
SDK Tracing Setup
Use SDK tracing when building applications that programmatically use the Claude Agent SDK.
Requirements
- MLflow >= 3.5 (
pip install mlflow>=3.5) - Claude Agent SDK >= 0.1.0 (
pip install claude-agent-sdk >= 0.1.0)