supercompact 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/cli.js +616 -0
- package/dist/dialogue.js +93 -0
- package/dist/estimate.js +217 -0
- package/dist/keep.js +76 -0
- package/dist/measure.js +204 -0
- package/dist/preview.js +163 -0
- package/dist/rewrite.js +342 -0
- package/dist/store.js +261 -0
- package/dist/transcript.js +182 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adam Albastov
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
```
|
|
2
|
+
███████╗██╗ ██╗██████╗ ███████╗██████╗
|
|
3
|
+
██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗
|
|
4
|
+
███████╗██║ ██║██████╔╝█████╗ ██████╔╝
|
|
5
|
+
╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗
|
|
6
|
+
███████║╚██████╔╝██║ ███████╗██║ ██║
|
|
7
|
+
╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
|
|
8
|
+
██████╗ ██████╗ ███╗ ███╗██████╗ █████╗ ██████╗████████╗
|
|
9
|
+
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝╚══██╔══╝
|
|
10
|
+
██║ ██║ ██║██╔████╔██║██████╔╝███████║██║ ██║
|
|
11
|
+
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██║
|
|
12
|
+
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║ ██║╚██████╗ ██║
|
|
13
|
+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
|
|
14
|
+
|
|
15
|
+
╭────────────────────────────────────────────────────────────────╮
|
|
16
|
+
│ a4abe3a1 274k tokens before supercompact │
|
|
17
|
+
├────────────────────────────────────────────────────────────────┤
|
|
18
|
+
│ tool traffic ████████████████████ 68% │
|
|
19
|
+
│ starting context ██████ 21% │
|
|
20
|
+
│ you and Claude ███ 11% │
|
|
21
|
+
╰────────────────────────────────────────────────────────────────╯
|
|
22
|
+
│
|
|
23
|
+
▼
|
|
24
|
+
╭────────────────────────────────────────────────────────────────╮
|
|
25
|
+
│ a4abe3a1 87k tokens same id, same resume │
|
|
26
|
+
│ every message kept character for character · no model used │
|
|
27
|
+
╰────────────────────────────────────────────────────────────────╯
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
[](https://www.npmjs.com/package/supercompact)
|
|
31
|
+
[](https://github.com/SignedAdam/supercompact/actions/workflows/check.yml)
|
|
32
|
+
[](https://nodejs.org)
|
|
33
|
+
[](package.json)
|
|
34
|
+
[](LICENSE)
|
|
35
|
+
|
|
36
|
+
Up to 95% of the tokens in a heavy Claude Code session are tool traffic. `supercompact` strips that traffic out of the transcript on disk and gives you back the context window.
|
|
37
|
+
|
|
38
|
+
Every human message stays. Every assistant response stays. There is no model summarising your conversation and no loss of detail. You keep everything you agreed on, lose the machine's scratch work, and resume the session right where you left off.
|
|
39
|
+
|
|
40
|
+
Run this first. It reads your local sessions, calculates the token split across your history, and writes nothing:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx supercompact measure
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
3289 sessions, 365.5M tokens of context
|
|
48
|
+
|
|
49
|
+
removed 229.3M 63% ████████████████··········
|
|
50
|
+
starting context 112.3M 31% ████████··················
|
|
51
|
+
kept verbatim 24.0M 7% ██························
|
|
52
|
+
|
|
53
|
+
removed is tool calls and their results.
|
|
54
|
+
starting context is your MCP tools, skills, CLAUDE.md files and so on.
|
|
55
|
+
kept verbatim is every message you and Claude sent.
|
|
56
|
+
|
|
57
|
+
your last 3 sessions
|
|
58
|
+
|
|
59
|
+
session now after starting removed
|
|
60
|
+
a4abe3a1-d4e9-4c99-823d-2d7d947564ce 274k 87k 58k 68%
|
|
61
|
+
a8feeb50-76ad-424d-b150-df1e9185373d 998k 613k 49k 39%
|
|
62
|
+
0f729543-99e5-4e56-8d31-ef3bcd0a2b47 563k 179k 51k 68%
|
|
63
|
+
|
|
64
|
+
after is what the session weighs once it has been supercompacted.
|
|
65
|
+
|
|
66
|
+
Your newest session starts with 58k already loaded. (You should fix this btw)
|
|
67
|
+
|
|
68
|
+
436 of your sessions passed 200k tokens. The middle one drops by 87%.
|
|
69
|
+
Your heaviest session held 1.0M tokens. 3k of it was the two of you talking.
|
|
70
|
+
|
|
71
|
+
Context sizes are the numbers the API reported on each turn, not an estimate.
|
|
72
|
+
The keep options hold some tool results back, and the preview prices them.
|
|
73
|
+
|
|
74
|
+
Try it on this machine: npx supercompact --preview
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Never throw away a session
|
|
78
|
+
|
|
79
|
+
Tool traffic is almost everything in a Claude Code transcript. Files read, shell commands, test runs, and build logs account for up to 95 percent of the variable tokens in a working session. The actual conversation is a fraction of the file.
|
|
80
|
+
|
|
81
|
+
When a session gets heavy, the standard move is to abandon it and start over. You throw away the history, re-explain the architecture from scratch, and waste time catching the agent back up.
|
|
82
|
+
|
|
83
|
+
I built this so sessions never have to die. When you strip the tool noise, the session stops being disposable. You keep the agreements, the architectural decisions, and the conclusions the agent reached. The evidence is gone, but the context stays.
|
|
84
|
+
|
|
85
|
+
## How this differs from `/compact`
|
|
86
|
+
|
|
87
|
+
Claude Code has a built-in `/compact` command. That command sends your conversation to a model and asks for a summary. The original wording is replaced with a paraphrase, and detail is lost.
|
|
88
|
+
|
|
89
|
+
`supercompact` does not use a model. It executes a direct rewrite of the JSONL session file on disk. Every human message and every assistant response stays character for character.
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
92
|
+
|
|
93
|
+
Install globally or run it with `npx`.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npm install -g supercompact
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
By default, `supercompact` creates a new session file and leaves your original transcript untouched:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
supercompact
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
kept 724 messages from you and 774 from Claude
|
|
107
|
+
was 3.4 MB, 233 tool calls
|
|
108
|
+
now 1.3 MB, about 180k tokens
|
|
109
|
+
|
|
110
|
+
new session 1f4df052-7cea-4af3-97fc-e990d7dd707c
|
|
111
|
+
resume it cd '/Users/sauel/dev/agents' && claude --resume 1f4df052-7cea-4af3-97fc-e990d7dd707c
|
|
112
|
+
|
|
113
|
+
0f729543 was not touched.
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To rewrite the current session under its existing ID and name:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
supercompact --in-place
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`--in-place` writes a full backup copy of the original file before modifying anything. It also leaves the trailing entries alone so an active turn continues working.
|
|
123
|
+
|
|
124
|
+
Claude Code loads transcripts when it starts up. It does not monitor the file for changes while running. Resume the session to load the stripped state:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
claude --resume <id>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
To check the token reduction without writing anything:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
supercompact --preview
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Reference
|
|
137
|
+
|
|
138
|
+
### Commands
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
supercompact copy the current session, stripped
|
|
142
|
+
supercompact <id> copy that session
|
|
143
|
+
supercompact --in-place rewrite it, same id and name
|
|
144
|
+
supercompact --preview token cost, writes nothing
|
|
145
|
+
supercompact measure the split across all your sessions
|
|
146
|
+
supercompact list recent sessions
|
|
147
|
+
supercompact help show the help
|
|
148
|
+
supercompact version print the version
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Options
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
--tools keep one line per tool call and drop the output
|
|
155
|
+
--keep-last N keep the newest N messages unchanged
|
|
156
|
+
--keep-tools N keep the newest N tool results
|
|
157
|
+
--unique-tools with --keep-tools, repeated identical calls count once
|
|
158
|
+
--preview print the token savings without writing any files
|
|
159
|
+
--in-place rewrite the session file instead of making a copy
|
|
160
|
+
--json output machine-readable JSON
|
|
161
|
+
--limit N number of sessions to display with list
|
|
162
|
+
--project-dir P look in project directory P instead of current directory
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`<id>` is the first few characters of a session id, which `list` prints.
|
|
166
|
+
|
|
167
|
+
## Inside Claude Code
|
|
168
|
+
|
|
169
|
+
The repo includes a slash command and an agent skill under `agent/`. To install them:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
cp agent/commands/supercompact.md ~/.claude/commands/
|
|
173
|
+
cp -r agent/skills/supercompact ~/.claude/skills/
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Run `/supercompact` inside a session to shrink the active transcript in place:
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
/supercompact [tools] [keep N] [preview]
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- `tools` keeps the tool call names and removes the output.
|
|
183
|
+
- `keep 10` leaves the last 10 messages unchanged.
|
|
184
|
+
- `preview` calculates the savings without writing anything.
|
|
185
|
+
- `copy` writes a new session instead of modifying the active file.
|
|
186
|
+
|
|
187
|
+
The skill lets Claude Code measure its own transcript and strip tool traffic autonomously when asked.
|
|
188
|
+
|
|
189
|
+
## Details
|
|
190
|
+
|
|
191
|
+
- Node.js 18 or higher. Tested on Node 18 and 22 in CI.
|
|
192
|
+
- Zero runtime dependencies.
|
|
193
|
+
- 48 tests run against throwaway session trees in CI on macOS and Ubuntu.
|
|
194
|
+
- Windows is untested.
|
|
195
|
+
- MIT license. Author Adam Albastov. Source code on [GitHub](https://github.com/SignedAdam/supercompact).
|