MCPcopy
hub / github.com/phuryn/claude-usage / cmd_today

Function cmd_today

cli.py:96–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

94
95
96def cmd_today():
97 conn = require_db()
98 conn.row_factory = sqlite3.Row
99 today = date.today().isoformat()
100
101 rows = conn.execute("""
102 SELECT
103 COALESCE(model, 'unknown') as model,
104 SUM(input_tokens) as inp,
105 SUM(output_tokens) as out,
106 SUM(cache_read_tokens) as cr,
107 SUM(cache_creation_tokens) as cc,
108 COUNT(*) as turns
109 FROM turns
110 WHERE substr(timestamp, 1, 10) = ?
111 GROUP BY model
112 ORDER BY inp + out DESC
113 """, (today,)).fetchall()
114
115 sessions = conn.execute("""
116 SELECT COUNT(DISTINCT session_id) as cnt
117 FROM turns
118 WHERE substr(timestamp, 1, 10) = ?
119 """, (today,)).fetchone()
120
121 subagent = conn.execute("""
122 SELECT
123 COUNT(*) as turns,
124 SUM(input_tokens + output_tokens + cache_read_tokens + cache_creation_tokens) as tokens
125 FROM turns
126 WHERE substr(timestamp, 1, 10) = ?
127 AND COALESCE(is_subagent, 0) = 1
128 """, (today,)).fetchone()
129
130 print()
131 hr()
132 print(f" Today's Usage ({today})")
133 hr()
134
135 if not rows:
136 print(" No usage recorded today.")
137 print()
138 return
139
140 total_inp = total_out = total_cr = total_cc = total_turns = 0
141 total_cost = 0.0
142
143 for r in rows:
144 cost = calc_cost(r["model"], r["inp"] or 0, r["out"] or 0, r["cr"] or 0, r["cc"] or 0)
145 total_cost += cost
146 total_inp += r["inp"] or 0
147 total_out += r["out"] or 0
148 total_cr += r["cr"] or 0
149 total_cc += r["cc"] or 0
150 total_turns += r["turns"]
151 print(f" {r['model']:<30} turns={r['turns']:<4} in={fmt(r['inp'] or 0):<8} out={fmt(r['out'] or 0):<8} cost={fmt_cost(cost)}")
152
153 hr()

Callers

nothing calls this directly

Calls 5

require_dbFunction · 0.85
hrFunction · 0.85
calc_costFunction · 0.85
fmtFunction · 0.85
fmt_costFunction · 0.85

Tested by

no test coverage detected