Claude Code observability + cost optimization CLI
Project description
costcut CLI
OSS CLI for Costcut. Tracks Claude Code session tokens, cost, hook compliance.
Backward compatibility: binary alias
cost-guardalso works for the main commands.
Install (Week 6+)
pip install costcut # PyPI (Week 6 release)
brew install costcut # Homebrew tap (Week 6 release)
Dev install
cd cli
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
costcut --version
Commands
costcut 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.
costcut report — session analytics (Week 2 ✅)
Scans Claude Code JSONL transcripts in ~/.claude/projects/, aggregates tokens + cost per session, renders a Rich table.
costcut report # default: last 20 sessions for cwd
costcut report --project ~/Projects/MyApp # specific project
costcut report --since 2026-05-01 # only sessions since date
costcut report --last 5 # top 5 most recent
costcut report --all # no limit
Output columns: Started | Duration | Model | Msgs | In | Out | Cache | Cost | Session. Final row = TOTAL.
costcut auth — token management (Week 7 ✅)
Manages authentication with backend API.
costcut auth set <api_key> # save API key (must start with cg_live_)
costcut auth status # check login status + show masked token
costcut auth logout # remove stored token
Token storage: ~/.config/costcut/token (0o600 permissions). Env override: COSTCUT_TOKEN=cg_live_... takes precedence. Backend: GET /v1/auth/me (Bearer JWT).
costcut push — upload sessions to backend (Week 7 ✅)
Aggregates sessions from local JSONL and POSTs to backend API.
costcut push # default: last 30 days
costcut push --project ~/Projects/MyApp # specific project
costcut push --since 7 # only last 7 days
costcut 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)
costcut live— real-time TUI dashboard (Week 2.5)costcut 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.1.0.tar.gz.
File metadata
- Download URL: costcut-0.1.0.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92f348133332db166e86713f9fc1cc2e0bdf711a8f448b98bb6fd8235803a5e8
|
|
| MD5 |
6c154744a960b83d02872557a1ef908e
|
|
| BLAKE2b-256 |
5130aa04f28e88db38467101fbe19bc1a21d2d0ad8ccd76c861e4fee08ab7fbe
|
File details
Details for the file costcut-0.1.0-py3-none-any.whl.
File metadata
- Download URL: costcut-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.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 |
f34940c6b0791f7162b9970476216168cba1a77f3a03afccac4ad712bc4c0d54
|
|
| MD5 |
76984950715d47ad360fba8e19beb80b
|
|
| BLAKE2b-256 |
0697e7ccd166f01048bc02fa634c1335a960d25899b81dccf755c84983244e88
|