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: localhost:3000/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 http://localhost:3000/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.0.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.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_traces_client-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 097feae88ddd6521589d7b4d275ce2bd3bbba9222f84620a1588baceea30d77a
MD5 77123e0468baf175030bfba1c438ec48
BLAKE2b-256 06c86e49aef6fcf2f33a2c57ed17c7a47fa9e2fe40f2a03f2ca3bff98656669f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for claude_traces_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc2b79a3339c4491269b469a81f819279a7957de38e6ae9314031ef7c1b5f7d
MD5 e3357c71093329f0ef8fc12124b7ac4c
BLAKE2b-256 46b17a0ca752b209e809326dac4074a2a6e248186ce53cb6c19d10b8e7005860

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