@mlflow/claude-code
v0.4.0
Published
Claude Code and Claude Agent SDK integration package for MLflow Tracing
Maintainers
Readme
MLflow Typescript SDK - Claude Code
Trace Claude Code sessions and Claude Agent SDK runs with MLflow Tracing.
| Package | NPM | Description |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| @mlflow/claude-code | | Trace Claude Code CLI sessions (Stop-hook) and Claude Agent SDK queries. |
Installation
npm install @mlflow/claude-codeFor Claude Agent SDK tracing, also install the SDK:
npm install @anthropic-ai/claude-agent-sdkQuickstart
Start an MLflow Tracking Server if you don't have one already, then point your environment at it:
export MLFLOW_TRACKING_URI=http://localhost:5000
export MLFLOW_EXPERIMENT_ID=<experiment-id>Tracing the Claude Code CLI
Install the bundled Stop-hook plugin once; it will trace every CLI session automatically. See the docs for plugin setup.
Tracing the Claude Agent SDK
Wrap the SDK's query function with createTracedQuery:
import { query } from '@anthropic-ai/claude-agent-sdk';
import { createTracedQuery } from '@mlflow/claude-code';
import * as mlflow from '@mlflow/core';
mlflow.init({
trackingUri: 'http://localhost:5000',
experimentId: '<experiment-id>',
});
const tracedQuery = createTracedQuery(query);
const result = tracedQuery({
prompt: 'List the files in this directory',
options: {
permissionMode: 'bypassPermissions',
},
});
for await (const message of result) {
if (message.type === 'result') {
console.log('Result:', message.result);
}
}The wrapper produces the same span tree as the Claude Code CLI integration: an AGENT root span with LLM and TOOL children, plus nested AGENT spans for sub-agents invoked via the Task tool. Token usage (including cache_read_input_tokens and cache_creation_input_tokens) is recorded on every LLM span and aggregated on the root.
Documentation
Official documentation for the MLflow TypeScript SDK is at https://mlflow.org/docs/latest/genai/tracing/quickstart.
