Skip to main content

Extract and upload Claude Code traces

Project description

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).

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_traces_client-0.1.2.tar.gz (50.2 kB view details)

Uploaded Source

Built Distribution

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

claude_traces_client-0.1.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file claude_traces_client-0.1.2.tar.gz.

File metadata

  • Download URL: claude_traces_client-0.1.2.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for claude_traces_client-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f0cc2c5622876ac91e430d77f440a364e8d3aea45117a65f1b21195952e56f06
MD5 0b93f3d5abbc5fb4f5b0d17ce483e278
BLAKE2b-256 061b6e8a075e85c28739289cd976ee9d3fea5305af20df69aba1edc2422a0a49

See more details on using hashes here.

File details

Details for the file claude_traces_client-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_traces_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ecc5dd5665cbe18a4c6ee6c0caa6ab7e6803f6ab31f15b17fbe824a594d2e1d1
MD5 92c4e59ec2a2489bfc92af9cdc5a23c6
BLAKE2b-256 b9d39d109647d87fd43db4bef5c79dbae93bd6c38a5c42a3d6033073ddaeea50

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