lakonai 0.15.0 → 0.16.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/README.md +88 -357
- package/bin/lakonai.js +168 -24
- package/package.json +1 -1
- package/src/hooks/version-check.js +1 -1
- package/src/install/index.js +52 -10
- package/src/mem-compress.js +29 -19
- package/src/mem-llm.js +22 -11
- package/src/output-bench.js +92 -0
- package/src/rules/lakonai.md +11 -11
- package/src/update-prompt.js +20 -0
- package/src/upgrade.js +34 -0
package/README.md
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
<h1 align="center">lakonai</h1>
|
|
6
6
|
|
|
7
|
-
<
|
|
8
|
-
<strong>Cut LLM tokens by up to 94% — without losing a single identifier.</strong>
|
|
9
|
-
</p>
|
|
7
|
+
<h3 align="center">Speak less. Ship more.</h3>
|
|
10
8
|
|
|
11
9
|
<p align="center">
|
|
12
|
-
<
|
|
10
|
+
<strong>Cut LLM tokens by up to 94% - without losing a single identifier.</strong>
|
|
13
11
|
</p>
|
|
14
12
|
|
|
13
|
+
<p align="center"><em>Spartan replies for AI agents.</em></p>
|
|
14
|
+
|
|
15
15
|
<p align="center">
|
|
16
16
|
<a href="https://www.npmjs.com/package/lakonai"><img src="https://img.shields.io/npm/v/lakonai?color=0F0F0F&label=npm" alt="npm" /></a>
|
|
17
17
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0F0F0F" alt="MIT" /></a>
|
|
@@ -22,68 +22,38 @@
|
|
|
22
22
|
|
|
23
23
|
<p align="center">
|
|
24
24
|
One install. <strong>Four fronts</strong> of token waste, closed at once:<br/>
|
|
25
|
-
<strong>what the model writes</strong> · <strong>what your shell dumps in</strong> · <strong>what
|
|
26
|
-
|
|
27
|
-
and shrinks your <strong>CLAUDE.md</strong> with a local AI CLI — <strong>no API key</strong>. Learns new filters the more you use it.<br/>
|
|
28
|
-
Works across <strong>Claude Code, Codex, Cursor, Windsurf, Cline, Gemini CLI</strong>.
|
|
25
|
+
<strong>what the model writes</strong> · <strong>what your shell dumps in</strong> · <strong>what it reads</strong> · <strong>the catalogs & memory loaded every session</strong>.<br/>
|
|
26
|
+
Works across <strong>Claude Code, Codex, Cursor, Windsurf, Cline, Gemini CLI</strong> - no API key.
|
|
29
27
|
</p>
|
|
30
28
|
|
|
31
29
|
---
|
|
32
30
|
|
|
33
|
-
##
|
|
31
|
+
## Savings, measured
|
|
34
32
|
|
|
35
|
-
| Command
|
|
36
|
-
|
|
|
37
|
-
| `git log -p -10`
|
|
38
|
-
| `ls -laR` (deep
|
|
39
|
-
| `
|
|
40
|
-
| `git
|
|
41
|
-
| `
|
|
42
|
-
| `npm test` (passing suite) | 4,451 | 358 | **-92%** |
|
|
43
|
-
| `Read pnpm-lock.yaml` | ~56,000 | **blocked** | **-95%** |
|
|
44
|
-
| `Grep` (auto `head_limit`) | unbounded | 30 matches | **capped** |
|
|
33
|
+
| Command | Raw tokens | Filtered | Saved |
|
|
34
|
+
| --------------------- | ---------: | ----------: | -------: |
|
|
35
|
+
| `git log -p -10` | 10,497 | 78 | **-94%** |
|
|
36
|
+
| `ls -laR` (deep dir) | 23,624 | 117 | **-94%** |
|
|
37
|
+
| `npm test` (passing) | 4,451 | 358 | **-92%** |
|
|
38
|
+
| `git diff HEAD~5` | 13,230 | 798 | **-89%** |
|
|
39
|
+
| `Read pnpm-lock.yaml` | ~56,000 | **blocked** | **-95%** |
|
|
45
40
|
|
|
46
|
-
Conservative
|
|
41
|
+
Conservative - peaks go higher. `lakonai gain` shows your own.
|
|
47
42
|
|
|
48
43
|
---
|
|
49
44
|
|
|
50
|
-
##
|
|
51
|
-
|
|
52
|
-
In 346 BC, Philip II of Macedon — father of Alexander the Great — sent the Spartans a message:
|
|
53
|
-
|
|
54
|
-
> _"If I invade Lakonía, I will raze your cities to the ground."_
|
|
55
|
-
|
|
56
|
-
The Spartans replied with a single word:
|
|
57
|
-
|
|
58
|
-
> _"If."_
|
|
59
|
-
|
|
60
|
-
That region was **Lakonía**. Its people gave the English language the word **laconic** — using as few words as possible. They didn't waste breath, didn't waste arrows, didn't waste anything.
|
|
61
|
-
|
|
62
|
-
Your AI coding agent does. It opens with _"Sure! I'd be happy to help…"_, repeats your question back, and explains what the diff already shows. It reads `git log` in full when one line per commit would do. Every wasted token is a soldier you didn't need to send.
|
|
63
|
-
|
|
64
|
-
**lakonai trims both sides.**
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## Four fronts. One install.
|
|
69
|
-
|
|
70
|
-
| Front | Wasted tokens look like… | lakonai fixes it by… |
|
|
71
|
-
| ---------------------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
72
|
-
| **Output** (the model) | _"Great question! Let me explain…"_ | Installing a terse-response rule. No preamble, no recap, no restating. |
|
|
73
|
-
| **Input** (your shell tools) | `git log` dumping 1.8 k tokens of author metadata | Wrapping **30 commands** — `git`/`ls`/`grep`/`cat`/`find`, **test runners** (jest/pytest/go/cargo), **lint/build** (tsc/eslint/ruff/make), **docker/kubectl/aws** — and compressing before context. |
|
|
74
|
-
| **Reads** (file ingestion) | Agent runs `Read` on `pnpm-lock.yaml` → 80 k of nothing | A `PreToolUse` hook on `Read` blocks lockfiles & `node_modules`, caps files >800 lines. |
|
|
75
|
-
| **Search** (Grep tool) | `Grep` returns 800 matches and you re-read every one | A `PreToolUse` hook on `Grep` auto-caps `head_limit` at 30 with a one-shot hint. |
|
|
76
|
-
| **Context** (every session) | MCP tool catalogs + your `CLAUDE.md`, re-paid every single session | **Auto-compressing MCP catalogs** on install; **opt-in `compress-memory`** for your memory files. |
|
|
77
|
-
| **Analysis** (the rule) | `Read` 5k of logs to count errors in your head | "Think in code" — write `node -e '…filter…count'`, consume only the answer. |
|
|
78
|
-
|
|
79
|
-
Most tools stop at one front. lakonai works all four transparently — your agent doesn't have to remember anything.
|
|
45
|
+
## What it does - four fronts
|
|
80
46
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
47
|
+
| Front | Wasted tokens look like… | lakonai fixes it by… |
|
|
48
|
+
| --------------------------- | --------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
49
|
+
| **Output** (the model) | _"Great question! Let me explain…"_ | A terse-response rule - no preamble, no recap. |
|
|
50
|
+
| **Input** (your shell) | `git log` dumping 1.8k tokens of metadata | Filtering **30 commands** (git/ls/grep/tests/lint/docker…) before they hit context. |
|
|
51
|
+
| **Reads** (files) | `Read pnpm-lock.yaml` → 80k of nothing | A hook that blocks lockfiles/`node_modules`, caps huge files, and caps `Grep`. |
|
|
52
|
+
| **Context** (every session) | MCP catalogs + your `CLAUDE.md`, re-paid every turn | Auto-compressing MCP catalogs; opt-in `compress-memory`. |
|
|
85
53
|
|
|
86
|
-
|
|
54
|
+
Most tools stop at one front. lakonai works all four - and **gets better the more
|
|
55
|
+
you use it**: it auto-learns new heavy commands and turns on a safe filter for them,
|
|
56
|
+
no config. ([full reference →](docs/reference.md))
|
|
87
57
|
|
|
88
58
|
---
|
|
89
59
|
|
|
@@ -91,350 +61,111 @@ Most tools stop at one front. lakonai works all four transparently — your agen
|
|
|
91
61
|
|
|
92
62
|
```bash
|
|
93
63
|
npm install -g lakonai
|
|
94
|
-
lakonai install
|
|
64
|
+
lakonai install # global agents (Claude Code / Codex / Gemini)
|
|
65
|
+
lakonai install --here # + per-project rules (Cursor / Windsurf / Cline)
|
|
95
66
|
```
|
|
96
67
|
|
|
97
|
-
That's it
|
|
98
|
-
|
|
99
|
-
Working inside a repo and want **per-project** rules (Cursor, Windsurf, Cline)? Add `--here`:
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
cd path/to/your/repo
|
|
103
|
-
lakonai install --here # globals + per-project rules in this dir
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
From the next session forward your agent:
|
|
107
|
-
|
|
108
|
-
1. **Responds tersely** — no preamble, no restating, no recap. (rule in `CLAUDE.md` / equivalent)
|
|
109
|
-
2. **Has its `Bash` calls auto-rewritten** — `PreToolUse` hook intercepts `git`/`ls`/`cat`/`grep`/etc and prefixes them with `lakonai` transparently.
|
|
110
|
-
3. **Has its `Read` calls guarded** — a second hook denies `node_modules/`, lockfiles, and build artifacts (with a hint to `grep` instead), and auto-caps reads over 800 lines.
|
|
111
|
-
4. **Has its `Grep` calls capped** — a third hook auto-sets `head_limit` to 30 if you didn't, with a once-per-session hint to use `output_mode:"count"` for tallies.
|
|
112
|
-
5. **Is told to "think in code"** — for any count/filter/parse task, the rule pushes the agent toward a one-shot `node -e` (or `awk`) script that consumes the data so the agent consumes only the answer.
|
|
113
|
-
6. **Logs per-turn LLM token usage** — a `Stop` hook records `input_tokens` / `output_tokens` / `cache_read` after each model turn so `lakonai gain` shows model-side savings alongside shell-side savings.
|
|
114
|
-
7. **Tells you about new versions** — a `SessionStart` hook checks npm once per day and surfaces a `lakonai X.Y.Z available` notice inside the session (opt-out: `LAKON_NO_UPDATE_CHECK=1`).
|
|
115
|
-
8. **Auto-compresses MCP tool catalogs** — if you have MCP servers in `~/.claude.json`, install transparently wraps each stdio server so its tool/prompt/resource **descriptions** are compressed before they hit context (offline; backed up; reverted on `uninstall`; opt-out `LAKON_NO_MCP=1`). Requests and tool-call results are never touched.
|
|
116
|
-
|
|
117
|
-
You'll see savings stack up immediately in `lakonai gain`.
|
|
118
|
-
|
|
119
|
-
### Make shell filtering automatic on _every_ agent (`lakonai shim`)
|
|
120
|
-
|
|
121
|
-
The hooks above are Claude-Code-only — they're the only platform whose hook API
|
|
122
|
-
can transparently rewrite a tool call. To get **automatic** shell-output
|
|
123
|
-
filtering on Codex, Cursor, Windsurf, Cline and Gemini CLI too, run:
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
lakonai shim # prepend ~/.lakon/shim to PATH; lakonai shim --off to undo
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
This drops tiny executable wrappers for `ls`/`grep`/`rg`/`ag`/`find`/`cat`/`tree`/`head`
|
|
130
|
-
into `~/.lakon/shim/` and prepends that dir to your shell's PATH. Now **any** agent
|
|
131
|
-
that runs one of those commands through a shell gets its output filtered through
|
|
132
|
-
lakonai — no hook API, no model cooperation. `git` is deliberately excluded (its
|
|
133
|
-
subcommands open editors / stream), and the wrappers only shadow read-only,
|
|
134
|
-
single-shot commands so they can never break an interactive invocation.
|
|
135
|
-
|
|
136
|
-
It's **opt-in** because it edits your shell rc (`.zshrc`/`.bashrc`) and shadows
|
|
137
|
-
system commands on PATH. Caveat: it only reaches agents that inherit your shell's
|
|
138
|
-
PATH (terminal-launched CLIs do; some GUI apps with their own environment may not).
|
|
139
|
-
|
|
140
|
-
### Compress a memory file (opt-in)
|
|
68
|
+
That's it - from the next session your agent is terse, its shell output filtered,
|
|
69
|
+
junk reads blocked, and MCP catalogs compressed. Watch it in `lakonai gain`.
|
|
141
70
|
|
|
142
|
-
|
|
71
|
+
Two extras worth knowing:
|
|
143
72
|
|
|
144
|
-
|
|
73
|
+
- **`lakonai shim`** - makes shell filtering automatic on **every** agent (not just
|
|
74
|
+
Claude Code) by routing `ls`/`grep`/`find`/… through lakonai at the PATH level.
|
|
75
|
+
- **`lakonai compress-memory CLAUDE.md`** - shrinks your memory file with a **local
|
|
76
|
+
AI CLI you already have, no API key** (backed up, validated byte-for-byte).
|
|
145
77
|
|
|
146
|
-
|
|
147
|
-
| -------------- | ----------- | ----------------- |
|
|
148
|
-
| `claude` | Claude Code | `claude --print` |
|
|
149
|
-
| `gemini` | Gemini CLI | `gemini -p` |
|
|
150
|
-
| `codex` | Codex | `codex exec -` |
|
|
151
|
-
| `cursor-agent` | Cursor | `cursor-agent -p` |
|
|
78
|
+
---
|
|
152
79
|
|
|
153
|
-
|
|
80
|
+
## Output savings: improvements on top of improvements
|
|
154
81
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
lakonai revert-memory CLAUDE.md # restore from the backup
|
|
158
|
-
```
|
|
82
|
+
How much does the rule cut the model's output? We measured the **same rule, same
|
|
83
|
+
prompt** against two baselines:
|
|
159
84
|
|
|
160
|
-
|
|
85
|
+
| The model lakonai is layered on… | …and the rule cuts | |
|
|
86
|
+
| ------------------------------------------- | :----------------: | ---------------------------------------------- |
|
|
87
|
+
| a **raw, verbose** model (Gemini default) | **~70%** | as strong as any terse-prompt tool |
|
|
88
|
+
| **Claude Code** - already concise by design | **~10% more** | the hard case: trimming what's already trimmed |
|
|
161
89
|
|
|
162
|
-
|
|
90
|
+
_361 → 107 tokens on the verbose baseline; 240 → 216 on Claude Code. Same rule -
|
|
91
|
+
the only variable is how much fat the model started with._
|
|
163
92
|
|
|
164
|
-
|
|
93
|
+
Anyone can cut the obvious fat (~70% off a rambling API). lakonai's edge is the
|
|
94
|
+
**hard** case: point it at an agent that's _already_ optimized for brevity and it
|
|
95
|
+
**still finds another ~10%** - stacked on top of filtered shell output, blocked
|
|
96
|
+
reads, and compressed catalogs. **Improvements on top of improvements.**
|
|
165
97
|
|
|
166
|
-
>
|
|
167
|
-
|
|
168
|
-
---
|
|
169
|
-
|
|
170
|
-
## Use the filter directly
|
|
171
|
-
|
|
172
|
-
The CLI works as a standalone tool too. Run any shell command through `lakonai` to filter its output:
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
lakonai git status # compressed git status
|
|
176
|
-
lakonai git log -50 # one line per commit (hash + subject)
|
|
177
|
-
lakonai git diff # only +/- lines, no noise
|
|
178
|
-
lakonai ls -la # size + name only
|
|
179
|
-
lakonai grep -r foo src/ # truncates at 15 matches
|
|
180
|
-
lakonai npm test # passing suite collapses to its summary line
|
|
181
|
-
lakonai find . -name '*.ts' # groups matches by directory
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
Unsupported commands run unchanged.
|
|
98
|
+
> `lakonai gain` shows the honest **~10% marginal** number - what you actually save
|
|
99
|
+
> on _your_ already-concise agent, not an inflated raw-baseline headline.
|
|
185
100
|
|
|
186
101
|
---
|
|
187
102
|
|
|
188
103
|
## See your savings
|
|
189
104
|
|
|
190
|
-
```bash
|
|
191
|
-
lakonai gain
|
|
192
105
|
```
|
|
193
|
-
|
|
194
|
-
```
|
|
195
|
-
lakonai — saved 161.8k tok (67% smaller) across 2104 commands
|
|
106
|
+
lakonai - saved 161.8k tok (67% smaller) across 2104 commands
|
|
196
107
|
|
|
197
108
|
today 6.7k tok saved (68%)
|
|
198
109
|
this week 36.4k tok saved (67%)
|
|
199
110
|
|
|
200
|
-
top: git 124.3k
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
Simple and objective: one headline number, today/this-week, and your top commands.
|
|
204
|
-
Before you have any data, `gain` shows a sample benchmark so you see what the
|
|
205
|
-
filters do. Set `LAKON_COLOR=1`/`0` (or `NO_COLOR=1`) to force/disable ANSI colors.
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## Commands
|
|
210
|
-
|
|
211
|
-
After `lakonai install`, everything is automatic — you rarely need anything but
|
|
212
|
-
`gain` (to see the savings) and `doctor` (to check it's active).
|
|
213
|
-
|
|
214
|
-
| Command | What it does |
|
|
215
|
-
| --------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
216
|
-
| `lakonai install [--here] [--only <p>]` | Install rule + hooks (globals by default; `--here` adds per-project) |
|
|
217
|
-
| `lakonai uninstall` | Strip the lakonai block from each config (keeps your other content) |
|
|
218
|
-
| `lakonai revert [--only <p>]` | Restore each config to its pre-install state from backup |
|
|
219
|
-
| `lakonai backups` | Show backup history per platform |
|
|
220
|
-
| `lakonai shim [--off]` | Enable/disable the universal PATH shim — automatic shell filtering on _every_ agent |
|
|
221
|
-
| `lakonai compress-memory <file>` | Shrink an authored memory file with your local agent CLI (opt-in, backed up, validated) |
|
|
222
|
-
| `lakonai revert-memory <file>` | Restore a memory file from its `.original.md` backup |
|
|
223
|
-
| `lakonai gain` | Show savings by window + top commands (and a sample benchmark before you have data) |
|
|
224
|
-
| `lakonai doctor` | Per-platform health: CLI on PATH, rule installed, hooks registered |
|
|
225
|
-
| `lakonai <cmd> [args]` | (internal) Run a command, filter its output, track savings |
|
|
226
|
-
| `lakonai version` / `--version` / `-v` | Print the installed lakonai version |
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
|
-
## Supported filters
|
|
231
|
-
|
|
232
|
-
| Command | What it does |
|
|
233
|
-
| -------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
234
|
-
| `git log` | One line per commit (`<hash> <subject>`), capped at 50 |
|
|
235
|
-
| `git status` | Drops hint paragraphs, separates changed vs untracked |
|
|
236
|
-
| `git diff` / `show` | Only `+`/`-`/`@@` lines, drops `index`/`---`/`+++`, cap 120 lines |
|
|
237
|
-
| `ls -la` / `tree` | `<size>\t<name>` (drops perms / dates / link targets), cap 60 |
|
|
238
|
-
| `cat` | Collapses blank-line runs, cap 200 lines |
|
|
239
|
-
| `head` / `tail` | Cap 50 lines |
|
|
240
|
-
| `grep` / `rg` / `ag` | Cap 15 matches with "tighten the pattern" hint |
|
|
241
|
-
| `find` | Groups matched paths by directory, drops permission-denied noise |
|
|
242
|
-
| test runners | jest/vitest/mocha/pytest/ava, `npm/pnpm/yarn/bun test`, `go test`, `cargo test` — collapse passes, keep failures + summary |
|
|
243
|
-
| lint / build | `tsc`, `eslint`, `ruff`, `cargo clippy`, `make` — strip noise, "ok" when clean |
|
|
244
|
-
| pkg / cloud | `npm/pnpm/yarn/bun install`, `diff`, `docker`, `kubectl`, `aws` — strip progress/noise, cap |
|
|
245
|
-
|
|
246
|
-
The last three groups are powered by a declarative engine (`src/filters/defs.js`)
|
|
247
|
-
plus a couple of structured filters; adding a new command is usually one data entry.
|
|
248
|
-
|
|
249
|
-
Unsupported commands run unchanged (passthrough), still tracked at 0 % savings.
|
|
250
|
-
|
|
251
|
-
### Gets better the more you use it (auto-learning)
|
|
252
|
-
|
|
253
|
-
lakonai watches your session history (the Claude Code transcript) and, when an
|
|
254
|
-
**unfiltered** command keeps showing up with heavy output, it **enables a
|
|
255
|
-
conservative filter for it automatically** — no config, no manual rules. The
|
|
256
|
-
auto-filter is near-lossless (collapses repeated/blank lines, truncates only
|
|
257
|
-
with an announced marker) so it never hides a real error. Disable with
|
|
258
|
-
`LAKON_NO_LEARN=1`.
|
|
111
|
+
top: git 124.3k · ls 18.2k · grep 12.0k
|
|
259
112
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
The `Read` hook automatically:
|
|
263
|
-
|
|
264
|
-
- **Denies** paths under `node_modules/`, `vendor/`, `dist/`, `build/`, `target/`, `.next/`, `.nuxt/`, `.turbo/`, `.svelte-kit/`, `.parcel-cache/`, `.vercel/`, `coverage/`, `__pycache__/`, `.venv/`, `.git/objects/`, `__snapshots__/`, `.ipynb_checkpoints/`, `.mypy_cache/`, `.pytest_cache/`, `.ruff_cache/`, `.tox/`, `cypress/screenshots/`, `cypress/videos/`, `playwright-report/`, `test-results/`, `.idea/`, `.vscode/`, `tmp/`
|
|
265
|
-
- **Denies** lockfiles (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `Cargo.lock`, `go.sum`, `*.lock`)
|
|
266
|
-
- **Denies** build artifacts (`*.min.js`, `*.min.css`, `*.min.mjs`, `*.tsbuildinfo`, `*.map`, `*.log`, `*.pyc`, `*.pyo`, `*.so`, `*.o`, `*.a`, `*.dylib`, `*.dll`, `*.exe`, `*.class`, `*.wasm`)
|
|
267
|
-
- **Caps** files over 800 lines at 800 (with hint to `Read` again with `offset` for more, or `grep -n` for the symbol you need)
|
|
268
|
-
|
|
269
|
-
Each deny returns a one-line reason the model reads, so it knows to `grep -n` the symbol instead.
|
|
270
|
-
|
|
271
|
-
### Grep tool guard (Claude Code)
|
|
272
|
-
|
|
273
|
-
The `Grep` hook auto-sets `head_limit` to **30** when the agent didn't pass one. First call per 4-hour window includes a one-line hint suggesting `output_mode:"count"` for tallies; subsequent calls cap silently.
|
|
274
|
-
|
|
275
|
-
### Session output tracking (Claude Code)
|
|
276
|
-
|
|
277
|
-
A `Stop` hook fires at the end of every model turn, reads the latest `usage` block from the transcript, and appends a `cmd: "session"` entry to the log with `input_tokens`, `output_tokens`, `cache_read_input_tokens`, and `cache_creation_input_tokens`.
|
|
278
|
-
|
|
279
|
-
`lakonai gain` renders these in a separate **session output** block (see example above) — so you can watch model-side verbosity drop and cache-hit ratios climb over time. Top commands list excludes session entries; they're not shell calls.
|
|
280
|
-
|
|
281
|
-
### Update notifications (Claude Code)
|
|
282
|
-
|
|
283
|
-
A `SessionStart` hook checks `registry.npmjs.org/lakonai/latest` at most once per 24 hours (cached at `~/.lakon/version.json`) and, if a newer version exists, emits a `hookSpecificOutput.additionalContext` that surfaces inside the Claude session:
|
|
284
|
-
|
|
285
|
-
```
|
|
286
|
-
lakonai 0.8.0 available (you have 0.7.0). Update: npm i -g lakonai@latest
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
Outside Claude, `lakonai gain` and `lakonai version` print the same notice on stderr (yellow when TTY).
|
|
290
|
-
|
|
291
|
-
**Opt out:** `LAKON_NO_UPDATE_CHECK=1`.
|
|
292
|
-
**Test endpoint:** `LAKON_REGISTRY_URL=http://localhost:8080/` (overrides the npm URL for local testing).
|
|
293
|
-
|
|
294
|
-
### Multi-profile Claude Code
|
|
295
|
-
|
|
296
|
-
If you use wrapper aliases like `claude-my=CLAUDE_CONFIG_DIR=$HOME/.claude-my claude` (e.g. one profile per Anthropic account or org), set the same env var when running `lakonai install` so hooks and the rule file land in the right config dir:
|
|
297
|
-
|
|
298
|
-
```bash
|
|
299
|
-
CLAUDE_CONFIG_DIR=$HOME/.claude-my lakonai install
|
|
300
|
-
CLAUDE_CONFIG_DIR=$HOME/.claude-company lakonai install
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
Each profile gets its own independent install. `lakonai uninstall` / `lakonai revert` respect the same env var.
|
|
304
|
-
|
|
305
|
-
---
|
|
306
|
-
|
|
307
|
-
## Supported AI agents
|
|
308
|
-
|
|
309
|
-
| Agent | Scope | What `lakonai install` writes |
|
|
310
|
-
| ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
311
|
-
| Claude Code¹ | global | Rule block in `~/.claude/CLAUDE.md` + **five** hooks in `~/.claude/settings.json` (`PreToolUse`: Bash rewrite + Read guard + Grep guard; `Stop`: session-usage log + auto-learning; `SessionStart`: update notify) + `/lakonai:gain` slash command |
|
|
312
|
-
| Codex CLI | global | Rule block in `~/.codex/AGENTS.md` |
|
|
313
|
-
| Gemini CLI | global | Rule block in `~/.gemini/GEMINI.md` |
|
|
314
|
-
| Cursor | project² | `.cursor/rules/lakonai.mdc` in the current dir |
|
|
315
|
-
| Windsurf | project² | `.windsurf/rules/lakonai.md` in the current dir |
|
|
316
|
-
| Cline | project² | `.clinerules/lakonai.md` in the current dir |
|
|
317
|
-
|
|
318
|
-
### What each agent actually gets (honest capability matrix)
|
|
319
|
-
|
|
320
|
-
Once you run `lakonai shim` (see above), the **shell-mediated** features are
|
|
321
|
-
automatic on every agent — they work at the PATH level, no hook API and no model
|
|
322
|
-
cooperation needed. **Shell filtering** routes every wrapped command through
|
|
323
|
-
lakonai, and the **Read-guard** refuses junk reads done via the shell
|
|
324
|
-
(`cat pnpm-lock.yaml`, `head node_modules/…`). What the shim *can't* see is an
|
|
325
|
-
agent's own non-shell Read tool and its full command stream — guarding that tool
|
|
326
|
-
and auto-learning need a call-rewriting hook, which today only Claude Code
|
|
327
|
-
exposes. Honest matrix:
|
|
328
|
-
|
|
329
|
-
| Agent | Terse rule | Shell filter | Read/Grep guard | Auto-learning |
|
|
330
|
-
| ----------- | :--------: | -------------------- | --------------------- | --------------- |
|
|
331
|
-
| Claude Code | ✅ | ✅ automatic (hook) | ✅ tool + shell | ✅ transcript+log |
|
|
332
|
-
| Codex CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
333
|
-
| Cursor | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
334
|
-
| Windsurf | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
335
|
-
| Cline | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
336
|
-
| Gemini CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
|
|
337
|
-
|
|
338
|
-
Run `lakonai doctor` to see, per platform, what's actually active on your machine.
|
|
339
|
-
The only thing **not** automatic everywhere is guarding the agent's *own non-shell
|
|
340
|
-
Read tool* — that needs a call-rewriting hook, which today only Claude Code exposes
|
|
341
|
-
(see ²).
|
|
342
|
-
|
|
343
|
-
¹ `lakonai shim` prepends `~/.lakon/shim` to PATH so `ls`/`grep`/`rg`/`ag`/`find`/`cat`/`tree`/`head` filter automatically for any agent that runs them through a shell (opt-in — it edits your shell rc; `git` is excluded for safety). Without it, those commands filter only when the model prefixes `lakonai` itself.
|
|
344
|
-
² The shim refuses junk reads (lockfiles, `node_modules/…`, build artifacts) done through the shell with `cat`/`head`/`tail`/`less` — same deny rules as the Claude Read hook. An agent's *own* internal Read tool (not via the shell) still needs a hook, so capping/blocking it is automatic only on Claude Code. Codex's hook [can't yet rewrite a tool call](https://github.com/openai/codex/issues/18491); Cursor's can deny but not cap; Gemini's `BeforeTool` could (installer planned, pending schema validation against the real CLI).
|
|
345
|
-
³ Auto-learning runs off `~/.lakon/log.jsonl`, which every `lakonai` call (shim wrappers + rule-prefixed commands) appends to on any agent — so it promotes new heavy commands automatically everywhere, throttled hourly. Claude Code additionally learns from the full session transcript (a wider window). Disable with `LAKON_NO_LEARN=1`.
|
|
346
|
-
|
|
347
|
-
¹ "Claude Code" covers **every** Claude Code frontend — terminal CLI, VS Code extension, JetBrains plugin, desktop app. All read the same `~/.claude/CLAUDE.md` + `~/.claude/settings.json`, so one install lights up all of them.
|
|
348
|
-
|
|
349
|
-
² Project-scoped tools only read rules from the current directory, so `lakonai install` skips them by default to avoid scattering files across your repos. Add `--here` (or use `--project`) when you actually want them in the current dir.
|
|
350
|
-
|
|
351
|
-
Each install is **idempotent** (rerunning replaces the existing block) and **reversible** (`uninstall` strips it, `revert` restores from backup).
|
|
352
|
-
|
|
353
|
-
---
|
|
354
|
-
|
|
355
|
-
## Backup & revert
|
|
356
|
-
|
|
357
|
-
Before writing to your config file for the first time, `lakonai` copies it into `~/.lakon/backups/<platform>/<filename>.<timestamp>.bak`. Every install thereafter appends another snapshot to that file's manifest.
|
|
358
|
-
|
|
359
|
-
```bash
|
|
360
|
-
lakonai uninstall # strips just the lakonai block; keeps your other CLAUDE.md content
|
|
361
|
-
lakonai revert # restores the file to its pre-install state, byte for byte
|
|
362
|
-
lakonai backups # shows every snapshot, per platform, with timestamps
|
|
113
|
+
output (terse rule): ~10% fewer tokens vs your agent's baseline
|
|
363
114
|
```
|
|
364
115
|
|
|
365
|
-
|
|
116
|
+
Input is measured & deterministic; output is measured by your local AI CLI (no key,
|
|
117
|
+
weekly, at a TTY only). Both sides, one number.
|
|
366
118
|
|
|
367
119
|
---
|
|
368
120
|
|
|
369
|
-
##
|
|
370
|
-
|
|
371
|
-
Every filtered command appends a JSON line to `~/.lakon/log.jsonl`. The `Stop` hook appends one line per model turn with token counts (`cmd: "session"`). `lakonai gain` reads that log and shows a simple headline + per-window + top-commands summary.
|
|
372
|
-
|
|
373
|
-
The log stores: timestamp, command name, first few args, raw/filtered token counts (shell entries); timestamp, session id, `input_tokens` / `output_tokens` / `cache_read` / `cache_create` (session entries). **No file contents. No full arguments. No transcript content. No data ever leaves your machine** — except the one daily HEAD request to `registry.npmjs.org` for the update check (opt-out: `LAKON_NO_UPDATE_CHECK=1`).
|
|
374
|
-
|
|
375
|
-
Override the location with `LAKON_HOME=/path`. Disable per-command logging with `LAKON_NO_TRACK=1`.
|
|
376
|
-
|
|
377
|
-
> Note: env vars and the data dir keep the historical `LAKON_*` / `~/.lakon/` names so existing installs keep their logs and backups intact. New installs land there too.
|
|
378
|
-
|
|
379
|
-
---
|
|
121
|
+
## Commands
|
|
380
122
|
|
|
381
|
-
|
|
123
|
+
| Command | What it does |
|
|
124
|
+
| --------------------------------------------------------- | -------------------------------------------------------------- |
|
|
125
|
+
| `lakonai install [--here]` | Install rule + hooks (globals; `--here` adds per-project) |
|
|
126
|
+
| `lakonai upgrade` | Update to the latest version + refresh the rule block |
|
|
127
|
+
| `lakonai uninstall` / `revert` | Strip the lakonai block / restore from backup |
|
|
128
|
+
| `lakonai shim [--off]` | Universal PATH shim - automatic shell filtering on every agent |
|
|
129
|
+
| `lakonai compress-memory <file>` / `revert-memory <file>` | Shrink a memory file via your local AI CLI / undo |
|
|
130
|
+
| `lakonai gain` | Token savings - input (measured) and output (estimated) |
|
|
131
|
+
| `lakonai doctor` | Per-platform health: CLI on PATH, rule, hooks |
|
|
382
132
|
|
|
383
|
-
|
|
384
|
-
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
385
|
-
| `LAKON_HOME` | Where to keep the log + backups + version cache (default `~/.lakon`) |
|
|
386
|
-
| `LAKON_NO_TRACK` | Set to `1` to disable per-command logging |
|
|
387
|
-
| `LAKON_NO_UPDATE_CHECK` | Set to `1` to disable the `SessionStart` npm check + terminal hint |
|
|
388
|
-
| `LAKON_REGISTRY_URL` | Override the npm registry URL used by the update check (testing) |
|
|
389
|
-
| `LAKON_COLOR` | `1` forces ANSI colors in `lakonai gain`; `0` disables; unset = TTY auto-detect |
|
|
390
|
-
| `NO_COLOR` | Standard. Disables ANSI colors when set to any non-empty value. |
|
|
391
|
-
| `CLAUDE_CONFIG_DIR` | When set during `lakonai install` / `uninstall`, hooks + rule land in that dir instead of `~/.claude/`. Used for multi-profile setups. |
|
|
133
|
+
Full flags, filters, env vars and internals: **[docs/reference.md](docs/reference.md)**.
|
|
392
134
|
|
|
393
135
|
---
|
|
394
136
|
|
|
395
|
-
##
|
|
137
|
+
## Agents - what each one gets
|
|
396
138
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
139
|
+
| Agent | Installs | Shell filter | Read/Grep guard | Auto-learn |
|
|
140
|
+
| ------------------------- | ---------------------------------------------------- | :----------: | :-------------: | :--------: |
|
|
141
|
+
| Claude Code | `~/.claude/CLAUDE.md` + 5 hooks + MCP compress | ✅ hook | ✅ tool + shell | ✅ |
|
|
142
|
+
| Codex / Gemini | rule in `~/.codex/AGENTS.md` · `~/.gemini/GEMINI.md` | ✅ shim | ✅ shell reads | ✅ |
|
|
143
|
+
| Cursor / Windsurf / Cline | per-project rule (`--here`) | ✅ shim | ✅ shell reads | ✅ |
|
|
400
144
|
|
|
401
|
-
|
|
145
|
+
Hooks are Claude-Code-only (the only platform with a call-rewriting hook API);
|
|
146
|
+
everywhere else `lakonai shim` makes the shell-mediated features automatic. The one
|
|
147
|
+
thing not universal is guarding an agent's **own non-shell Read tool** - see the
|
|
148
|
+
[honest matrix](docs/reference.md#capability-matrix-per-agent). Every install is
|
|
149
|
+
idempotent and reversible (`uninstall`/`revert`, backups first).
|
|
402
150
|
|
|
403
151
|
---
|
|
404
152
|
|
|
405
|
-
##
|
|
153
|
+
## Why "lakonai"
|
|
406
154
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
npm install # only devDeps (jest for tests/coverage); zero runtime deps
|
|
411
|
-
npm test # run the Jest suite
|
|
412
|
-
npm run test:coverage # text + HTML coverage report (coverage/index.html)
|
|
413
|
-
npm run test:coverage:check # enforce the coverage threshold
|
|
414
|
-
node bin/lakonai.js --help
|
|
415
|
-
```
|
|
155
|
+
In 346 BC, Philip II of Macedon warned Sparta: _"If I invade Lakonía, I will raze
|
|
156
|
+
your cities."_ The Spartans replied with one word: _"If."_ Their region, **Lakonía**,
|
|
157
|
+
gave English the word **laconic** - using as few words as possible.
|
|
416
158
|
|
|
417
|
-
|
|
159
|
+
Your AI agent isn't laconic. It opens with _"Sure! I'd be happy to help…"_, repeats
|
|
160
|
+
your question, and reads `git log` in full. lakonai trims both sides.
|
|
418
161
|
|
|
419
162
|
---
|
|
420
163
|
|
|
421
164
|
## Credits
|
|
422
165
|
|
|
423
|
-
Built on ideas from
|
|
424
|
-
|
|
425
|
-
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
lakonai condenses both into one zero-dependency npm package with a single install command, automatic backups, and time-windowed savings tracking.
|
|
429
|
-
|
|
430
|
-
---
|
|
431
|
-
|
|
432
|
-
## License
|
|
166
|
+
Built on ideas from [**caveman**](https://github.com/juliusbrussee/caveman) (terse
|
|
167
|
+
rule + auto-clarity) and [**rtk**](https://github.com/rtk-ai/rtk) (CLI output
|
|
168
|
+
filtering) - condensed into one zero-dependency package with automatic backups and
|
|
169
|
+
savings tracking.
|
|
433
170
|
|
|
434
|
-
MIT
|
|
435
|
-
|
|
436
|
-
---
|
|
437
|
-
|
|
438
|
-
<p align="center">
|
|
439
|
-
<sub>Speak less. Ship more.</sub>
|
|
440
|
-
</p>
|
|
171
|
+
MIT - see [LICENSE](LICENSE).
|