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
Configuration
Add to ~/.claude/settings.json:
{
"hooks": {
"SessionEnd": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "cc-costtrack"
}
]
}
]
}
}
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cc_costtrack-0.0.1.tar.gz.
File metadata
- Download URL: cc_costtrack-0.0.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27ca13b0d7f25038f260dcfb11dde3d7816dd066e5c902c50b8d61654b044d51
|
|
| MD5 |
6f152780645e04a2086584de44d5bd4f
|
|
| BLAKE2b-256 |
05e6dfc321717625e7c7174969dc2c717a6e113156beb2c50a3fd8f4fac85689
|
File details
Details for the file cc_costtrack-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cc_costtrack-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3b78ac7d91c66037302f356c23fc2c57d5049856cced35c559605b46056a5f0
|
|
| MD5 |
93e02b919079cbea79238f2bf74b5bd6
|
|
| BLAKE2b-256 |
c6fe5925435013a0f7be5de0a7e23d5dd09963ff7d155bad3f99428ec8517a6f
|