Last active
August 9, 2025 13:06
-
-
Save 9wick/8c0e9dae6c191cf3d7182315a1f1a81a to your computer and use it in GitHub Desktop.
ClaudeCodeでStatusLineに現在のtoken数 + ccusageを表示する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "statusLine": { | |
| "type": "command", | |
| "command": "/Users/xxxx/.claude/statusline.sh" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 標準入力を変数に格納 | |
| input=$(cat) | |
| # # transcript_pathを抽出 | |
| transcript_file=$(echo "$input" | jq -r '.transcript_path') | |
| # そのファイルから.message.usageが存在する最後の行を見つけてトークン数を計算 | |
| tac "$transcript_file" | while read -r line; do | |
| if echo "$line" | jq -e '.message.usage' >/dev/null 2>&1; then | |
| echo "$line" | jq -r ' | |
| .message.usage | | |
| (.input_tokens + | |
| .cache_creation_input_tokens + | |
| .cache_read_input_tokens) | | |
| "\(.) tokens" | |
| ' | |
| break | |
| fi | |
| done | |
| # # 2行目: npx ccusage@latest statuslineの実行結果 | |
| echo "$input" | npx ccusage@latest statusline | |
| # sample jsonl one line | |
| # { | |
| # "parentUuid":"f7b73aec-4a83-4236-9fb7-5a6146a571d2", | |
| # "isSidechain":false, | |
| # "userType":"external", | |
| # "cwd":"/Users/xxxx/Documents/src/github.com/9wick/9wick", | |
| # "sessionId":"7dba2b51-39f9-4b9b-bcb5-001a2cdd452e", | |
| # "version":"1.0.72", | |
| # "gitBranch":"main", | |
| # "message":{ | |
| # "id":"msg_01EKRFnTAuwTjDXpAqUx6de2", | |
| # "type":"message", | |
| # "role":"assistant", | |
| # "model":"claude-sonnet-4-20250514", | |
| # "content":[ | |
| # { | |
| # "type":"text", | |
| # "text":"こんにちは!" | |
| # } | |
| # ], | |
| # "stop_reason":null, | |
| # "stop_sequence":null, | |
| # "usage":{ | |
| # "input_tokens":3, | |
| # "cache_creation_input_tokens":211, | |
| # "cache_read_input_tokens":16364, | |
| # "output_tokens":101, | |
| # "service_tier":"standard" | |
| # } | |
| # }, | |
| # "requestId":"req_011CRwnnEXq97xmDSKxP3MjH", | |
| # "type":"assistant", | |
| # "uuid":"2ea0d4f1-40c3-4cb8-b424-6da079997443", | |
| # "timestamp":"2025-08-09T08:05:27.371Z" | |
| # } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
出力サンプル
