sessioncost 0.2.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kish21
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ prune tests
2
+ prune build
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: sessioncost
3
+ Version: 0.2.0
4
+ Summary: See how many tokens each turn of your coding-agent chat sends, why, and what to cut. Cost goes down with it.
5
+ Author: kish21
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/kish21/sessioncost
8
+ Keywords: claude-code,codex,cursor,antigravity,tokens,cost
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Environment :: Console
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # SessionCost
17
+
18
+ See how many tokens each turn of your coding-agent chat sends, why, and what to cut.
19
+
20
+ Every message you send makes the agent send the whole conversation again, plus its setup, plus whatever it read.
21
+ Type `/sessioncost` in a chat and see, for each of your messages, how many tokens went out and what they were, the
22
+ heaviest turn, and the fixes that would have sent fewer, measured from that chat. Fewer tokens is what makes an agent
23
+ cheaper and faster, so the cost is shown too, as the result. It works in **Claude Code, Codex, Cursor and Antigravity**,
24
+ runs on your computer, and sends nothing anywhere.
25
+
26
+ ## Get it
27
+
28
+ **Using Claude Code?** Type these two lines in a Claude Code chat:
29
+
30
+ ```
31
+ /plugin marketplace add kish21/sessioncost
32
+ /plugin install sessioncost@sessioncost
33
+ ```
34
+
35
+ (Or in the editor: **Manage Plugins → Marketplaces**, add `kish21/sessioncost`, then install **sessioncost** from
36
+ the **Plugins** tab.) This needs Python 3.10 or newer on your computer. If you have none, `/sessioncost` says so and
37
+ gives you the line below.
38
+
39
+ **Using Codex, Cursor or Antigravity (or Claude Code without Python)?** Paste one line in a terminal:
40
+
41
+ | Your computer | Paste this |
42
+ |---|---|
43
+ | Windows (PowerShell) | `irm https://raw.githubusercontent.com/kish21/sessioncost/main/install.ps1 \| iex` |
44
+ | macOS or Linux | `curl -fsSL https://raw.githubusercontent.com/kish21/sessioncost/main/install.sh \| sh` |
45
+
46
+ It installs SessionCost (bringing its own Python if your computer has none, via [uv](https://docs.astral.sh/uv/)),
47
+ then adds `/sessioncost` to every agent you have. Run the same line again to update.
48
+
49
+ **Then:** restart your agent and type `/sessioncost` in any chat.
50
+
51
+ ## What you get
52
+
53
+ A short summary in the chat:
54
+
55
+ ```
56
+ SessionCost: Add a CSV export to the reports page
57
+ 1.9M tokens sent, 24k written · 5 turns · 31 calls · 22 min working, 6.0 min waiting for you
58
+ Heaviest turn: #3 “now add tests” · 910k tokens sent (48%) · $1.12
59
+ Top fix: Turn off tools this session never used · 420k fewer tokens sent · saves $0.214 (measured from this session)
60
+ Cost: $2.31 exact (API prices 2026-10-08)
61
+ Report: ~/.sessioncost/reports/<session-id>.html
62
+ ```
63
+
64
+ (The numbers above are an example.) Say yes when it offers to open the report: a page in your browser with
65
+
66
+ - **Turn by turn**: one row per thing you asked, with the tokens it sent and wrote, its calls and minutes, and its
67
+ cost. Click a turn to see its calls, and a call to see what it sent (fixed setup, carried history, new input) and
68
+ what it wrote. Every set of parts adds up to the number above it.
69
+ - **Replay**: step or play through the chat call by call and watch the context grow.
70
+ - **Where the tokens went**: by kind of step (reading, running commands, writing files, helpers...) and by kind of
71
+ token.
72
+ - **What to fix**: the fixes that apply to this chat, each with the tokens it would cut and the money that saves.
73
+ - **Sent with every call**: the agent's fixed setup, and which tools were never used.
74
+
75
+ Asking costs almost nothing: the agent runs the tool and shows its summary, and never reads the log or the report
76
+ into the chat.
77
+
78
+ ## If something goes wrong
79
+
80
+ - **`/sessioncost` does nothing:** restart the agent after installing.
81
+ - **"Python is not found" with the Claude Code plugin:** paste the one line for your computer from above.
82
+ - **Windows says running scripts is disabled:** run the line as
83
+ `powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/kish21/sessioncost/main/install.ps1 | iex"`.
84
+ - **Already have Python and prefer pip:** `pip install https://github.com/kish21/sessioncost/archive/refs/heads/main.zip`,
85
+ then `python -m sessioncost setup`.
86
+
87
+ ## Which agents, and how exact
88
+
89
+ | Agent | Where its log is | Tokens |
90
+ |---|---|---|
91
+ | Claude Code | `~/.claude/projects/<project>/<session>.jsonl` | exact, from the log |
92
+ | Codex (CLI, IDE, app) | `~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl` | exact, from the log |
93
+ | Antigravity | `~/.gemini/antigravity-ide/conversations/<id>.db` | exact, from the log |
94
+ | Cursor | Cursor's `User/globalStorage/state.vscdb` | **estimated** from text size; exact with your usage export |
95
+
96
+ Cursor keeps no token counts on your computer. SessionCost rebuilds each call from the chat's messages, estimates
97
+ its size from the text (characters / 4), and scales it so the last call matches the context size Cursor itself
98
+ recorded. For exact numbers, download your usage export from the Cursor dashboard and pass it with
99
+ `--cursor-usage file.csv`.
100
+
101
+ ## From a terminal
102
+
103
+ After the one-line install, `sessioncost` also works in a terminal, from your project folder, and costs zero tokens:
104
+
105
+ ```
106
+ sessioncost # the newest chat of this folder's project (same as: sessioncost last)
107
+ sessioncost list # recent chats: date, id, cost, turns, calls, first message
108
+ sessioncost 3f2a9c1e # one chat, by the first characters of its id
109
+ sessioncost path/to/session.jsonl # or an Antigravity .db
110
+ sessioncost 3f2a9c1e --cursor-usage usage-events.csv # a Cursor chat, with exact tokens from your export
111
+ sessioncost setup # add /sessioncost to your agents again
112
+ ```
113
+
114
+ Options: `--project <dir>` (another project folder), `--no-open` (write the report, do not open it), `--json`
115
+ (print the full model as JSON), `--prices <file>`, `--subscription` (see below), `--cursor-usage <file.csv>`.
116
+
117
+ `last` and `list` look at every agent above for the project folder. `last` picks the chat whose **last logged
118
+ message** is newest, not the newest file: reopening an old chat touches its file but does not make it the latest.
119
+
120
+ ## Privacy
121
+
122
+ Local only. SessionCost reads log files on your disk and writes one HTML file to `~/.sessioncost/reports/`. It
123
+ sends nothing anywhere, calls no AI model and needs no network. The report page loads a web font from Google Fonts
124
+ when you are online and falls back to system fonts when you are not.
125
+
126
+ ## How money is labelled
127
+
128
+ Every token class is priced on its own: new input, input written to the cache (5-minute and 1-hour rates differ),
129
+ input re-read from the cache, and output (the model's writing, hidden thinking included). Each model call is
130
+ counted once, even though the log writes one reply as several rows.
131
+
132
+ - **exact (API prices as of <date>)**: every model in the session has a checked rate in the price table. The
133
+ figure is what the same tokens cost on the public API on that date.
134
+ - **estimate**: at least one model has no checked rate (the OpenAI and Gemini rates are from third-party price
135
+ lists, not yet checked against the providers' own pages), or the tokens themselves are estimated (Cursor without
136
+ its usage export).
137
+ - **API-equivalent**: with `--subscription`, and always for Antigravity. On a plan that is not billed per token
138
+ (Claude Pro or Max, a ChatGPT plan, Antigravity) the figure is what the same work would cost at API prices.
139
+
140
+ When the log carries the agent's own running total (Claude Code), or you give Cursor's usage export with its cost
141
+ column, the report shows it as a cross-check.
142
+
143
+ Prices live in `sessioncost/prices.json` (USD per million tokens). Override any model in
144
+ `~/.sessioncost/prices.json` (merged over the built-in table) or pass `--prices <file>`.
145
+
146
+ Sizes the log does not give directly (how much of a call's input was the fixed setup, how much of its output was a
147
+ file rather than a message) are estimated from the text (characters / 4) and scaled so the parts add up exactly to
148
+ the token counts in the log. They are marked "~ estimated" on the page.
149
+
150
+ ## The built-in fixes
151
+
152
+ Three simple checks. Each one shows the tokens it would cut and what they cost, in this session.
153
+
154
+ 1. **Tools never used, sent with every call.** Tool definitions travel with every model call. The saving is what
155
+ the unused ones cost across the session's calls.
156
+ 2. **The same unchanged file read again.** A read that returned exactly the same text as an earlier read in the
157
+ same chat. The saving is what that copy cost when it came in, plus on every later call that carried it.
158
+ 3. **A confirm-only stop.** You typed only "yes", "ok", "save" or "go" (or picked such an answer on a question
159
+ card), and the agent had stopped just to ask. The saving is the cost of re-sending the conversation to receive
160
+ that answer.
161
+
162
+ ## Roadmap
163
+
164
+ - Compare two sessions of the same task side by side.
165
+ - An optional fix engine with more checks.
166
+
167
+ _Status: early. MIT license._
@@ -0,0 +1,152 @@
1
+ # SessionCost
2
+
3
+ See how many tokens each turn of your coding-agent chat sends, why, and what to cut.
4
+
5
+ Every message you send makes the agent send the whole conversation again, plus its setup, plus whatever it read.
6
+ Type `/sessioncost` in a chat and see, for each of your messages, how many tokens went out and what they were, the
7
+ heaviest turn, and the fixes that would have sent fewer, measured from that chat. Fewer tokens is what makes an agent
8
+ cheaper and faster, so the cost is shown too, as the result. It works in **Claude Code, Codex, Cursor and Antigravity**,
9
+ runs on your computer, and sends nothing anywhere.
10
+
11
+ ## Get it
12
+
13
+ **Using Claude Code?** Type these two lines in a Claude Code chat:
14
+
15
+ ```
16
+ /plugin marketplace add kish21/sessioncost
17
+ /plugin install sessioncost@sessioncost
18
+ ```
19
+
20
+ (Or in the editor: **Manage Plugins → Marketplaces**, add `kish21/sessioncost`, then install **sessioncost** from
21
+ the **Plugins** tab.) This needs Python 3.10 or newer on your computer. If you have none, `/sessioncost` says so and
22
+ gives you the line below.
23
+
24
+ **Using Codex, Cursor or Antigravity (or Claude Code without Python)?** Paste one line in a terminal:
25
+
26
+ | Your computer | Paste this |
27
+ |---|---|
28
+ | Windows (PowerShell) | `irm https://raw.githubusercontent.com/kish21/sessioncost/main/install.ps1 \| iex` |
29
+ | macOS or Linux | `curl -fsSL https://raw.githubusercontent.com/kish21/sessioncost/main/install.sh \| sh` |
30
+
31
+ It installs SessionCost (bringing its own Python if your computer has none, via [uv](https://docs.astral.sh/uv/)),
32
+ then adds `/sessioncost` to every agent you have. Run the same line again to update.
33
+
34
+ **Then:** restart your agent and type `/sessioncost` in any chat.
35
+
36
+ ## What you get
37
+
38
+ A short summary in the chat:
39
+
40
+ ```
41
+ SessionCost: Add a CSV export to the reports page
42
+ 1.9M tokens sent, 24k written · 5 turns · 31 calls · 22 min working, 6.0 min waiting for you
43
+ Heaviest turn: #3 “now add tests” · 910k tokens sent (48%) · $1.12
44
+ Top fix: Turn off tools this session never used · 420k fewer tokens sent · saves $0.214 (measured from this session)
45
+ Cost: $2.31 exact (API prices 2026-10-08)
46
+ Report: ~/.sessioncost/reports/<session-id>.html
47
+ ```
48
+
49
+ (The numbers above are an example.) Say yes when it offers to open the report: a page in your browser with
50
+
51
+ - **Turn by turn**: one row per thing you asked, with the tokens it sent and wrote, its calls and minutes, and its
52
+ cost. Click a turn to see its calls, and a call to see what it sent (fixed setup, carried history, new input) and
53
+ what it wrote. Every set of parts adds up to the number above it.
54
+ - **Replay**: step or play through the chat call by call and watch the context grow.
55
+ - **Where the tokens went**: by kind of step (reading, running commands, writing files, helpers...) and by kind of
56
+ token.
57
+ - **What to fix**: the fixes that apply to this chat, each with the tokens it would cut and the money that saves.
58
+ - **Sent with every call**: the agent's fixed setup, and which tools were never used.
59
+
60
+ Asking costs almost nothing: the agent runs the tool and shows its summary, and never reads the log or the report
61
+ into the chat.
62
+
63
+ ## If something goes wrong
64
+
65
+ - **`/sessioncost` does nothing:** restart the agent after installing.
66
+ - **"Python is not found" with the Claude Code plugin:** paste the one line for your computer from above.
67
+ - **Windows says running scripts is disabled:** run the line as
68
+ `powershell -ExecutionPolicy ByPass -c "irm https://raw.githubusercontent.com/kish21/sessioncost/main/install.ps1 | iex"`.
69
+ - **Already have Python and prefer pip:** `pip install https://github.com/kish21/sessioncost/archive/refs/heads/main.zip`,
70
+ then `python -m sessioncost setup`.
71
+
72
+ ## Which agents, and how exact
73
+
74
+ | Agent | Where its log is | Tokens |
75
+ |---|---|---|
76
+ | Claude Code | `~/.claude/projects/<project>/<session>.jsonl` | exact, from the log |
77
+ | Codex (CLI, IDE, app) | `~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl` | exact, from the log |
78
+ | Antigravity | `~/.gemini/antigravity-ide/conversations/<id>.db` | exact, from the log |
79
+ | Cursor | Cursor's `User/globalStorage/state.vscdb` | **estimated** from text size; exact with your usage export |
80
+
81
+ Cursor keeps no token counts on your computer. SessionCost rebuilds each call from the chat's messages, estimates
82
+ its size from the text (characters / 4), and scales it so the last call matches the context size Cursor itself
83
+ recorded. For exact numbers, download your usage export from the Cursor dashboard and pass it with
84
+ `--cursor-usage file.csv`.
85
+
86
+ ## From a terminal
87
+
88
+ After the one-line install, `sessioncost` also works in a terminal, from your project folder, and costs zero tokens:
89
+
90
+ ```
91
+ sessioncost # the newest chat of this folder's project (same as: sessioncost last)
92
+ sessioncost list # recent chats: date, id, cost, turns, calls, first message
93
+ sessioncost 3f2a9c1e # one chat, by the first characters of its id
94
+ sessioncost path/to/session.jsonl # or an Antigravity .db
95
+ sessioncost 3f2a9c1e --cursor-usage usage-events.csv # a Cursor chat, with exact tokens from your export
96
+ sessioncost setup # add /sessioncost to your agents again
97
+ ```
98
+
99
+ Options: `--project <dir>` (another project folder), `--no-open` (write the report, do not open it), `--json`
100
+ (print the full model as JSON), `--prices <file>`, `--subscription` (see below), `--cursor-usage <file.csv>`.
101
+
102
+ `last` and `list` look at every agent above for the project folder. `last` picks the chat whose **last logged
103
+ message** is newest, not the newest file: reopening an old chat touches its file but does not make it the latest.
104
+
105
+ ## Privacy
106
+
107
+ Local only. SessionCost reads log files on your disk and writes one HTML file to `~/.sessioncost/reports/`. It
108
+ sends nothing anywhere, calls no AI model and needs no network. The report page loads a web font from Google Fonts
109
+ when you are online and falls back to system fonts when you are not.
110
+
111
+ ## How money is labelled
112
+
113
+ Every token class is priced on its own: new input, input written to the cache (5-minute and 1-hour rates differ),
114
+ input re-read from the cache, and output (the model's writing, hidden thinking included). Each model call is
115
+ counted once, even though the log writes one reply as several rows.
116
+
117
+ - **exact (API prices as of <date>)**: every model in the session has a checked rate in the price table. The
118
+ figure is what the same tokens cost on the public API on that date.
119
+ - **estimate**: at least one model has no checked rate (the OpenAI and Gemini rates are from third-party price
120
+ lists, not yet checked against the providers' own pages), or the tokens themselves are estimated (Cursor without
121
+ its usage export).
122
+ - **API-equivalent**: with `--subscription`, and always for Antigravity. On a plan that is not billed per token
123
+ (Claude Pro or Max, a ChatGPT plan, Antigravity) the figure is what the same work would cost at API prices.
124
+
125
+ When the log carries the agent's own running total (Claude Code), or you give Cursor's usage export with its cost
126
+ column, the report shows it as a cross-check.
127
+
128
+ Prices live in `sessioncost/prices.json` (USD per million tokens). Override any model in
129
+ `~/.sessioncost/prices.json` (merged over the built-in table) or pass `--prices <file>`.
130
+
131
+ Sizes the log does not give directly (how much of a call's input was the fixed setup, how much of its output was a
132
+ file rather than a message) are estimated from the text (characters / 4) and scaled so the parts add up exactly to
133
+ the token counts in the log. They are marked "~ estimated" on the page.
134
+
135
+ ## The built-in fixes
136
+
137
+ Three simple checks. Each one shows the tokens it would cut and what they cost, in this session.
138
+
139
+ 1. **Tools never used, sent with every call.** Tool definitions travel with every model call. The saving is what
140
+ the unused ones cost across the session's calls.
141
+ 2. **The same unchanged file read again.** A read that returned exactly the same text as an earlier read in the
142
+ same chat. The saving is what that copy cost when it came in, plus on every later call that carried it.
143
+ 3. **A confirm-only stop.** You typed only "yes", "ok", "save" or "go" (or picked such an answer on a question
144
+ card), and the agent had stopped just to ask. The saving is the cost of re-sending the conversation to receive
145
+ that answer.
146
+
147
+ ## Roadmap
148
+
149
+ - Compare two sessions of the same task side by side.
150
+ - An optional fix engine with more checks.
151
+
152
+ _Status: early. MIT license._
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sessioncost"
7
+ version = "0.2.0"
8
+ description = "See how many tokens each turn of your coding-agent chat sends, why, and what to cut. Cost goes down with it."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ dependencies = []
13
+ authors = [{ name = "kish21" }]
14
+ keywords = ["claude-code", "codex", "cursor", "antigravity", "tokens", "cost"]
15
+ classifiers = ["Programming Language :: Python :: 3", "Environment :: Console"]
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/kish21/sessioncost"
19
+
20
+ [project.scripts]
21
+ sessioncost = "sessioncost.cli:main"
22
+
23
+ [tool.setuptools]
24
+ packages = ["sessioncost", "sessioncost.readers"]
25
+
26
+ [tool.setuptools.package-data]
27
+ sessioncost = ["prices.json", "report_template.html", "skill/SKILL.md"]
@@ -0,0 +1,2 @@
1
+ """SessionCost: see where every token of your agent session went, turn by turn, and what to fix."""
2
+ __version__ = "0.2.0"
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())