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.1.0.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.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cc_costtrack-0.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 befd25ee083dde0b4cf6f4b48f94f4fccbe85523eb480ecf5a471f2bead51ea7
MD5 14bd76105e5f2f6c277a6849f3d44b3c
BLAKE2b-256 9c07f7a3b60073a2fcaf85bf05ed680e1bbbff7193c1649f73b2c6a46b3339fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cc_costtrack-0.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6013c9b52fe6b3f13ed1d9354d4df0e018658cfa41c65e7fc28c85d90a1e9a8
MD5 73c11c5c634529575b35e381a750d48e
BLAKE2b-256 d21990fcc3375012592d88786c383e30a15e3e9e3385457c16ba066ece588ec0

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