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.3.tar.gz (8.8 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.3-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cc_costtrack-0.0.3.tar.gz
  • Upload date:
  • Size: 8.8 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.3.tar.gz
Algorithm Hash digest
SHA256 ae6cda2f11e242f8187d85a28b8c1db5db80a91b6f54a75997ca5f3c6e61f779
MD5 eb400b731f8b1cd9314b3fc62106b0d5
BLAKE2b-256 632c7d07cbb94dfcd866dcbddf3299aa220cf5bc1a9ceaa1818944903673e1ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cc_costtrack-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 17ecfbb5287051fa0760e0c73650b881fbff2149386b9e925badb2624e10151e
MD5 1de0d92ee7d83abf7e8baafc77481785
BLAKE2b-256 fccf58df0ab05236c835d8277c4b22be1d0ffa67dfb65efee3a361f1233a1814

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