Skip to main content

Cost tracking hook for ClaudeCode, to run at end of each session

Project description

Claude Code Session End Hook for Cost Tracking

Introduction

Claude Code hook that should run at the end of sessions. The hook will log cost and usage in a CSV file, in ~/.claude folder.

Installation

pip install cc-costtrack

On newer Linux systems, install with:

pip3 install --break-system-packages cc-costtrack

Configuration

Add to ~/.claude/settings.json:

{
  "hooks": {
    "SessionEnd": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "cc-costtrack"
          }
        ]
      }
    ]
  }
}

Upgrade

Upgrade with pip regularly:

pip install cc-costtrack -U

On newer Linux systems, install with:

pip3 install --break-system-packages cc-costtrack -U

Development

Set up a virtual environment:

python3 -m venv .venv

Activate the virtual environment before running any of the steps below:

source .venv/bin/activate

Testing

pip install -e ".[test]"
pytest

Build and publish

Build the distribution:

pip install -e ".[package]"
python -m build

This creates dist/ with .tar.gz and .whl files.

Configure Publishing to Pypi

Configure PyPI credentials in ~/.pypirc:

[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = __token__
password = pypi-<your-api-token>

[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-<your-test-api-token>

API tokens can be created at:

Alternatively, set credentials via environment variables instead of ~/.pypirc:

export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-<your-api-token>

To target TestPyPI, override the repository URL:

export TWINE_REPOSITORY_URL=https://test.pypi.org/legacy/

Publishing to Test Pypi

To publish to TestPyPI first:

pip install -e ".[package,publish]"

# Using ini file:
twine upload --repository testpypi dist/*

# Or, with environment variables:
export TWINE_REPOSITORY_URL=https://test.pypi.org/legacy/
twine upload dist/*

Publishing to Pypi

Publish to PyPI:

pip install -e ".[publish]"
twine upload dist/*

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

cc_costtrack-0.0.2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

cc_costtrack-0.0.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file cc_costtrack-0.0.2.tar.gz.

File metadata

  • Download URL: cc_costtrack-0.0.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cc_costtrack-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7729a5ee5c65ba76707111d1b4ac40b57da554f4b120c22f281751051f159944
MD5 b970b3ba3a7d043a94bd35566ceea979
BLAKE2b-256 da43402c5a3932de9516e1afd89c2599857cf471760a24d2d0d8d41b9b2aead6

See more details on using hashes here.

File details

Details for the file cc_costtrack-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: cc_costtrack-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cc_costtrack-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1920d584f1ffc7fa425557e0e31d5192dc648d54f0669fbc70f10a080355649a
MD5 00757046f030c3f489ba6e4a22bdb2d9
BLAKE2b-256 e87eb9f4b398446764cb4a18c1e715babfb0080183b6897cae42e3c662dbd8d8

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