-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_tokens.py
More file actions
executable file
·43 lines (33 loc) · 1.13 KB
/
update_tokens.py
File metadata and controls
executable file
·43 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
"""
Update token count for the HUD widget
Can be called manually or integrated into Claude Code
"""
import json
import sys
from pathlib import Path
def update_token_count(used, total=200000):
"""Update the token status file"""
status_file = Path.home() / '.claude' / 'token_status.json'
status_file.parent.mkdir(parents=True, exist_ok=True)
remaining = total - used
percentage = (remaining / total) * 100 if total > 0 else 0
data = {
'used': used,
'total': total,
'remaining': remaining,
'percentage': percentage
}
with open(status_file, 'w') as f:
json.dump(data, f, indent=2)
print(f"Token count updated: {remaining:,} remaining ({percentage:.1f}%)")
def main():
if len(sys.argv) < 2:
print("Usage: update_tokens.py <used_tokens> [total_tokens]")
print("Example: update_tokens.py 25000 200000")
sys.exit(1)
used = int(sys.argv[1])
total = int(sys.argv[2]) if len(sys.argv) > 2 else 200000
update_token_count(used, total)
if __name__ == '__main__':
main()