teamspend-cli 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.
Files changed (36) hide show
  1. teamspend_cli-0.2.1/.gitignore +8 -0
  2. teamspend_cli-0.2.1/LICENSE +202 -0
  3. teamspend_cli-0.2.1/PKG-INFO +386 -0
  4. teamspend_cli-0.2.1/README.md +350 -0
  5. teamspend_cli-0.2.1/examples/README.md +35 -0
  6. teamspend_cli-0.2.1/pyproject.toml +66 -0
  7. teamspend_cli-0.2.1/src/teamspend/__init__.py +82 -0
  8. teamspend_cli-0.2.1/src/teamspend/adapters/__init__.py +9 -0
  9. teamspend_cli-0.2.1/src/teamspend/adapters/claude_code.py +77 -0
  10. teamspend_cli-0.2.1/src/teamspend/adapters/claude_code_personal.py +258 -0
  11. teamspend_cli-0.2.1/src/teamspend/adapters/codex.py +265 -0
  12. teamspend_cli-0.2.1/src/teamspend/adapters/copilot.py +189 -0
  13. teamspend_cli-0.2.1/src/teamspend/adapters/csv_import.py +127 -0
  14. teamspend_cli-0.2.1/src/teamspend/adapters/cursor.py +114 -0
  15. teamspend_cli-0.2.1/src/teamspend/adapters/opencode.py +250 -0
  16. teamspend_cli-0.2.1/src/teamspend/cli.py +318 -0
  17. teamspend_cli-0.2.1/src/teamspend/compare.py +77 -0
  18. teamspend_cli-0.2.1/src/teamspend/errors.py +96 -0
  19. teamspend_cli-0.2.1/src/teamspend/http_client.py +204 -0
  20. teamspend_cli-0.2.1/src/teamspend/output.py +251 -0
  21. teamspend_cli-0.2.1/src/teamspend/py.typed +0 -0
  22. teamspend_cli-0.2.1/src/teamspend/types.py +111 -0
  23. teamspend_cli-0.2.1/tests/__init__.py +0 -0
  24. teamspend_cli-0.2.1/tests/conftest.py +50 -0
  25. teamspend_cli-0.2.1/tests/test_claude_code.py +97 -0
  26. teamspend_cli-0.2.1/tests/test_claude_code_personal.py +299 -0
  27. teamspend_cli-0.2.1/tests/test_cli.py +253 -0
  28. teamspend_cli-0.2.1/tests/test_codex.py +173 -0
  29. teamspend_cli-0.2.1/tests/test_compare.py +64 -0
  30. teamspend_cli-0.2.1/tests/test_copilot.py +275 -0
  31. teamspend_cli-0.2.1/tests/test_csv_import.py +77 -0
  32. teamspend_cli-0.2.1/tests/test_cursor.py +191 -0
  33. teamspend_cli-0.2.1/tests/test_http_client.py +136 -0
  34. teamspend_cli-0.2.1/tests/test_opencode.py +200 -0
  35. teamspend_cli-0.2.1/tests/test_output.py +260 -0
  36. teamspend_cli-0.2.1/tests/test_types.py +63 -0
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ .venv-freshinstall/
3
+ dist/
4
+ build/
5
+ *.egg-info/
6
+ __pycache__/
7
+ *.pyc
8
+ .pytest_cache/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Rudrendu Paul and Sourav Nandy
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,386 @@
1
+ Metadata-Version: 2.4
2
+ Name: teamspend-cli
3
+ Version: 0.2.1
4
+ Summary: Compare AI coding tool spend before and after a migration -- Cursor, Claude Code, GitHub Copilot, OpenCode, and Codex CLI, real numbers pulled from each vendor's own API or local logs, one command, zero runtime dependencies.
5
+ Project-URL: Homepage, https://github.com/RudrenduPaul/teamspend
6
+ Project-URL: Repository, https://github.com/RudrenduPaul/teamspend
7
+ Project-URL: Bug Tracker, https://github.com/RudrenduPaul/teamspend/issues
8
+ Project-URL: Changelog, https://github.com/RudrenduPaul/teamspend/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/RudrenduPaul/teamspend/blob/main/docs/getting-started.md
10
+ Project-URL: Author - Rudrendu Paul, https://github.com/RudrenduPaul
11
+ Project-URL: Author - Sourav Nandy, https://github.com/Sourav-nandy-ai
12
+ Author: Rudrendu Paul, Sourav Nandy
13
+ License-Expression: Apache-2.0
14
+ License-File: LICENSE
15
+ Keywords: ai-coding-agents,claude-code,cli,codex,cost,cost-tracking,cursor,finops,github-copilot,opencode
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Environment :: Console
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: License :: OSI Approved :: Apache Software License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Topic :: Office/Business :: Financial
28
+ Classifier: Topic :: Software Development :: Quality Assurance
29
+ Classifier: Topic :: Utilities
30
+ Requires-Python: >=3.9
31
+ Provides-Extra: dev
32
+ Requires-Dist: build<2,>=1.0; extra == 'dev'
33
+ Requires-Dist: pytest<9,>=7.0; extra == 'dev'
34
+ Requires-Dist: twine<7,>=5.0; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # teamspend (Python)
38
+
39
+ Compare AI coding tool spend before and after a migration -- Cursor,
40
+ Claude Code, GitHub Copilot, OpenCode, and Codex CLI, real numbers pulled
41
+ from each vendor's own API or local logs, one command.
42
+
43
+ [![PyPI version](https://img.shields.io/pypi/v/teamspend.svg)](https://pypi.org/project/teamspend/)
44
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/RudrenduPaul/teamspend/blob/main/LICENSE)
45
+ [![Python versions](https://img.shields.io/pypi/pyversions/teamspend.svg)](https://pypi.org/project/teamspend/)
46
+ [![npm version](https://img.shields.io/npm/v/teamspend-cli.svg)](https://www.npmjs.com/package/teamspend-cli)
47
+
48
+ ## Why this exists
49
+
50
+ More teams are running more than one AI coding tool at once, or moving
51
+ between them, than ever before. Cursor's Admin API reports Cursor spend.
52
+ Anthropic's Claude Enterprise Analytics API reports Claude Code spend.
53
+ Neither has a reason to show a competitor's number next to its own, so a
54
+ team mid-migration is left opening two dashboards and doing the
55
+ subtraction by hand. teamspend pulls both sides through the same
56
+ normalized schema and prints one honest delta. This package is the Python
57
+ distribution -- a genuine, independent port, not a wrapper around the
58
+ Node binary.
59
+
60
+ ## Install
61
+
62
+ ```bash
63
+ pip install teamspend
64
+ ```
65
+
66
+ or with [uv](https://docs.astral.sh/uv/):
67
+
68
+ ```bash
69
+ uv add teamspend
70
+ ```
71
+
72
+ Zero runtime dependencies: the standard library's `urllib` handles every
73
+ admin-API call. The complementary JS/TS distribution installs the same way
74
+ on the npm side: `npm install -g teamspend-cli` (or `npx teamspend-cli ...`
75
+ to run it once without installing; the older `teamspend` npm name is
76
+ deprecated in favor of `teamspend-cli`, same maintainer and repo) -- see the
77
+ [project README](https://github.com/RudrenduPaul/teamspend#readme) for
78
+ that package. Both distributions (this PyPI package and the npm package)
79
+ are first-class and maintained together.
80
+
81
+ ## Quickstart
82
+
83
+ ```bash
84
+ export TEAMSPEND_CURSOR_TOKEN=<your Cursor Admin API key>
85
+ export TEAMSPEND_CLAUDE_CODE_TOKEN=<your Anthropic Admin/Analytics API key>
86
+
87
+ teamspend --tools cursor,claude-code \
88
+ --before 2026-04-01:2026-04-30 \
89
+ --after 2026-06-01:2026-06-30
90
+ ```
91
+
92
+ Both credentials need org-admin-level access on their platform. If you can
93
+ already see billing for your org, you have what you need.
94
+
95
+ Output (shape shown below; your real numbers come from your own org's API
96
+ data):
97
+
98
+ ```
99
+ teamspend snapshot -- migration cost comparison
100
+ Tools: cursor -> claude-code
101
+
102
+ BEFORE (cursor)
103
+ Total spend: $2140.00 (exact, usage-based)
104
+ Active users: 14
105
+
106
+ AFTER (claude-code)
107
+ Total spend: $1860.00 (exact, usage-based)
108
+ Active users: 14
109
+
110
+ DELTA: -$280.00 (-13.1%)
111
+
112
+ Full report: ./teamspend-snapshot-2026-07-16T2031.json
113
+ ```
114
+
115
+ Exit code `0` means both periods fetched successfully, `1` means at least
116
+ one side failed (auth, a vendor API window limit, or a CLI argument
117
+ error) -- see `DATA UNAVAILABLE` in the terminal output and the `error`
118
+ field of the JSON report for the reason.
119
+
120
+ ## GitHub Copilot support
121
+
122
+ ```bash
123
+ export TEAMSPEND_COPILOT_TOKEN=<a token with read:org on the org>
124
+ export TEAMSPEND_COPILOT_ORG=<your GitHub org login>
125
+ export TEAMSPEND_COPILOT_SEAT_PRICE_USD=19 # optional
126
+
127
+ teamspend --tools cursor,copilot --before 2026-04-01:2026-04-30 --after 2026-06-01:2026-06-30
128
+ ```
129
+
130
+ GitHub's real Copilot usage metrics API has no cost/spend field at all --
131
+ only usage counts, most usefully `ai_credits_used`. teamspend converts that
132
+ to USD at GitHub's own published, fixed rate of 1 AI credit = $0.01 USD,
133
+ and adds `TEAMSPEND_COPILOT_SEAT_PRICE_USD` (if set) once per user for the
134
+ whole window to also reflect the flat per-seat license price GitHub's API
135
+ never exposes. Every Copilot result is therefore always `is_estimated`,
136
+ regardless of whether a seat price was supplied -- see the project
137
+ [README's "GitHub Copilot support" section](https://github.com/RudrenduPaul/teamspend#github-copilot-support)
138
+ and [docs/concepts.md](https://github.com/RudrenduPaul/teamspend/blob/main/docs/concepts.md#copilots-usage-based-report-pagination-and-cost-derivation)
139
+ for the full mechanics.
140
+
141
+ ## OpenCode and Codex CLI: local-only, no API key needed
142
+
143
+ ```bash
144
+ teamspend --tools claude-code,opencode --before 2026-04-01:2026-04-30 --after 2026-06-01:2026-06-30
145
+ teamspend --tools claude-code,codex --before 2026-04-01:2026-04-30 --after 2026-06-01:2026-06-30
146
+ ```
147
+
148
+ Neither [OpenCode](https://github.com/anomalyco/opencode) nor
149
+ [Codex CLI](https://github.com/openai/codex) has an admin, team, or
150
+ billing API -- both are local CLIs, so teamspend reads their own local
151
+ session logs directly off disk instead: `~/.local/share/opencode/storage/message/`
152
+ for OpenCode, `~/.codex/sessions/YYYY/MM/DD/` for Codex. No credential,
153
+ no network call for either. Both results attribute everything to the
154
+ single local user running the command, not a team, and are always marked
155
+ `is_estimated`: OpenCode stores `cost: 0` for most models in its own
156
+ logs, and Codex's local data has no cost field at all, only exact token
157
+ counts. Codex also only keeps roughly the last 7 days of logs readable
158
+ before background-compressing them. See the project README's
159
+ [OpenCode](https://github.com/RudrenduPaul/teamspend#opencode-local-only-no-api-key-needed)
160
+ and [Codex CLI](https://github.com/RudrenduPaul/teamspend#codex-cli-local-only-no-api-key-needed)
161
+ sections for the full mechanics and caveats.
162
+
163
+ ## Personal usage mode, for when you don't have admin access
164
+
165
+ ```bash
166
+ teamspend --tools claude-code-personal,claude-code-personal --before 2026-04-01:2026-04-30 --after 2026-06-01:2026-06-30
167
+ ```
168
+
169
+ If you just want your own personal Claude Code spend and don't have (or
170
+ don't want to use) org-admin access, use `claude-code-personal` instead
171
+ of `claude-code`. It reads Claude Code's own local JSONL session logs
172
+ straight off disk, no API key, no network call, no admin access needed --
173
+ just the logs Claude Code already writes on your machine.
174
+
175
+ ## Session-level cost breakdown
176
+
177
+ ```bash
178
+ teamspend --tools claude-code-personal,claude-code-personal --before 2026-04-01:2026-04-30 --after 2026-06-01:2026-06-30 --breakdown session
179
+ ```
180
+
181
+ Add `--breakdown session` to break a flat total down by session, using
182
+ the `sessionId`/`sessionID` each log entry already carries -- available
183
+ for `claude-code-personal` and `opencode` only, since `cursor`,
184
+ `claude-code`, and `copilot` pull from admin APIs that return per-user
185
+ aggregates with no session field to group by. A session is the most
186
+ honest proxy teamspend can offer for "cost per task" -- it is not a
187
+ measure of whether that session's output was actually good, since no
188
+ vendor exposes that.
189
+
190
+ ## Using the library instead of the CLI
191
+
192
+ Both packages export a programmatic API for scripts and CI gates that want
193
+ to call teamspend in-process instead of shelling out to a CLI binary.
194
+
195
+ **TypeScript:**
196
+
197
+ ```ts
198
+ import { fetchCursorSpend, fetchClaudeCodeSpend, buildComparison } from 'teamspend';
199
+ ```
200
+
201
+ **Python:**
202
+
203
+ ```python
204
+ from teamspend import fetch_cursor_spend, fetch_claude_code_spend, build_comparison, DateWindow, PeriodOutcome
205
+
206
+ before_window = DateWindow("2026-04-01", "2026-04-30")
207
+ after_window = DateWindow("2026-06-01", "2026-06-30")
208
+
209
+ before_result = fetch_cursor_spend(before_window, cursor_api_key)
210
+ after_result = fetch_claude_code_spend(after_window, claude_api_key)
211
+
212
+ report = build_comparison(
213
+ PeriodOutcome("before", "cursor", before_result, None),
214
+ PeriodOutcome("after", "claude-code", after_result, None),
215
+ )
216
+ print(report.delta_usd, report.delta_percent)
217
+ ```
218
+
219
+ Both return the same shape of normalized data (`total_cost_usd`/
220
+ `totalCostUsd`, `users`, `is_estimated`/`isEstimated`) -- see
221
+ [docs/concepts.md](https://github.com/RudrenduPaul/teamspend/blob/main/docs/concepts.md)
222
+ for the full data model.
223
+
224
+ ## How it works
225
+
226
+ ```
227
+ CLI flags / env vars
228
+ -> two adapters run concurrently (ThreadPoolExecutor, 2 workers)
229
+ - Cursor: 30-day-chunk pagination against api.cursor.com/admin/usage, summed per user
230
+ - Claude Code: single call to api.anthropic.com .../usage_report/claude_code
231
+ (guarded: no data before 2026-01-01)
232
+ -> each field read from a response is validated (require_field) --
233
+ missing field raises SchemaDriftError, never a silent guess
234
+ -> suspicious-zero detection: real token/request activity + cost 0
235
+ -> that user, and the whole side, is marked isEstimated
236
+ -> build_comparison(): before/after -> delta_usd, delta_percent,
237
+ top 5 spenders across both periods
238
+ -> terminal summary + JSON report (0600 file perms) written to cwd
239
+ ```
240
+
241
+ **Concurrency and failure isolation.** `cli.py`'s `run()` submits the
242
+ before and after fetches to a 2-worker `ThreadPoolExecutor` and resolves
243
+ each `Future` independently, catching any exception per side into a
244
+ `PeriodOutcome(result=None, error=...)` rather than letting one side's
245
+ failure abort the other -- mirroring the TypeScript CLI's
246
+ `Promise.allSettled`. Exit code `0` requires both sides to have a
247
+ `result`; either side without one returns exit code `1`.
248
+
249
+ **Retry/backoff.** Every adapter call goes through `http_client.py`'s
250
+ `fetch_with_retry`, which retries HTTP 429 and 5xx responses up to 3
251
+ times with exponential backoff (0.5s base, doubling), raises
252
+ `AuthenticationError` immediately -- never retried -- on 401/403, and
253
+ raises `RetryExhaustedError` once the retry budget is spent. The real
254
+ network call sits behind a swappable `transport` function (`urllib` in
255
+ production), which is how the pytest suite simulates arbitrary HTTP
256
+ statuses without opening a real socket.
257
+
258
+ **Cursor pagination.** The Cursor Admin API caps each call's window at 30
259
+ days, so `adapters/cursor.py`'s `_split_into_chunks` breaks any longer
260
+ `--before`/`--after` window into consecutive 30-day chunks, fetches each
261
+ one, and sums the result per `user_id`. If any chunk fails after retries
262
+ are exhausted, the entire fetch fails -- it never reports a total built
263
+ from only the chunks that happened to succeed.
264
+
265
+ **Claude Code start-date guard.** Anthropic's Claude Enterprise Analytics
266
+ API has no data before 2026-01-01. `adapters/claude_code.py` checks the
267
+ requested window's start date before making any request and raises
268
+ `DataUnavailableError` if it predates that date; the CLI then falls back
269
+ to `--before-csv`/`--after-csv` for that side if one was passed, or
270
+ surfaces the error as that side's `PeriodOutcome.error` otherwise.
271
+
272
+ **Suspicious-zero detection.** Cursor plans without usage overage, and
273
+ Claude.ai Team/Enterprise seats, report a technically valid `cost_usd`/
274
+ `spend_usd` of exactly 0 for a user who clearly has real token or request
275
+ activity. Both adapters check for that specific combination and mark that
276
+ user -- and the whole side's `is_estimated` flag -- as estimated, so the
277
+ output never shows a misleading exact-looking $0 next to genuine usage.
278
+
279
+ **The comparison itself.** `compare.py`'s `build_comparison()` takes two
280
+ independently-resolved `PeriodOutcome`s. `delta_usd` and `delta_percent`
281
+ are computed only when both sides have a `result`; otherwise they're
282
+ `None` and the terminal output prints `DELTA: unavailable`. It also
283
+ collects the top 5 spenders from each side, merges and re-sorts them by
284
+ cost, and keeps the top 5 across both periods combined.
285
+
286
+ ## CSV import, for the history a live API can't reach
287
+
288
+ ```bash
289
+ teamspend --tools cursor,claude-code \
290
+ --before 2025-11-01:2025-11-30 \
291
+ --after 2026-06-01:2026-06-30 \
292
+ --before-csv ./before.csv
293
+ ```
294
+
295
+ CSV schema: `date,user_email,cost_usd,is_estimated`, one row per user per
296
+ day. Rows are aggregated per `user_email`.
297
+
298
+ ## Good to know before you run it
299
+
300
+ - This is a snapshot tool, not a running dashboard. It answers one
301
+ question well and stops.
302
+ - The output includes real emails and dollar amounts, printed to your
303
+ terminal and saved to a report file (`0600` permissions, auto-added to
304
+ `.gitignore`). If you wire this into a scheduled CI job on a public
305
+ repo, that data lands in your build logs, so check your CI provider's
306
+ log visibility first.
307
+ - Flat-seat and per-seat billing tiers (Cursor plans without usage
308
+ overage, Claude.ai Team/Enterprise seats) don't expose true per-user
309
+ cost through the vendor's own Admin API. When teamspend sees a user
310
+ with real token or request activity but a reported cost of exactly $0,
311
+ it marks that user's number, and the whole report, as estimated rather
312
+ than showing a misleading exact-looking $0.
313
+ - Claude Code's Analytics API has no data before 2026-01-01. A window that
314
+ starts earlier raises `DataUnavailableError` and, if `--before-csv`/
315
+ `--after-csv` was passed, falls back to the CSV import path for that
316
+ side automatically.
317
+
318
+ ## Security
319
+
320
+ The three admin-API tools need org-admin-level credentials --
321
+ `TEAMSPEND_CURSOR_TOKEN` (Cursor Admin API), `TEAMSPEND_CLAUDE_CODE_TOKEN`
322
+ (Anthropic's Claude Enterprise Analytics API), and/or
323
+ `TEAMSPEND_COPILOT_TOKEN` + `TEAMSPEND_COPILOT_ORG` (GitHub Copilot usage
324
+ metrics API) -- read only from environment variables via `os.environ.get()` in
325
+ `cli.py`'s `_fetch_tool()`. Neither is ever hardcoded, persisted to disk,
326
+ or included in the JSON report or terminal output. A 401/403 from either
327
+ vendor's API raises `AuthenticationError` naming which environment
328
+ variable to check; the credential value itself never appears in that
329
+ message, a log line, or a traceback. `opencode`, `codex`, and
330
+ `claude-code-personal` need no credential at all -- they read local
331
+ files only, never a network call.
332
+
333
+ The one other untrusted input this package reads is an imported CSV file
334
+ (`--before-csv`/`--after-csv`): `adapters/csv_import.py` strips C0
335
+ control characters (`\x00`-`\x1f`) from every cell before it can reach
336
+ the terminal summary, closing a terminal/ANSI-escape-injection path a
337
+ crafted `user_email` or `cost_usd` cell could otherwise open. Nothing
338
+ read from an API response or a CSV file is ever passed to `eval`, `exec`,
339
+ or a shell -- both adapters and the CSV importer only parse and validate
340
+ (`require_field` in `http_client.py` raises `SchemaDriftError` rather
341
+ than guessing when a vendor field is missing).
342
+
343
+ The JSON report file (`teamspend-snapshot-*.json`) contains real per-user
344
+ emails and dollar amounts, so `output.py` writes it with `0600`
345
+ (owner-read/write-only) permissions via `os.open(..., O_CREAT |
346
+ O_WRONLY, 0o600)` -- avoiding the umask-then-chmod race a separate
347
+ `chmod` call after write would leave open -- and the CLI auto-scaffolds a
348
+ `.gitignore` entry for that file pattern on first run.
349
+
350
+ **What's out of scope**: the accuracy of a vendor's own admin-API
351
+ response (a wrong number from Cursor's or Anthropic's API is a report for
352
+ that vendor, not teamspend), and findings that assume a credential has
353
+ already been put somewhere insecure by the user (a committed `.env` file,
354
+ a world-readable shell history) -- teamspend reads credentials only from
355
+ environment variables it does not set or persist itself.
356
+
357
+ To report a vulnerability, use
358
+ [GitHub Security Advisories](https://github.com/RudrenduPaul/teamspend/security/advisories/new)
359
+ rather than a public issue -- see
360
+ [SECURITY.md](https://github.com/RudrenduPaul/teamspend/blob/main/SECURITY.md)
361
+ for the full policy and response timeline. **Honest note**: this project
362
+ does not currently publish SLSA provenance, Sigstore signatures, or an
363
+ SBOM, and has no OpenSSF Scorecard badge set up -- none of that
364
+ infrastructure exists yet for either distribution, so it isn't claimed
365
+ here. Both distributions have zero runtime dependencies (this package
366
+ uses only `urllib` from the standard library), so there is no
367
+ third-party HTTP client to audit in the request path.
368
+
369
+ ## Development
370
+
371
+ ```bash
372
+ cd python
373
+ python3 -m venv .venv && source .venv/bin/activate
374
+ pip install -e ".[dev]"
375
+ pytest
376
+ ```
377
+
378
+ Source lives under `python/src/teamspend/`, laid out to mirror the
379
+ TypeScript module structure 1:1 (`adapters/`, `compare.py`, `output.py`,
380
+ `cli.py`, `types.py`, `errors.py`, `http_client.py`) so a change in one
381
+ codebase has an obvious counterpart to check in the other. See
382
+ [CONTRIBUTING.md](https://github.com/RudrenduPaul/teamspend/blob/main/CONTRIBUTING.md).
383
+
384
+ ## License
385
+
386
+ Apache 2.0.