Claude Code observability + cost optimization CLI
Project description
cost-guard CLI
OSS CLI for Cost Guard. Tracks Claude Code session tokens, cost, hook compliance.
Install (Week 6+)
pip install cost-guard # PyPI (Week 6 release)
brew install cost-guard # Homebrew tap (Week 6 release)
Dev install
cd cli
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
cost-guard --version
Commands
cost-guard init — install hooks bundle (Week 3 ✅)
Installs 5 bundled hook scripts + shared library into .claude/hooks/, registers them in .claude/settings.json.
cost-guard init # install to .claude/hooks (default)
cost-guard init --target ~/.claude/hooks # explicit target path
cost-guard init --dry-run # preview changes, write nothing
cost-guard init --force # overwrite existing hooks
Installs:
- Hooks:
parallel_agents_guard.sh,test_before_push_guard.sh,large_read_warning.sh,token_alert.sh,session_cost_check.sh - Library:
_lib/cost.sh(shared utilities)
Registers hooks in .claude/settings.json with event + matcher + command path. Idempotent: running twice adds no duplicates.
Exit code 0 on success, 1 on error.
cost-guard report — session analytics (Week 2 ✅)
Scans Claude Code JSONL transcripts in ~/.claude/projects/, aggregates tokens + cost per session, renders a Rich table.
cost-guard report # default: last 20 sessions for cwd
cost-guard report --project ~/Projects/MyApp # specific project
cost-guard report --since 2026-05-01 # only sessions since date
cost-guard report --last 5 # top 5 most recent
cost-guard report --all # no limit
Output columns: Started | Duration | Model | Msgs | In | Out | Cache | Cost | Session. Final row = TOTAL.
cost-guard auth — token management (Week 7 ✅)
Manages authentication with backend API.
cost-guard auth set <api_key> # save API key (must start with cg_live_)
cost-guard auth status # check login status + show masked token
cost-guard auth logout # remove stored token
Token storage: ~/.config/cost-guard/token (0o600 permissions). Env override: COST_GUARD_TOKEN=cg_live_... takes precedence. Backend: GET /v1/auth/me (Bearer JWT).
cost-guard push — upload sessions to backend (Week 7 ✅)
Aggregates sessions from local JSONL and POSTs to backend API.
cost-guard push # default: last 30 days
cost-guard push --project ~/Projects/MyApp # specific project
cost-guard push --since 7 # only last 7 days
cost-guard push --dry-run # preview without HTTP
Requires authenticated token. Filters by --since (days). POSTs {id, project, primary_model, started_at, ended_at, input_tokens, output_tokens, cost_usd}. Continues on errors, returns 1 if any failed.
Stubs (later weeks)
cost-guard live— real-time TUI dashboard (Week 2.5)cost-guard alert --budget 5— daily spend cap (Week 3)
Pricing
Per-million-token rates (verified 2026-05-23 against https://docs.claude.com/en/docs/about-claude/models):
| Model | Input | Output | Cache read | Cache write 5m | Cache write 1h |
|---|---|---|---|---|---|
claude-opus-4-7 / 4-6 |
$15 | $75 | $1.50 | $18.75 | $30 |
claude-sonnet-4-6 / 4-5 |
$3 | $15 | $0.30 | $3.75 | $6 |
claude-haiku-4-5 |
$1 | $5 | $0.10 | $1.25 | $2 |
Unknown models return cost=0 (not None) — see cost_guard.pricing.compute_cost_usd.
Tests
cd cli
pytest # 50 tests, ~1s
COSTGUARD_REAL_SMOKE=1 pytest tests/test_real_data_smoke.py # opt-in: scans real ~/.claude/projects
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 costcut-0.0.9.tar.gz.
File metadata
- Download URL: costcut-0.0.9.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f51ea0a8f28aebbd59cec15c8e652951dc1bdb54aa0fd63c431661ebbaca200
|
|
| MD5 |
a76c229c3dd830b18b29e20625c1d9f1
|
|
| BLAKE2b-256 |
a33698df21b15bec40b0929c8adf0180b2356f3a38290eb1edf307d8f90a6122
|
File details
Details for the file costcut-0.0.9-py3-none-any.whl.
File metadata
- Download URL: costcut-0.0.9-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3752a00198ce3fe360036a6d96eb031d1c557248a532ceea19570155fac2e249
|
|
| MD5 |
dc06ec21381a8a325631dc3ead300d3d
|
|
| BLAKE2b-256 |
59cb63d8cda2e1830e7c411a53db56a2b4032b29d1a69a0ba793c69fbad6be02
|