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.1.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.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_traces_client-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 1f01c0f8f44a9a2368184a87cc6567fd3d87af948ddbac163164a1cbde740f81
MD5 7bc32b980a34a39219371da005943ffe
BLAKE2b-256 3d2062b1d57220807601099f6c552c29c8e41e7988ffcee6c9098d367487a360

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for claude_traces_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d495cb0ba0b42c2ec1d6146357047c88946e7c5ae694e746d18a20b91ef8e32
MD5 a38c9145a3028dc5bcc94df87abb75b9
BLAKE2b-256 85e1ad672515b2e8ad6f33ae4fc56c810bd2e51fa56401e1440cefe56f202302

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