Skip to main content

claude_traces_client

Extract and upload Claude Code traces to a configurable endpoint.

Installation

pip install claude-traces-client

Or install from source:

cd claude_traces_client
pip install -e .

Usage

from claude_traces_client import traced
from claude_code_sdk import query, ClaudeCodeOptions

# Endpoint read from CLAUDE_TRACES_ENDPOINT env var (default: https://claudetraces.dev/api/trace)
async for msg in traced(query(prompt="Hello", options=opts)):
    print(msg)  # Messages flow through unchanged
# Trace is POSTed automatically after iteration completes

Configuration

Environment Variable Default Description
CLAUDE_TRACES_ENDPOINT https://claudetraces.dev/api/trace URL to POST traces to

API

traced(messages, *, project_path=None, headers=None, timeout=30.0, raise_on_upload_error=False)

Wrap a Claude SDK message iterator to upload traces after completion.

Parameters:

  • messages: AsyncIterator from query() or ClaudeSDKClient
  • project_path: Project path for trace lookup (default: cwd)
  • headers: Optional headers for the POST request (e.g., {"Authorization": "Bearer ..."})
  • timeout: Upload timeout in seconds
  • raise_on_upload_error: If True, raise on upload failure; if False, silently continue

Yields: Messages unchanged from the underlying iterator

How It Works

  1. Wraps the Claude SDK's async message iterator
  2. Captures the session_id from the first SystemMessage with subtype='init'
  3. After iteration completes, reads the trace file from ~/.claude/projects/<encoded-path>/<session_id>.jsonl
  4. POSTs the trace contents to the configured endpoint with Content-Type: application/x-ndjson

Trace File Location

Claude Code writes traces to:

~/.claude/projects/<encoded-path>/<session_id>.jsonl

Where <encoded-path> is the project path with / replaced by - (e.g., /Users/foo/bar becomes -Users-foo-bar).

Metadata

Release files for claude-traces-client 0.1.2

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

Source distribution (sdist)

Source distribution for claude-traces-client 0.1.2
File Size Uploaded
claude_traces_client-0.1.2.tar.gz 50.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for claude-traces-client 0.1.2
File Interpreter ABI Platform
claude_traces_client-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 56.0 kB

Release files / claude_traces_client-0.1.2.tar.gz

Download URL claude_traces_client-0.1.2.tar.gz
Size 50.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f0cc2c5622876ac91e430d77f440a364e8d3aea45117a65f1b21195952e56f06
BLAKE2b-256 checksum
How to use checksums
061b6e8a075e85c28739289cd976ee9d3fea5305af20df69aba1edc2422a0a49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / claude_traces_client-0.1.2-py3-none-any.whl

Download URL claude_traces_client-0.1.2-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecc5dd5665cbe18a4c6ee6c0caa6ab7e6803f6ab31f15b17fbe824a594d2e1d1
BLAKE2b-256 checksum
How to use checksums
b9d39d109647d87fd43db4bef5c79dbae93bd6c38a5c42a3d6033073ddaeea50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

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