Skip to main content

pisama-claude-code

Lightweight trace capture for Claude Code sessions with token usage and cost tracking.

PyPI version GitHub stars Python versions License: MIT CI Downloads Downloads/month Code style: ruff

Demo

pisama-claude-code demo

Why Pisama?

When working with Claude Code, have you ever wondered:

  • How much did that session cost? Track token usage and costs in real-time
  • What tools were called? See every Bash, Read, Write, and Edit operation
  • Why did it fail? Capture traces for debugging and forensics
  • Can I export my sessions? JSONL export for analysis or compliance

pisama-claude-code captures everything Claude Code does, locally and privately.

┌─────────────────────┐         ┌─────────────────────┐
│   Claude Code       │         │   Pisama Platform   │
│   + pisama-cc       │ ──────▶ │   (optional)        │
│   (capture)         │  sync   │   - detection       │
└─────────────────────┘         │   - self-healing    │
        │                       └─────────────────────┘
        │
        ▼
   ~/.claude/pisama/traces/
   (local storage)

Installation

pip install pisama-claude-code

Requirements: Python 3.10+ and Claude Code CLI

Quick Start

# 1. Install capture hooks
pisama-cc install

# 2. Use Claude Code normally - traces are captured automatically

# 3. View your session data
pisama-cc status        # Summary with token totals and cost
pisama-cc traces        # Recent tool calls
pisama-cc usage         # Detailed breakdown

Features

Token & Cost Tracking

$ pisama-cc usage --by-model --by-tool

📊 Token Usage Summary (last 100 traces)
==================================================
Input tokens:           10,234
Output tokens:          85,421
Cache read tokens:   1,234,567
Total cost:        $    52.34

📈 By Model:
--------------------------------------------------
  claude-opus-4-5-20251101            $52.34

🔧 By Tool:
--------------------------------------------------
  Bash                   45 calls  $25.12
  Read                   30 calls  $15.34
  Write                  20 calls  $8.45
  Edit                   5 calls   $3.43

Session Status

$ pisama-cc status

📊 Pisama Status
========================================

🔧 Hook Installation:
    pisama-capture.py
    pisama-pre.sh
    pisama-post.sh
   All hooks installed

📁 Local Traces: 1,400
   Input tokens:  9,580
   Output tokens: 79,569
   Total cost:    $43.22

Export & Analysis

# Export to JSONL
pisama-cc export -o traces.jsonl

# Export compressed
pisama-cc export -o traces.jsonl.gz --compress

# Export to OpenTelemetry format
pisama-cc export --format otel -o traces-otel.json

# Filter by date range
pisama-cc traces --since 2025-01-01 --until 2025-01-04

OpenTelemetry Integration

Export traces to any OTEL-compatible backend (Jaeger, Honeycomb, Datadog, etc.):

# Install OTEL support
pip install pisama-claude-code[otel]

# Export to local Jaeger
pisama-cc export-otel -e http://localhost:4318/v1/traces

# Export to Honeycomb
pisama-cc export-otel -e https://api.honeycomb.io/v1/traces \
    -H "x-honeycomb-team=YOUR_API_KEY"

# Export to file in OTEL format
pisama-cc export --format otel -o traces.json

OTEL export uses GenAI semantic conventions for token usage, costs, and model attributes.

CLI Reference

Command Description
pisama-cc install Install capture hooks to ~/.claude/hooks/
pisama-cc uninstall Remove hooks
pisama-cc status Show status, token totals, and cost
pisama-cc traces View recent traces (-v for verbose, -c for content)
pisama-cc usage Token usage breakdown (--by-model, --by-tool)
pisama-cc export Export to JSONL or OTEL (--format otel, --compress)
pisama-cc export-otel Export to OpenTelemetry collector (-e ENDPOINT)
pisama-cc connect Connect to Pisama platform (forwarding is opt-in; add --auto-sync to forward every session)
pisama-cc sync Upload traces to platform
pisama-cc analyze Run failure detection (requires platform)
pisama-cc proxy serve Run the opt-in reasoning proxy for a session (experimental)
pisama-cc proxy install --always-on Always-on reasoning capture (macOS launchd)
pisama-cc proxy status / uninstall Proxy health / teardown
pisama-cc vault status Show PII tokenization vault status ([core])

Model Pricing

Supported models and pricing (per 1M tokens):

Model Input Output Cache Read
claude-opus-4-5 $15.00 $75.00 $1.50
claude-sonnet-4 $3.00 $15.00 $0.30
claude-3-5-sonnet $3.00 $15.00 $0.30
claude-3-5-haiku $0.80 $4.00 $0.08

Privacy & Security

  • Local-first: all traces are stored in ~/.claude/pisama/traces/.
  • Forwarding is opt-in: connect defaults to no auto-sync. Nothing leaves your machine until you run pisama-cc sync or reconnect with --auto-sync.
  • Secrets scrubbed by default: credential-shaped strings (API keys, JWTs, cloud tokens) are redacted from content before forwarding — no extras needed. The optional [core] extra adds pisama-core's reversible keychain vault.
  • Paths anonymized: home-directory paths are replaced with ~.
  • Reasoning proxy is experimental + opt-in: pisama-cc proxy routes API traffic through a local logging proxy to recover extended-thinking. It defaults to API-key usage. Subscription (OAuth) users: it handles your account token, which is ToS-sensitive — use only knowingly.

See SECURITY.md for our security policy.

Configuration

After installation, the hooks are automatically configured. To customize, edit ~/.claude/settings.local.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "*",
        "hooks": [
          { "type": "command", "command": "~/.claude/hooks/pisama-post.sh", "timeout": 10, "async": true }
        ]
      }
    ],
    "Stop": [
      {
        "matcher": "*",
        "hooks": [
          { "type": "command", "command": "~/.claude/hooks/pisama-forward.sh", "timeout": 30, "async": true }
        ]
      }
    ]
  }
}

Platform Integration (Optional)

For advanced features like failure detection and self-healing, connect to the Pisama platform:

pisama-cc connect        # Authenticate
pisama-cc sync           # Upload traces
pisama-cc analyze        # Run detection

Platform features:

  • 25 MAST failure mode detection
  • AI-powered fix suggestions
  • Self-healing automation
  • Visual dashboard

Part of the Pisama Platform

pisama-claude-code is the Claude Code integration for the broader Pisama multi-agent failure detection platform, which supports multiple agent frameworks:

Framework Package Status
Claude Code pisama-claude-code Stable
LangChain/LangGraph mao-testing SDK Available
CrewAI mao-testing SDK Available
AutoGen mao-testing SDK Available
n8n mao-testing SDK Available

For other frameworks, see the mao-testing SDK.

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

# Development setup
git clone https://github.com/tn-pisama/pisama-claude-code.git
cd pisama-claude-code
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check src/

Changelog

See CHANGELOG.md for release history.

License

MIT License - see LICENSE for details.

Links


Made with ❤️ for the Claude Code community

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pisama_claude_code-0.6.3.tar.gz (104.9 kB view details)

Uploaded Source

Built Distribution

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

pisama_claude_code-0.6.3-py3-none-any.whl (95.5 kB view details)

Uploaded Python 3

File details

Details for the file pisama_claude_code-0.6.3.tar.gz.

File metadata

  • Download URL: pisama_claude_code-0.6.3.tar.gz
  • Upload date:
  • Size: 104.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pisama_claude_code-0.6.3.tar.gz
Algorithm Hash digest
SHA256 88e76a2a6d85e628458c9e4ec16d45fe4306d0e2bd846ec2c3a13e4b35fe08da
MD5 490912fb4f1a174e03bf0c7d9c29d6dc
BLAKE2b-256 742341e9d41f9775b03f865a392f69ffff2cfbdca5e44e3886739485f340c4bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pisama_claude_code-0.6.3.tar.gz:

Publisher: publish.yml on Pisama-AI/pisama-claude-code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pisama_claude_code-0.6.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pisama_claude_code-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 348fe357538e90ecbb90aae4a148648489e15a9c70e1e736f19aeaed63f1ed1e
MD5 6a58a5d9d5f8a47b64c97d3250692413
BLAKE2b-256 91cd14cc39c4d8a1f043c021002b175ffc28e0da6156a8b17a67e8b94eaeb1e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pisama_claude_code-0.6.3-py3-none-any.whl:

Publisher: publish.yml on Pisama-AI/pisama-claude-code

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page