cursor-usage 0.1.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cursor_usage-0.1.0/src/cursor_usage.egg-info → cursor_usage-0.2.1}/PKG-INFO +17 -1
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/README.md +16 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/pyproject.toml +1 -1
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage/__init__.py +1 -1
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage/api.py +8 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage/auth.py +19 -4
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage/cli.py +42 -1
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage/report.py +126 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1/src/cursor_usage.egg-info}/PKG-INFO +17 -1
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage.egg-info/SOURCES.txt +1 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/tests/test_auth.py +25 -0
- cursor_usage-0.2.1/tests/test_limits.py +151 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/LICENSE +0 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/setup.cfg +0 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage/__main__.py +0 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage.egg-info/dependency_links.txt +0 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage.egg-info/entry_points.txt +0 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage.egg-info/requires.txt +0 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/src/cursor_usage.egg-info/top_level.txt +0 -0
- {cursor_usage-0.1.0 → cursor_usage-0.2.1}/tests/test_report.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cursor-usage
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Cross-platform CLI to read your Cursor (cursor.com) usage, spend, and per-event logs.
|
|
5
5
|
Author: cursor-usage contributors
|
|
6
6
|
License: MIT
|
|
@@ -28,12 +28,17 @@ Dynamic: license-file
|
|
|
28
28
|
</p>
|
|
29
29
|
|
|
30
30
|
<p align="center">
|
|
31
|
+
<a href="https://pypi.org/project/cursor-usage/"><img alt="PyPI" src="https://img.shields.io/pypi/v/cursor-usage?color=blue&label=PyPI"></a>
|
|
31
32
|
<img alt="Python" src="https://img.shields.io/badge/python-3.8%2B-blue">
|
|
32
33
|
<img alt="Platforms" src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey">
|
|
33
34
|
<img alt="Dependencies" src="https://img.shields.io/badge/dependencies-zero-brightgreen">
|
|
34
35
|
<img alt="License" src="https://img.shields.io/badge/license-MIT-green">
|
|
35
36
|
</p>
|
|
36
37
|
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img src="https://raw.githubusercontent.com/javaisbetterthanpython/cursor-usage/main/docs/demo.gif" alt="cursor-usage demo — monthly summary and per-day breakdown" width="760">
|
|
40
|
+
</p>
|
|
41
|
+
|
|
37
42
|
---
|
|
38
43
|
|
|
39
44
|
Cursor shows your usage on its web dashboard, but there's no official way to get
|
|
@@ -56,12 +61,22 @@ claude-4.6-opus-high 233.71 786,434 1,059,451
|
|
|
56
61
|
gemini-3.5-flash 45.77 16,097,065 1,075,904
|
|
57
62
|
gpt-5.4-high 43.65 4,069,043 1,041,967
|
|
58
63
|
...
|
|
64
|
+
|
|
65
|
+
==============================================================================
|
|
66
|
+
CURSOR CYCLE LIMITS | resets 2026-07-04
|
|
67
|
+
==============================================================================
|
|
68
|
+
Composer / Auto [###########...................] 36.7% used, 63.3% left
|
|
69
|
+
Other models [####..........................] 12.4% used, 87.6% left
|
|
70
|
+
Included usage $146.80 of $400.00 used ($253.20 left)
|
|
59
71
|
```
|
|
60
72
|
|
|
61
73
|
## ✨ Features
|
|
62
74
|
|
|
63
75
|
- **One command, real numbers** — per-model tokens and compute value for the
|
|
64
76
|
current billing month.
|
|
77
|
+
- **📊 Cycle limits** — the default summary also shows % used / % left before
|
|
78
|
+
hitting your plan's rate limit, split into **Composer / Auto** (composer-2.5,
|
|
79
|
+
composer-2.5-fast, Auto) vs **Other models**.
|
|
65
80
|
- **📅 Per-day breakdown** — `--by-day` shows how much you burned each day.
|
|
66
81
|
- **🧾 CSV export** — `--csv` dumps every usage event (timestamp, model, tokens,
|
|
67
82
|
cost) for your own spreadsheets and charts.
|
|
@@ -90,6 +105,7 @@ That's it — if you're signed in to Cursor on this machine, it just works.
|
|
|
90
105
|
| `cursor-usage --month 2026-05` | Window: a specific month |
|
|
91
106
|
| `cursor-usage --start 2026-06-01 --end 2026-06-07` | Window: an explicit range |
|
|
92
107
|
| `cursor-usage --json` | Raw aggregated JSON (for scripting) |
|
|
108
|
+
| `cursor-usage --limits-json` | Raw cycle-limits JSON (for scripting) |
|
|
93
109
|
| `cursor-usage -v` | Also print which session source was used |
|
|
94
110
|
|
|
95
111
|
Flags combine — e.g. `cursor-usage --by-day --csv june.csv --month 2026-06`.
|
|
@@ -5,12 +5,17 @@
|
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/cursor-usage/"><img alt="PyPI" src="https://img.shields.io/pypi/v/cursor-usage?color=blue&label=PyPI"></a>
|
|
8
9
|
<img alt="Python" src="https://img.shields.io/badge/python-3.8%2B-blue">
|
|
9
10
|
<img alt="Platforms" src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey">
|
|
10
11
|
<img alt="Dependencies" src="https://img.shields.io/badge/dependencies-zero-brightgreen">
|
|
11
12
|
<img alt="License" src="https://img.shields.io/badge/license-MIT-green">
|
|
12
13
|
</p>
|
|
13
14
|
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="https://raw.githubusercontent.com/javaisbetterthanpython/cursor-usage/main/docs/demo.gif" alt="cursor-usage demo — monthly summary and per-day breakdown" width="760">
|
|
17
|
+
</p>
|
|
18
|
+
|
|
14
19
|
---
|
|
15
20
|
|
|
16
21
|
Cursor shows your usage on its web dashboard, but there's no official way to get
|
|
@@ -33,12 +38,22 @@ claude-4.6-opus-high 233.71 786,434 1,059,451
|
|
|
33
38
|
gemini-3.5-flash 45.77 16,097,065 1,075,904
|
|
34
39
|
gpt-5.4-high 43.65 4,069,043 1,041,967
|
|
35
40
|
...
|
|
41
|
+
|
|
42
|
+
==============================================================================
|
|
43
|
+
CURSOR CYCLE LIMITS | resets 2026-07-04
|
|
44
|
+
==============================================================================
|
|
45
|
+
Composer / Auto [###########...................] 36.7% used, 63.3% left
|
|
46
|
+
Other models [####..........................] 12.4% used, 87.6% left
|
|
47
|
+
Included usage $146.80 of $400.00 used ($253.20 left)
|
|
36
48
|
```
|
|
37
49
|
|
|
38
50
|
## ✨ Features
|
|
39
51
|
|
|
40
52
|
- **One command, real numbers** — per-model tokens and compute value for the
|
|
41
53
|
current billing month.
|
|
54
|
+
- **📊 Cycle limits** — the default summary also shows % used / % left before
|
|
55
|
+
hitting your plan's rate limit, split into **Composer / Auto** (composer-2.5,
|
|
56
|
+
composer-2.5-fast, Auto) vs **Other models**.
|
|
42
57
|
- **📅 Per-day breakdown** — `--by-day` shows how much you burned each day.
|
|
43
58
|
- **🧾 CSV export** — `--csv` dumps every usage event (timestamp, model, tokens,
|
|
44
59
|
cost) for your own spreadsheets and charts.
|
|
@@ -67,6 +82,7 @@ That's it — if you're signed in to Cursor on this machine, it just works.
|
|
|
67
82
|
| `cursor-usage --month 2026-05` | Window: a specific month |
|
|
68
83
|
| `cursor-usage --start 2026-06-01 --end 2026-06-07` | Window: an explicit range |
|
|
69
84
|
| `cursor-usage --json` | Raw aggregated JSON (for scripting) |
|
|
85
|
+
| `cursor-usage --limits-json` | Raw cycle-limits JSON (for scripting) |
|
|
70
86
|
| `cursor-usage -v` | Also print which session source was used |
|
|
71
87
|
|
|
72
88
|
Flags combine — e.g. `cursor-usage --by-day --csv june.csv --month 2026-06`.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cursor-usage"
|
|
7
|
-
version = "0.1
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Cross-platform CLI to read your Cursor (cursor.com) usage, spend, and per-event logs."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -5,6 +5,8 @@ Endpoints used (all on ``https://cursor.com``):
|
|
|
5
5
|
GET /api/usage?user=<id> -> legacy counter + startOfMonth
|
|
6
6
|
POST /api/dashboard/get-aggregated-usage-events -> per-model tokens + cents
|
|
7
7
|
POST /api/dashboard/get-filtered-usage-events -> per-event log (paginated)
|
|
8
|
+
POST /api/dashboard/get-current-period-usage -> cycle limits (primary)
|
|
9
|
+
GET /api/usage-summary -> cycle limits (fallback)
|
|
8
10
|
|
|
9
11
|
State-changing POSTs require an ``Origin: https://cursor.com`` header (CSRF guard).
|
|
10
12
|
Auth is the ``WorkosCursorSessionToken`` cookie, value ``<sub>::<jwt>`` (the ``::``
|
|
@@ -73,6 +75,12 @@ class CursorClient:
|
|
|
73
75
|
"userId": user_id, "page": page, "pageSize": page_size},
|
|
74
76
|
)
|
|
75
77
|
|
|
78
|
+
def current_period_usage(self):
|
|
79
|
+
return self._request("/api/dashboard/get-current-period-usage", "POST", {})
|
|
80
|
+
|
|
81
|
+
def usage_summary(self):
|
|
82
|
+
return self._request("/api/usage-summary")
|
|
83
|
+
|
|
76
84
|
def all_events(self, user_id, start_ms, end_ms, page_size=1000, progress=None):
|
|
77
85
|
"""Fetch every usage event in the window by paginating.
|
|
78
86
|
|
|
@@ -29,6 +29,7 @@ import os
|
|
|
29
29
|
import sqlite3
|
|
30
30
|
import subprocess
|
|
31
31
|
import sys
|
|
32
|
+
import threading
|
|
32
33
|
from pathlib import Path
|
|
33
34
|
|
|
34
35
|
KEYCHAIN_SERVICE = "cursor-access-token"
|
|
@@ -78,15 +79,29 @@ def _from_macos_keychain():
|
|
|
78
79
|
return None
|
|
79
80
|
|
|
80
81
|
|
|
82
|
+
KEYRING_TIMEOUT = 5.0 # seconds
|
|
83
|
+
|
|
84
|
+
|
|
81
85
|
def _from_keyring():
|
|
82
86
|
try:
|
|
83
87
|
import keyring # optional dependency
|
|
84
88
|
except Exception:
|
|
85
89
|
return None
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
# A locked Linux Secret Service keyring blocks forever on an unlock prompt
|
|
91
|
+
# nobody answers (SSH, cron, a desktop nobody is watching). Ask from a
|
|
92
|
+
# daemon thread and give up after KEYRING_TIMEOUT so the state DB is tried.
|
|
93
|
+
result = []
|
|
94
|
+
|
|
95
|
+
def lookup():
|
|
96
|
+
try:
|
|
97
|
+
result.append(keyring.get_password(KEYCHAIN_SERVICE, KEYCHAIN_ACCOUNT))
|
|
98
|
+
except Exception:
|
|
99
|
+
result.append(None)
|
|
100
|
+
|
|
101
|
+
worker = threading.Thread(target=lookup, daemon=True)
|
|
102
|
+
worker.start()
|
|
103
|
+
worker.join(KEYRING_TIMEOUT)
|
|
104
|
+
return result[0] if result else None
|
|
90
105
|
|
|
91
106
|
|
|
92
107
|
def _state_db_candidates():
|
|
@@ -8,7 +8,7 @@ from datetime import datetime, timedelta, timezone
|
|
|
8
8
|
from . import __version__
|
|
9
9
|
from .api import CursorAPIError, CursorClient
|
|
10
10
|
from .auth import SessionNotFound, resolve_cookie_value
|
|
11
|
-
from .report import render_by_day, render_summary, write_csv
|
|
11
|
+
from .report import render_by_day, render_limits, render_summary, write_csv
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def _ms(dt):
|
|
@@ -41,6 +41,21 @@ def _resolve_window(args, client, user_id):
|
|
|
41
41
|
return _ms(start), _ms(end), start.strftime("%Y-%m-%d"), end.strftime("%Y-%m-%d")
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
def _fetch_limits(client):
|
|
45
|
+
"""Return cycle-limits payload; primary endpoint first, then fallback."""
|
|
46
|
+
last_err = None
|
|
47
|
+
for fn in (client.current_period_usage, client.usage_summary):
|
|
48
|
+
try:
|
|
49
|
+
payload = fn()
|
|
50
|
+
if isinstance(payload, dict):
|
|
51
|
+
return payload
|
|
52
|
+
except (CursorAPIError, OSError, ValueError) as exc:
|
|
53
|
+
last_err = exc
|
|
54
|
+
if last_err is not None:
|
|
55
|
+
raise last_err
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
|
|
44
59
|
def _progress(fetched, total):
|
|
45
60
|
if total:
|
|
46
61
|
sys.stderr.write("\r[events] %d/%d" % (fetched, total))
|
|
@@ -61,6 +76,8 @@ def build_parser():
|
|
|
61
76
|
help="write the per-event log to FILE as CSV")
|
|
62
77
|
p.add_argument("--json", action="store_true",
|
|
63
78
|
help="print the raw aggregated-usage JSON and exit")
|
|
79
|
+
p.add_argument("--limits-json", action="store_true",
|
|
80
|
+
help="print the raw cycle-limits JSON and exit")
|
|
64
81
|
g = p.add_argument_group("time window (default: current billing month)")
|
|
65
82
|
g.add_argument("--start", metavar="YYYY-MM-DD", help="window start (inclusive)")
|
|
66
83
|
g.add_argument("--end", metavar="YYYY-MM-DD", help="window end (inclusive)")
|
|
@@ -92,6 +109,21 @@ def main(argv=None):
|
|
|
92
109
|
"Re-authenticate: cursor-agent login", file=sys.stderr)
|
|
93
110
|
return 2
|
|
94
111
|
|
|
112
|
+
if args.limits_json:
|
|
113
|
+
# No time window needed; the endpoints always report the current cycle.
|
|
114
|
+
try:
|
|
115
|
+
payload = _fetch_limits(client)
|
|
116
|
+
if payload is None:
|
|
117
|
+
print("Cycle-limits endpoints returned no usable data.",
|
|
118
|
+
file=sys.stderr)
|
|
119
|
+
return 1
|
|
120
|
+
print(json.dumps(payload, indent=2))
|
|
121
|
+
except (CursorAPIError, OSError, ValueError) as exc:
|
|
122
|
+
print("Cycle-limits endpoints returned no usable JSON: %s" % exc,
|
|
123
|
+
file=sys.stderr)
|
|
124
|
+
return 1
|
|
125
|
+
return 0
|
|
126
|
+
|
|
95
127
|
start_ms, end_ms, start_label, end_label = _resolve_window(args, client, user_id)
|
|
96
128
|
meta = {"email": email, "start": start_label, "end": end_label}
|
|
97
129
|
|
|
@@ -102,6 +134,15 @@ def main(argv=None):
|
|
|
102
134
|
# The aggregated endpoint powers the summary (one cheap call).
|
|
103
135
|
print(render_summary(client.aggregated_usage(user_id, start_ms, end_ms), meta))
|
|
104
136
|
|
|
137
|
+
try:
|
|
138
|
+
section = render_limits(_fetch_limits(client))
|
|
139
|
+
if section:
|
|
140
|
+
print()
|
|
141
|
+
print(section)
|
|
142
|
+
except (CursorAPIError, OSError, ValueError) as exc:
|
|
143
|
+
if args.verbose:
|
|
144
|
+
print("[limits] unavailable: %s" % exc, file=sys.stderr)
|
|
145
|
+
|
|
105
146
|
# Per-event data powers --by-day and --csv; fetch it once if needed.
|
|
106
147
|
if args.by_day or args.csv:
|
|
107
148
|
events, total = client.all_events(
|
|
@@ -132,3 +132,129 @@ def write_csv(events, path):
|
|
|
132
132
|
|
|
133
133
|
def to_iso(ms):
|
|
134
134
|
return datetime.fromtimestamp(ms / 1000, tz=timezone.utc).strftime("%Y-%m-%d")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# --- cycle limits (from get-current-period-usage / usage-summary) --------
|
|
138
|
+
def _optional_f(d, k):
|
|
139
|
+
if k not in d:
|
|
140
|
+
return None
|
|
141
|
+
try:
|
|
142
|
+
v = d[k]
|
|
143
|
+
if v is None:
|
|
144
|
+
return None
|
|
145
|
+
return float(v or 0)
|
|
146
|
+
except (TypeError, ValueError):
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _optional_i(d, k):
|
|
151
|
+
if k not in d:
|
|
152
|
+
return None
|
|
153
|
+
try:
|
|
154
|
+
v = d[k]
|
|
155
|
+
if v is None:
|
|
156
|
+
return None
|
|
157
|
+
return int(v or 0)
|
|
158
|
+
except (TypeError, ValueError):
|
|
159
|
+
return None
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _parse_reset_date(payload):
|
|
163
|
+
raw = payload.get("billingCycleEnd")
|
|
164
|
+
if raw is None:
|
|
165
|
+
return None
|
|
166
|
+
try:
|
|
167
|
+
s = str(raw).strip()
|
|
168
|
+
if s.isdigit():
|
|
169
|
+
ms = int(s)
|
|
170
|
+
return datetime.fromtimestamp(ms / 1000, tz=timezone.utc).strftime(
|
|
171
|
+
"%Y-%m-%d")
|
|
172
|
+
return datetime.fromisoformat(s.replace("Z", "+00:00")).strftime(
|
|
173
|
+
"%Y-%m-%d")
|
|
174
|
+
except (TypeError, ValueError, OSError):
|
|
175
|
+
return None
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _limit_bar(pct, width=30):
|
|
179
|
+
filled = int(round(pct / 100.0 * width))
|
|
180
|
+
filled = max(0, min(width, filled))
|
|
181
|
+
return "#" * filled + "." * (width - filled)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _limit_bucket_line(label, pct):
|
|
185
|
+
if pct is None:
|
|
186
|
+
return None
|
|
187
|
+
bar = _limit_bar(pct)
|
|
188
|
+
left = max(0.0, 100.0 - pct)
|
|
189
|
+
return "%-16s[%s] %6.1f%% used, %6.1f%% left" % (label, bar, pct, left)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def render_limits(payload):
|
|
193
|
+
"""Render cycle-limit % bars and included-usage dollars, or None."""
|
|
194
|
+
if not payload or not isinstance(payload, dict):
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
plan = (payload.get("planUsage")
|
|
198
|
+
or (payload.get("individualUsage") or {}).get("plan")
|
|
199
|
+
or {})
|
|
200
|
+
|
|
201
|
+
enabled = payload.get("enabled", plan.get("enabled", True))
|
|
202
|
+
if not enabled:
|
|
203
|
+
return None
|
|
204
|
+
|
|
205
|
+
is_unlimited = bool(payload.get("isUnlimited"))
|
|
206
|
+
|
|
207
|
+
auto_pct = _optional_f(plan, "autoPercentUsed")
|
|
208
|
+
api_pct = _optional_f(plan, "apiPercentUsed")
|
|
209
|
+
|
|
210
|
+
used = None
|
|
211
|
+
if "totalSpend" in plan:
|
|
212
|
+
used = _optional_i(plan, "totalSpend")
|
|
213
|
+
if used is None and "used" in plan:
|
|
214
|
+
used = _optional_i(plan, "used")
|
|
215
|
+
|
|
216
|
+
limit = _optional_i(plan, "limit") if "limit" in plan else None
|
|
217
|
+
|
|
218
|
+
remaining = None
|
|
219
|
+
if "remaining" in plan:
|
|
220
|
+
remaining = _optional_i(plan, "remaining")
|
|
221
|
+
if remaining is None and limit is not None and used is not None:
|
|
222
|
+
remaining = max(0, limit - used)
|
|
223
|
+
|
|
224
|
+
money_line = None
|
|
225
|
+
if limit is not None and limit > 0 and used is not None and remaining is not None:
|
|
226
|
+
money_line = "%-16s%s of %s used (%s left)" % (
|
|
227
|
+
"Included usage", _money(used), _money(limit), _money(remaining))
|
|
228
|
+
|
|
229
|
+
if (not is_unlimited and auto_pct is None and api_pct is None
|
|
230
|
+
and not money_line):
|
|
231
|
+
return None
|
|
232
|
+
|
|
233
|
+
reset = _parse_reset_date(payload)
|
|
234
|
+
|
|
235
|
+
out = ["=" * 78]
|
|
236
|
+
header = "CURSOR CYCLE LIMITS"
|
|
237
|
+
if reset:
|
|
238
|
+
header += " | resets %s" % reset
|
|
239
|
+
out.append(header)
|
|
240
|
+
out.append("=" * 78)
|
|
241
|
+
|
|
242
|
+
if is_unlimited:
|
|
243
|
+
out.append("Plan reports unlimited usage for this cycle.")
|
|
244
|
+
if money_line:
|
|
245
|
+
out.append(money_line)
|
|
246
|
+
return "\n".join(out)
|
|
247
|
+
|
|
248
|
+
for label, pct in [("Composer / Auto", auto_pct),
|
|
249
|
+
("Other models", api_pct)]:
|
|
250
|
+
line = _limit_bucket_line(label, pct)
|
|
251
|
+
if line:
|
|
252
|
+
out.append(line)
|
|
253
|
+
|
|
254
|
+
if money_line:
|
|
255
|
+
out.append(money_line)
|
|
256
|
+
|
|
257
|
+
if len(out) <= 3:
|
|
258
|
+
return None
|
|
259
|
+
|
|
260
|
+
return "\n".join(out)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cursor-usage
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Cross-platform CLI to read your Cursor (cursor.com) usage, spend, and per-event logs.
|
|
5
5
|
Author: cursor-usage contributors
|
|
6
6
|
License: MIT
|
|
@@ -28,12 +28,17 @@ Dynamic: license-file
|
|
|
28
28
|
</p>
|
|
29
29
|
|
|
30
30
|
<p align="center">
|
|
31
|
+
<a href="https://pypi.org/project/cursor-usage/"><img alt="PyPI" src="https://img.shields.io/pypi/v/cursor-usage?color=blue&label=PyPI"></a>
|
|
31
32
|
<img alt="Python" src="https://img.shields.io/badge/python-3.8%2B-blue">
|
|
32
33
|
<img alt="Platforms" src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey">
|
|
33
34
|
<img alt="Dependencies" src="https://img.shields.io/badge/dependencies-zero-brightgreen">
|
|
34
35
|
<img alt="License" src="https://img.shields.io/badge/license-MIT-green">
|
|
35
36
|
</p>
|
|
36
37
|
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img src="https://raw.githubusercontent.com/javaisbetterthanpython/cursor-usage/main/docs/demo.gif" alt="cursor-usage demo — monthly summary and per-day breakdown" width="760">
|
|
40
|
+
</p>
|
|
41
|
+
|
|
37
42
|
---
|
|
38
43
|
|
|
39
44
|
Cursor shows your usage on its web dashboard, but there's no official way to get
|
|
@@ -56,12 +61,22 @@ claude-4.6-opus-high 233.71 786,434 1,059,451
|
|
|
56
61
|
gemini-3.5-flash 45.77 16,097,065 1,075,904
|
|
57
62
|
gpt-5.4-high 43.65 4,069,043 1,041,967
|
|
58
63
|
...
|
|
64
|
+
|
|
65
|
+
==============================================================================
|
|
66
|
+
CURSOR CYCLE LIMITS | resets 2026-07-04
|
|
67
|
+
==============================================================================
|
|
68
|
+
Composer / Auto [###########...................] 36.7% used, 63.3% left
|
|
69
|
+
Other models [####..........................] 12.4% used, 87.6% left
|
|
70
|
+
Included usage $146.80 of $400.00 used ($253.20 left)
|
|
59
71
|
```
|
|
60
72
|
|
|
61
73
|
## ✨ Features
|
|
62
74
|
|
|
63
75
|
- **One command, real numbers** — per-model tokens and compute value for the
|
|
64
76
|
current billing month.
|
|
77
|
+
- **📊 Cycle limits** — the default summary also shows % used / % left before
|
|
78
|
+
hitting your plan's rate limit, split into **Composer / Auto** (composer-2.5,
|
|
79
|
+
composer-2.5-fast, Auto) vs **Other models**.
|
|
65
80
|
- **📅 Per-day breakdown** — `--by-day` shows how much you burned each day.
|
|
66
81
|
- **🧾 CSV export** — `--csv` dumps every usage event (timestamp, model, tokens,
|
|
67
82
|
cost) for your own spreadsheets and charts.
|
|
@@ -90,6 +105,7 @@ That's it — if you're signed in to Cursor on this machine, it just works.
|
|
|
90
105
|
| `cursor-usage --month 2026-05` | Window: a specific month |
|
|
91
106
|
| `cursor-usage --start 2026-06-01 --end 2026-06-07` | Window: an explicit range |
|
|
92
107
|
| `cursor-usage --json` | Raw aggregated JSON (for scripting) |
|
|
108
|
+
| `cursor-usage --limits-json` | Raw cycle-limits JSON (for scripting) |
|
|
93
109
|
| `cursor-usage -v` | Also print which session source was used |
|
|
94
110
|
|
|
95
111
|
Flags combine — e.g. `cursor-usage --by-day --csv june.csv --month 2026-06`.
|
|
@@ -25,3 +25,28 @@ def test_jwt_claims_roundtrip():
|
|
|
25
25
|
def test_jwt_claims_handles_garbage():
|
|
26
26
|
assert _jwt_claims("not-a-jwt") == {}
|
|
27
27
|
assert _jwt_claims("") == {}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_keyring_that_hangs_is_skipped(monkeypatch):
|
|
31
|
+
import sys
|
|
32
|
+
import threading
|
|
33
|
+
import types
|
|
34
|
+
|
|
35
|
+
from cursor_usage import auth
|
|
36
|
+
|
|
37
|
+
never = threading.Event()
|
|
38
|
+
fake = types.SimpleNamespace(get_password=lambda *a: never.wait())
|
|
39
|
+
monkeypatch.setitem(sys.modules, "keyring", fake)
|
|
40
|
+
monkeypatch.setattr(auth, "KEYRING_TIMEOUT", 0.1)
|
|
41
|
+
assert auth._from_keyring() is None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_keyring_answer_is_returned(monkeypatch):
|
|
45
|
+
import sys
|
|
46
|
+
import types
|
|
47
|
+
|
|
48
|
+
from cursor_usage import auth
|
|
49
|
+
|
|
50
|
+
fake = types.SimpleNamespace(get_password=lambda *a: "tok")
|
|
51
|
+
monkeypatch.setitem(sys.modules, "keyring", fake)
|
|
52
|
+
assert auth._from_keyring() == "tok"
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
from cursor_usage.report import render_limits
|
|
2
|
+
|
|
3
|
+
PRIMARY = {
|
|
4
|
+
"billingCycleStart": "1783126408000",
|
|
5
|
+
"billingCycleEnd": "1785804808000",
|
|
6
|
+
"planUsage": {
|
|
7
|
+
"totalSpend": 1047,
|
|
8
|
+
"includedSpend": 1047,
|
|
9
|
+
"remaining": 38953,
|
|
10
|
+
"limit": 40000,
|
|
11
|
+
"autoPercentUsed": 1.047,
|
|
12
|
+
"apiPercentUsed": 0,
|
|
13
|
+
"totalPercentUsed": 0.698,
|
|
14
|
+
},
|
|
15
|
+
"enabled": True,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
FALLBACK = {
|
|
19
|
+
"billingCycleStart": "2026-07-04T00:53:28.000Z",
|
|
20
|
+
"billingCycleEnd": "2026-08-04T00:53:28.000Z",
|
|
21
|
+
"membershipType": "ultra",
|
|
22
|
+
"isUnlimited": False,
|
|
23
|
+
"individualUsage": {
|
|
24
|
+
"plan": {
|
|
25
|
+
"enabled": True,
|
|
26
|
+
"used": 1002,
|
|
27
|
+
"limit": 40000,
|
|
28
|
+
"remaining": 38998,
|
|
29
|
+
"autoPercentUsed": 1.002,
|
|
30
|
+
"apiPercentUsed": 0,
|
|
31
|
+
"totalPercentUsed": 0.668,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_primary_shape_renders_buckets_and_money():
|
|
38
|
+
out = render_limits(PRIMARY)
|
|
39
|
+
assert out is not None
|
|
40
|
+
assert "Composer / Auto" in out
|
|
41
|
+
assert "Other models" in out
|
|
42
|
+
assert "1.0% used" in out
|
|
43
|
+
assert "99.0% left" in out
|
|
44
|
+
assert "$10.47 of $400.00 used" in out
|
|
45
|
+
assert "($389.53 left)" in out
|
|
46
|
+
assert "resets 2026-08-04" in out
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_fallback_shape_renders():
|
|
50
|
+
out = render_limits(FALLBACK)
|
|
51
|
+
assert out is not None
|
|
52
|
+
assert "resets 2026-08-04" in out
|
|
53
|
+
assert "$10.02 of $400.00" in out
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_zero_percents_empty_bar():
|
|
57
|
+
payload = dict(PRIMARY)
|
|
58
|
+
payload["planUsage"] = dict(PRIMARY["planUsage"])
|
|
59
|
+
payload["planUsage"]["autoPercentUsed"] = 0
|
|
60
|
+
payload["planUsage"]["apiPercentUsed"] = 0
|
|
61
|
+
out = render_limits(payload)
|
|
62
|
+
assert "0.0% used" in out
|
|
63
|
+
assert "100.0% left" in out
|
|
64
|
+
assert "[..............................]" in out
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_percent_over_100_full_bar():
|
|
68
|
+
payload = dict(PRIMARY)
|
|
69
|
+
payload["planUsage"] = dict(PRIMARY["planUsage"])
|
|
70
|
+
payload["planUsage"]["autoPercentUsed"] = 103.5
|
|
71
|
+
out = render_limits(payload)
|
|
72
|
+
assert "[##############################]" in out
|
|
73
|
+
assert "103.5% used" in out
|
|
74
|
+
assert "0.0% left" in out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_unlimited_no_bars():
|
|
78
|
+
payload = dict(PRIMARY)
|
|
79
|
+
payload["isUnlimited"] = True
|
|
80
|
+
out = render_limits(payload)
|
|
81
|
+
assert "unlimited usage" in out
|
|
82
|
+
assert "[" not in out.split("unlimited")[1]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_missing_plan_returns_none():
|
|
86
|
+
assert render_limits({"enabled": True}) is None
|
|
87
|
+
assert render_limits({}) is None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_enabled_false_returns_none():
|
|
91
|
+
payload = dict(PRIMARY)
|
|
92
|
+
payload["enabled"] = False
|
|
93
|
+
assert render_limits(payload) is None
|
|
94
|
+
payload2 = dict(FALLBACK)
|
|
95
|
+
payload2["individualUsage"] = dict(FALLBACK["individualUsage"])
|
|
96
|
+
payload2["individualUsage"]["plan"] = dict(
|
|
97
|
+
FALLBACK["individualUsage"]["plan"])
|
|
98
|
+
payload2["individualUsage"]["plan"]["enabled"] = False
|
|
99
|
+
assert render_limits(payload2) is None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_zero_limit_no_money_line():
|
|
103
|
+
payload = dict(PRIMARY)
|
|
104
|
+
payload["planUsage"] = dict(PRIMARY["planUsage"])
|
|
105
|
+
payload["planUsage"]["limit"] = 0
|
|
106
|
+
out = render_limits(payload)
|
|
107
|
+
assert out is not None
|
|
108
|
+
assert "$" not in out
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_string_numbers_tolerated():
|
|
112
|
+
payload = dict(PRIMARY)
|
|
113
|
+
payload["planUsage"] = dict(PRIMARY["planUsage"])
|
|
114
|
+
payload["planUsage"]["totalSpend"] = "1047"
|
|
115
|
+
payload["planUsage"]["limit"] = "40000"
|
|
116
|
+
payload["planUsage"]["remaining"] = "38953"
|
|
117
|
+
out = render_limits(payload)
|
|
118
|
+
assert "$10.47 of $400.00 used" in out
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_garbage_reset_date_omits_resets():
|
|
122
|
+
payload = dict(PRIMARY)
|
|
123
|
+
payload["billingCycleEnd"] = "not-a-date"
|
|
124
|
+
out = render_limits(payload)
|
|
125
|
+
assert out is not None
|
|
126
|
+
assert "resets" not in out
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_derived_remaining_when_missing():
|
|
130
|
+
payload = dict(PRIMARY)
|
|
131
|
+
payload["planUsage"] = dict(PRIMARY["planUsage"])
|
|
132
|
+
del payload["planUsage"]["remaining"]
|
|
133
|
+
out = render_limits(payload)
|
|
134
|
+
assert "($389.53 left)" in out
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_null_total_spend_falls_back_to_used():
|
|
138
|
+
payload = dict(PRIMARY)
|
|
139
|
+
payload["planUsage"] = dict(PRIMARY["planUsage"])
|
|
140
|
+
payload["planUsage"]["totalSpend"] = None
|
|
141
|
+
payload["planUsage"]["used"] = 1002
|
|
142
|
+
out = render_limits(payload)
|
|
143
|
+
assert "$10.02 of $400.00 used" in out
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_null_remaining_derived_from_limit():
|
|
147
|
+
payload = dict(PRIMARY)
|
|
148
|
+
payload["planUsage"] = dict(PRIMARY["planUsage"])
|
|
149
|
+
payload["planUsage"]["remaining"] = None
|
|
150
|
+
out = render_limits(payload)
|
|
151
|
+
assert "($389.53 left)" in out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|