HN 표시: Claude Code 세션 비용 예산을 책정하는 CLI

hackernews | | 🔧 개발도구
#claude #tip
원문 출처: hackernews · Genesis Park에서 요약 및 분석

요약

Tokenyst는 Claude Code 세션의 토큰 사용량과 API 비용을 자동으로 추적하는 경량 CLI 도구로, 사용자가 특정 작업별로 예산을 설정하고 비용을 모니터링할 수 있습니다. `tkst` 명령어를 통해 예산을 지정하면 프롬프트마다 비용이 표시되며, 세션 종료 후에는 전체 비용 요약을 제공해 개발자와 팀의 비용 관리를 돕습니다.

본문

Track token usage and API costs for your Claude Code sessions. Tokenyst is a lightweight CLI tool that runs alongside Claude Code, automatically capturing token consumption and calculating spend against your budget. Perfect for indie developers, agents, and teams managing API costs. - Automatic tracking — Runs silently after each Claude Code session, capturing tokens and costs - Budget management — Set per-task budgets and monitor spend in real-time - Cost calculation — Built-in pricing for all Claude models, including prompt cache multipliers - Local-first — All data stored in ~/.tokenyst/ on your machine (no cloud required) - Session summaries — See token usage and budget progress at a glance npm install -g tokenyst # or pnpm add -g tokenyst You'll need Node.js 18+ and Claude Code already installed. tkst -t "Issue-243" -b 5 # Create a budget of $5.00 for "Issue-243" All future session costs will be automatically allocated to your active task. tkst claude # or claude This spawns Claude Code with budget tracking enabled. After each prompt, the prompt's cost is displayed along with the budget progress. After your session ends, a cost summary is displayed. 💡 Note: Running claude on its own will still enable budget tracking. However, the post-prompt and post-session summaries will not show. tkst -t # ┌─────────┬────────────────────────────────┐ # │ Task │ Issue-243 │ # ├─────────┼────────────────────────────────┤ # │ Budget │ $3.24 / $5.00 ▓▓▓▓▓▓▓▓░░░░ 65% │ # └─────────┴────────────────────────────────┘ Use tkst -l to see all tasks, their budgets, spend, and remaining balance. tkst -t "Fix header buttons" -b 2 # Created task "Fix header buttons" with budget $2.00 tkst claude # [Claude Code prompt] # ⎿ Stop says: +$0.861 (turn) | Budget: $0.86 / $2.00 (43%) # [Claude Code prompt] # ⎿ Stop says: +$0.344 (turn) | Budget: $1.21 / $2.00 (60%) /exit # Budget Summary: # ┌─────────┬────────────────────────────────┐ # │ Task │ Fix header buttons │ # ├─────────┼────────────────────────────────┤ # │ Budget │ $1.21 / $2.00 ▓▓▓▓▓▓▓░░░░░ 60% │ # ├─────────┼────────────────────────────────┤ # │ Session │ $1.21 │ # └─────────┴────────────────────────────────┘ Initializing Claude Code with tkst will provide post-prompt and post-session summaries. # Change tasks tkst -t "Add unit tests" # Update budget to $3.00 tkst -u "Add unit tests" -b 3 # Delete a task tkst -d "Fix header buttons" tkst -a # View allocations for the current task tkst -a --all # View allocations for all tasks tkst -ra "Add landing page" "Issue-243" # Re-allocate from one task to another tkst -a "Add landing page" --delete # Delete an allocation from a task tkst -r "Add Landing page" # Delete all allocations from a task tkst task (-t) -n -b # ⎿ Create a task with a budget cap tkst claude (-c) # ⎿ Run Claude Code with budget tracking tkst list (-l) # ⎿ List all tasks tkst delete (-d) [--yes] [--all] # ⎿ Delete a task and its history tkst update (-u) [-b ] [-n ] [-a ] # ⎿ Change budget cap, rename, and/or manually add an allocation tkst allocations (-a) [] [--all] [--delete] # ⎿ View or delete allocations tkst reallocate (-ra) # ⎿ Move an allocation between tasks tkst reset (-r) [--yes] # ⎿ Wipe spending history for a task tkst --enable # ⎿ Re-enable tracking and stop hook tkst --disable # ⎿ Disable tracking and remove stop hook - You run tkst claude to start a Claude Code session - Tokenyst spawns Claude with inherited stdio, letting you work normally - When you exit Claude, Tokenyst automatically: - Finds your session transcript in ~/.claude/projects/ - Parses token usage from the last assistant turn(s) - Calculates cost using the current Claude model pricing - Deducts the cost from your active task budget - Shows a summary with remaining balance - Finds your session transcript in - All data is saved locally in ~/.tokenyst/config.json Your data lives here: ~/.tokenyst/config.json — All tasks, budgets, and spend allocations~/.tokenyst/recorded-turns.json — Internal dedup tracking (you can ignore this)~/.tokenyst/hook.log — Debug logs from the Stop hook integration - Node.js 18.0.0 or later - Claude Code (via claude command in your PATH) - pnpm, npm, or yarn (for installation)

Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.

공유

관련 저널 읽기

전체 보기 →