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/*
Metadata
Release files for cc-costtrack 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cc_costtrack-0.1.0.tar.gz | 8.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cc_costtrack-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.7 kB
Release files / cc_costtrack-0.1.0.tar.gz
| Download URL | cc_costtrack-0.1.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
befd25ee083dde0b4cf6f4b48f94f4fccbe85523eb480ecf5a471f2bead51ea7
|
|
BLAKE2b-256 checksum How to use checksums |
9c07f7a3b60073a2fcaf85bf05ed680e1bbbff7193c1649f73b2c6a46b3339fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / cc_costtrack-0.1.0-py3-none-any.whl
| Download URL | cc_costtrack-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6013c9b52fe6b3f13ed1d9354d4df0e018658cfa41c65e7fc28c85d90a1e9a8
|
|
BLAKE2b-256 checksum How to use checksums |
d21990fcc3375012592d88786c383e30a15e3e9e3385457c16ba066ece588ec0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|