Skip to main content

Trace capture for Claude Code sessions - sync to PISAMA platform for analysis

Project description

pisama-claude-code

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

PyPI version 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

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

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)
pisama-cc usage Token usage breakdown (--by-model, --by-tool)
pisama-cc export Export to JSONL (-o FILE, --compress)
pisama-cc connect Connect to PISAMA platform (optional)
pisama-cc sync Upload traces to platform
pisama-cc analyze Run failure detection (requires platform)

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 stored in ~/.claude/pisama/traces/
  • Secrets redacted: API keys, passwords, and tokens are automatically removed
  • Paths anonymized: Home directory paths replaced with ~
  • Platform sync is opt-in: Nothing leaves your machine without explicit action

See SECURITY.md for our security policy.

Configuration

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

{
  "hooks": {
    "PreToolCall": [
      {
        "command": "~/.claude/hooks/pisama-pre.sh",
        "timeout": 2000
      }
    ],
    "PostToolCall": [
      {
        "command": "~/.claude/hooks/pisama-post.sh",
        "timeout": 2000
      }
    ]
  }
}

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:

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

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

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

pisama_claude_code-0.3.6.tar.gz (339.3 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.3.6-py3-none-any.whl (38.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pisama_claude_code-0.3.6.tar.gz
  • Upload date:
  • Size: 339.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pisama_claude_code-0.3.6.tar.gz
Algorithm Hash digest
SHA256 a82d33b45bfc46d650a0d3bf6465a34e0ecb77a50c3ab41b89d902052a86d7b3
MD5 e102575ae2254525cc8c926fda837a13
BLAKE2b-256 0a57b252d165d5931e71b161e65cf42aa2ca0a116f9f369f5005cad82e48fb06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pisama_claude_code-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 aaec9ca75c4b987bd49cf52fafb3d5a96630612cab3a16fd0f1dc345ab6469dc
MD5 b06972d57f4a9c1245ff265adabb14e4
BLAKE2b-256 775d2844134cce063ef49e98ba135e044ac70ad1e5c0963651f10e511dec6e55

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