lakonai 0.15.1 → 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 CHANGED
@@ -4,15 +4,13 @@
4
4
 
5
5
  <h1 align="center">lakonai</h1>
6
6
 
7
- <p align="center">
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
- <em>Spartan replies for AI agents.</em>
10
+ <strong>Cut LLM tokens by up to 94% - without losing a single identifier.</strong>
13
11
  </p>
14
12
 
15
- <h3 align="center">Speak less. Ship more.</h3>
13
+ <p align="center"><em>Spartan replies for AI agents.</em></p>
16
14
 
17
15
  <p align="center">
18
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>
@@ -24,68 +22,38 @@
24
22
 
25
23
  <p align="center">
26
24
  One install. <strong>Four fronts</strong> of token waste, closed at once:<br/>
27
- <strong>what the model writes</strong> · <strong>what your shell dumps in</strong> · <strong>what files it reads</strong> · <strong>the catalogs &amp; memory loaded every session</strong>.<br/>
28
- Filters <strong>30 commands</strong>, guards <code>Read</code>/<code>Grep</code>, compresses your <strong>MCP tool catalogs automatically</strong>,<br/>
29
- 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/>
30
- 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 &amp; memory loaded every session</strong>.<br/>
26
+ Works across <strong>Claude Code, Codex, Cursor, Windsurf, Cline, Gemini CLI</strong> - no API key.
31
27
  </p>
32
28
 
33
29
  ---
34
30
 
35
- ## At a glance — measured savings
31
+ ## Savings, measured
36
32
 
37
- | Command | Raw tokens | Filtered | Saved |
38
- | -------------------------- | ---------: | ----------: | ---------: |
39
- | `git log -p -10` | 10,497 | 78 | **-94%** |
40
- | `ls -laR` (deep directory) | 23,624 | 117 | **-94%** |
41
- | `git diff HEAD~5` | 13,230 | 798 | **-89%** |
42
- | `git log --stat -50` | 4,845 | 439 | **-86%** |
43
- | `git status` | 17 | 1 | **-89%** |
44
- | `npm test` (passing suite) | 4,451 | 358 | **-92%** |
45
- | `Read pnpm-lock.yaml` | ~56,000 | **blocked** | **-95%** |
46
- | `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%** |
47
40
 
48
- Conservative numbers — peaks go higher in practice. Run `lakonai gain` to see your own savings stack up.
41
+ Conservative - peaks go higher. `lakonai gain` shows your own.
49
42
 
50
43
  ---
51
44
 
52
- ## The story behind the name
53
-
54
- In 346 BC, Philip II of Macedon — father of Alexander the Great — sent the Spartans a message:
55
-
56
- > _"If I invade Lakonía, I will raze your cities to the ground."_
57
-
58
- The Spartans replied with a single word:
59
-
60
- > _"If."_
61
-
62
- 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.
63
-
64
- 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.
65
-
66
- **lakonai trims both sides.**
67
-
68
- ---
69
-
70
- ## Four fronts. One install.
71
-
72
- | Front | Wasted tokens look like… | lakonai fixes it by… |
73
- | ---------------------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
74
- | **Output** (the model) | _"Great question! Let me explain…"_ | Installing a terse-response rule. No preamble, no recap, no restating. |
75
- | **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. |
76
- | **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. |
77
- | **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. |
78
- | **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. |
79
- | **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. |
45
+ ## What it does - four fronts
80
46
 
81
- Most tools stop at one front. lakonai works all four transparently — your agent doesn't have to remember anything.
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`. |
82
53
 
83
- > **Two that are easy to miss:**
84
- >
85
- > - **MCP catalogs, compressed automatically.** Connect MCP servers and their tool/prompt/resource _descriptions_ load into context every session. On install, lakonai wraps each stdio server and shrinks those descriptions offline — no manual config (caveman's equivalent is hand-wired). Reversible; opt-out `LAKON_NO_MCP=1`.
86
- > - **Your `CLAUDE.md`, compressed on command — no API key.** `lakonai compress-memory CLAUDE.md` rewrites your memory file using **a local AI CLI you already have** (`claude`/`gemini`/`codex`/`cursor-agent`). Backs up first, validates every code span / path / URL survives byte-for-byte. _(new in 0.12.0)_
87
-
88
- > **★ It gets better the more you use it.** lakonai watches your session history and, when an unfiltered command keeps showing up with heavy output, it **turns on a safe filter for that command automatically** — no config, no manual rules. Similar tools only _report_ what you're missing; lakonai just fixes it. (Near-lossless: it collapses repetition and truncates with a marker, never silently dropping a line that could be an error. Opt out with `LAKON_NO_LEARN=1`.)
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))
89
57
 
90
58
  ---
91
59
 
@@ -93,350 +61,111 @@ Most tools stop at one front. lakonai works all four transparently — your agen
93
61
 
94
62
  ```bash
95
63
  npm install -g lakonai
96
- lakonai install
97
- ```
98
-
99
- That's it. `lakonai install` configures your **global** agents — Claude Code, Codex, Gemini CLI — by writing rule blocks under `~/` only. It never touches your current directory by default.
100
-
101
- Working inside a repo and want **per-project** rules (Cursor, Windsurf, Cline)? Add `--here`:
102
-
103
- ```bash
104
- cd path/to/your/repo
105
- lakonai install --here # globals + per-project rules in this dir
64
+ lakonai install # global agents (Claude Code / Codex / Gemini)
65
+ lakonai install --here # + per-project rules (Cursor / Windsurf / Cline)
106
66
  ```
107
67
 
108
- From the next session forward your agent:
109
-
110
- 1. **Responds tersely** — no preamble, no restating, no recap. (rule in `CLAUDE.md` / equivalent)
111
- 2. **Has its `Bash` calls auto-rewritten** — `PreToolUse` hook intercepts `git`/`ls`/`cat`/`grep`/etc and prefixes them with `lakonai` transparently.
112
- 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.
113
- 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.
114
- 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.
115
- 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.
116
- 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`).
117
- 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.
118
-
119
- You'll see savings stack up immediately in `lakonai gain`.
120
-
121
- ### Make shell filtering automatic on _every_ agent (`lakonai shim`)
122
-
123
- The hooks above are Claude-Code-only — they're the only platform whose hook API
124
- can transparently rewrite a tool call. To get **automatic** shell-output
125
- filtering on Codex, Cursor, Windsurf, Cline and Gemini CLI too, run:
126
-
127
- ```bash
128
- lakonai shim # prepend ~/.lakon/shim to PATH; lakonai shim --off to undo
129
- ```
130
-
131
- This drops tiny executable wrappers for `ls`/`grep`/`rg`/`ag`/`find`/`cat`/`tree`/`head`
132
- into `~/.lakon/shim/` and prepends that dir to your shell's PATH. Now **any** agent
133
- that runs one of those commands through a shell gets its output filtered through
134
- lakonai — no hook API, no model cooperation. `git` is deliberately excluded (its
135
- subcommands open editors / stream), and the wrappers only shadow read-only,
136
- single-shot commands so they can never break an interactive invocation.
137
-
138
- It's **opt-in** because it edits your shell rc (`.zshrc`/`.bashrc`) and shadows
139
- system commands on PATH. Caveat: it only reaches agents that inherit your shell's
140
- PATH (terminal-launched CLIs do; some GUI apps with their own environment may not).
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
- ### Compress a memory file (opt-in)
71
+ Two extras worth knowing:
143
72
 
144
- Your `CLAUDE.md` (and other memory/notes) costs tokens **every session**. `lakonai compress-memory <file>` rewrites it tersely in place using **a local AI CLI you already have** — no API key to set up. A model rephrases and merges the prose (far higher savings than a regex pass — measured **~59%** on a verbose file, **~2%** on an already-terse one), while headings, tables, fenced code, inline code, paths and URLs are preserved byte-for-byte.
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
- It auto-detects, in order, whichever agent CLI is on your PATH:
147
-
148
- | CLI binary | Platform | Headless call |
149
- | -------------- | ----------- | ----------------- |
150
- | `claude` | Claude Code | `claude --print` |
151
- | `gemini` | Gemini CLI | `gemini -p` |
152
- | `codex` | Codex | `codex exec -` |
153
- | `cursor-agent` | Cursor | `cursor-agent -p` |
154
-
155
- (Windsurf and Cline ship no headless one-shot CLI, so on those you just use whichever of the above you also have. Force a specific one with `LAKONAI_MEM_CLI=gemini`; pick a model with `LAKONAI_MEM_MODEL`.)
156
-
157
- ```bash
158
- lakonai compress-memory CLAUDE.md # uses your local agent CLI; backup to CLAUDE.original.md
159
- lakonai revert-memory CLAUDE.md # restore from the backup
160
- ```
161
-
162
- Unlike the MCP catalog above, this is **always manual and opt-in** — it edits text you authored, so a `CLAUDE.original.md` backup is written first, the result is **validated** (aborts untouched if any code/path/URL would be lost; one auto-fix pass first), and nothing happens unless you ask. Sensitive-looking filenames (`.env`, `*api-key*`, …) are refused since their bytes cross the model boundary. `lakonai install` offers a one-time prompt to compress a detected `CLAUDE.md`; declining leaves it alone.
163
-
164
- > Hooks are currently Claude Code-only (the only platform with documented hook APIs). For Codex/Cursor/Windsurf/Cline/Gemini, the rule asks the model to grep-before-Read and use the `lakonai` prefix itself.
165
-
166
- > **Worried?** Every install backs up the target file first. `lakonai revert` puts it back byte-for-byte.
78
+ ---
167
79
 
168
- > **Upgrading from `lakon`?** The package was renamed to **lakonai** in 0.7.0; the legacy `lakon` / `lak` command aliases were since removed — use `lakonai`. Your `~/.lakon/` log + backups carry over untouched, and `lakonai install` rewrites your existing config block to the new brand.
80
+ ## Output savings: improvements on top of improvements
169
81
 
170
- ---
82
+ How much does the rule cut the model's output? We measured the **same rule, same
83
+ prompt** against two baselines:
171
84
 
172
- ## Use the filter directly
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 |
173
89
 
174
- The CLI works as a standalone tool too. Run any shell command through `lakonai` to filter its output:
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._
175
92
 
176
- ```bash
177
- lakonai git status # compressed git status
178
- lakonai git log -50 # one line per commit (hash + subject)
179
- lakonai git diff # only +/- lines, no noise
180
- lakonai ls -la # size + name only
181
- lakonai grep -r foo src/ # truncates at 15 matches
182
- lakonai npm test # passing suite collapses to its summary line
183
- lakonai find . -name '*.ts' # groups matches by directory
184
- ```
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.**
185
97
 
186
- 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.
187
100
 
188
101
  ---
189
102
 
190
103
  ## See your savings
191
104
 
192
- ```bash
193
- lakonai gain
194
- ```
195
-
196
105
  ```
197
- lakonai — saved 161.8k tok (67% smaller) across 2104 commands
106
+ lakonai - saved 161.8k tok (67% smaller) across 2104 commands
198
107
 
199
108
  today 6.7k tok saved (68%)
200
109
  this week 36.4k tok saved (67%)
201
110
 
202
- top: git 124.3k tok · ls 18.2k tok · grep 12.0k tok
203
- ```
204
-
205
- Simple and objective: one headline number, today/this-week, and your top commands.
206
- Before you have any data, `gain` shows a sample benchmark so you see what the
207
- filters do. Set `LAKON_COLOR=1`/`0` (or `NO_COLOR=1`) to force/disable ANSI colors.
208
-
209
- ---
210
-
211
- ## Commands
212
-
213
- After `lakonai install`, everything is automatic — you rarely need anything but
214
- `gain` (to see the savings) and `doctor` (to check it's active).
215
-
216
- | Command | What it does |
217
- | --------------------------------------- | ----------------------------------------------------------------------------------- |
218
- | `lakonai install [--here] [--only <p>]` | Install rule + hooks (globals by default; `--here` adds per-project) |
219
- | `lakonai uninstall` | Strip the lakonai block from each config (keeps your other content) |
220
- | `lakonai revert [--only <p>]` | Restore each config to its pre-install state from backup |
221
- | `lakonai backups` | Show backup history per platform |
222
- | `lakonai shim [--off]` | Enable/disable the universal PATH shim — automatic shell filtering on _every_ agent |
223
- | `lakonai compress-memory <file>` | Shrink an authored memory file with your local agent CLI (opt-in, backed up, validated) |
224
- | `lakonai revert-memory <file>` | Restore a memory file from its `.original.md` backup |
225
- | `lakonai gain` | Show savings by window + top commands (and a sample benchmark before you have data) |
226
- | `lakonai doctor` | Per-platform health: CLI on PATH, rule installed, hooks registered |
227
- | `lakonai <cmd> [args]` | (internal) Run a command, filter its output, track savings |
228
- | `lakonai version` / `--version` / `-v` | Print the installed lakonai version |
229
-
230
- ---
231
-
232
- ## Supported filters
233
-
234
- | Command | What it does |
235
- | -------------------- | -------------------------------------------------------------------------------------------------------------------------- |
236
- | `git log` | One line per commit (`<hash> <subject>`), capped at 50 |
237
- | `git status` | Drops hint paragraphs, separates changed vs untracked |
238
- | `git diff` / `show` | Only `+`/`-`/`@@` lines, drops `index`/`---`/`+++`, cap 120 lines |
239
- | `ls -la` / `tree` | `<size>\t<name>` (drops perms / dates / link targets), cap 60 |
240
- | `cat` | Collapses blank-line runs, cap 200 lines |
241
- | `head` / `tail` | Cap 50 lines |
242
- | `grep` / `rg` / `ag` | Cap 15 matches with "tighten the pattern" hint |
243
- | `find` | Groups matched paths by directory, drops permission-denied noise |
244
- | test runners | jest/vitest/mocha/pytest/ava, `npm/pnpm/yarn/bun test`, `go test`, `cargo test` — collapse passes, keep failures + summary |
245
- | lint / build | `tsc`, `eslint`, `ruff`, `cargo clippy`, `make` — strip noise, "ok" when clean |
246
- | pkg / cloud | `npm/pnpm/yarn/bun install`, `diff`, `docker`, `kubectl`, `aws` — strip progress/noise, cap |
247
-
248
- The last three groups are powered by a declarative engine (`src/filters/defs.js`)
249
- plus a couple of structured filters; adding a new command is usually one data entry.
250
-
251
- Unsupported commands run unchanged (passthrough), still tracked at 0 % savings.
252
-
253
- ### Gets better the more you use it (auto-learning)
111
+ top: git 124.3k · ls 18.2k · grep 12.0k
254
112
 
255
- lakonai watches your session history (the Claude Code transcript) and, when an
256
- **unfiltered** command keeps showing up with heavy output, it **enables a
257
- conservative filter for it automatically** — no config, no manual rules. The
258
- auto-filter is near-lossless (collapses repeated/blank lines, truncates only
259
- with an announced marker) so it never hides a real error. Disable with
260
- `LAKON_NO_LEARN=1`.
261
-
262
- ### Read tool guard (Claude Code)
263
-
264
- The `Read` hook automatically:
265
-
266
- - **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/`
267
- - **Denies** lockfiles (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `Cargo.lock`, `go.sum`, `*.lock`)
268
- - **Denies** build artifacts (`*.min.js`, `*.min.css`, `*.min.mjs`, `*.tsbuildinfo`, `*.map`, `*.log`, `*.pyc`, `*.pyo`, `*.so`, `*.o`, `*.a`, `*.dylib`, `*.dll`, `*.exe`, `*.class`, `*.wasm`)
269
- - **Caps** files over 800 lines at 800 (with hint to `Read` again with `offset` for more, or `grep -n` for the symbol you need)
270
-
271
- Each deny returns a one-line reason the model reads, so it knows to `grep -n` the symbol instead.
272
-
273
- ### Grep tool guard (Claude Code)
274
-
275
- 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.
276
-
277
- ### Session output tracking (Claude Code)
278
-
279
- 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`.
280
-
281
- `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.
282
-
283
- ### Update notifications (Claude Code)
284
-
285
- 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:
286
-
287
- ```
288
- lakonai 0.8.0 available (you have 0.7.0). Update: npm i -g lakonai@latest
289
- ```
290
-
291
- Outside Claude, `lakonai gain` and `lakonai version` print the same notice on stderr (yellow when TTY).
292
-
293
- **Opt out:** `LAKON_NO_UPDATE_CHECK=1`.
294
- **Test endpoint:** `LAKON_REGISTRY_URL=http://localhost:8080/` (overrides the npm URL for local testing).
295
-
296
- ### Multi-profile Claude Code
297
-
298
- 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:
299
-
300
- ```bash
301
- CLAUDE_CONFIG_DIR=$HOME/.claude-my lakonai install
302
- CLAUDE_CONFIG_DIR=$HOME/.claude-company lakonai install
113
+ output (terse rule): ~10% fewer tokens vs your agent's baseline
303
114
  ```
304
115
 
305
- Each profile gets its own independent install. `lakonai uninstall` / `lakonai revert` respect the same env var.
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.
306
118
 
307
119
  ---
308
120
 
309
- ## Supported AI agents
310
-
311
- | Agent | Scope | What `lakonai install` writes |
312
- | ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
313
- | 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 |
314
- | Codex CLI | global | Rule block in `~/.codex/AGENTS.md` |
315
- | Gemini CLI | global | Rule block in `~/.gemini/GEMINI.md` |
316
- | Cursor | project² | `.cursor/rules/lakonai.mdc` in the current dir |
317
- | Windsurf | project² | `.windsurf/rules/lakonai.md` in the current dir |
318
- | Cline | project² | `.clinerules/lakonai.md` in the current dir |
319
-
320
- ### What each agent actually gets (honest capability matrix)
321
-
322
- Once you run `lakonai shim` (see above), the **shell-mediated** features are
323
- automatic on every agent — they work at the PATH level, no hook API and no model
324
- cooperation needed. **Shell filtering** routes every wrapped command through
325
- lakonai, and the **Read-guard** refuses junk reads done via the shell
326
- (`cat pnpm-lock.yaml`, `head node_modules/…`). What the shim *can't* see is an
327
- agent's own non-shell Read tool and its full command stream — guarding that tool
328
- and auto-learning need a call-rewriting hook, which today only Claude Code
329
- exposes. Honest matrix:
330
-
331
- | Agent | Terse rule | Shell filter | Read/Grep guard | Auto-learning |
332
- | ----------- | :--------: | -------------------- | --------------------- | --------------- |
333
- | Claude Code | ✅ | ✅ automatic (hook) | ✅ tool + shell | ✅ transcript+log |
334
- | Codex CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
335
- | Cursor | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
336
- | Windsurf | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
337
- | Cline | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
338
- | Gemini CLI | ✅ | ✅ automatic (shim¹) | ✅ shell reads (shim²) | ✅ from log³ |
339
-
340
- Run `lakonai doctor` to see, per platform, what's actually active on your machine.
341
- The only thing **not** automatic everywhere is guarding the agent's *own non-shell
342
- Read tool* — that needs a call-rewriting hook, which today only Claude Code exposes
343
- (see ²).
344
-
345
- ¹ `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.
346
- ² 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).
347
- ³ 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`.
348
-
349
- ¹ "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.
350
-
351
- ² 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.
352
-
353
- Each install is **idempotent** (rerunning replaces the existing block) and **reversible** (`uninstall` strips it, `revert` restores from backup).
354
-
355
- ---
356
-
357
- ## Backup & revert
358
-
359
- 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.
360
-
361
- ```bash
362
- lakonai uninstall # strips just the lakonai block; keeps your other CLAUDE.md content
363
- lakonai revert # restores the file to its pre-install state, byte for byte
364
- lakonai backups # shows every snapshot, per platform, with timestamps
365
- ```
366
-
367
- Use `uninstall` to remove lakonai while keeping your other edits. Use `revert` when you want a clean rollback to exactly the file you had before.
368
-
369
- ---
370
-
371
- ## How tracking works
372
-
373
- 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.
374
-
375
- 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`).
376
-
377
- Override the location with `LAKON_HOME=/path`. Disable per-command logging with `LAKON_NO_TRACK=1`.
378
-
379
- > 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.
380
-
381
- ---
121
+ ## Commands
382
122
 
383
- ## Configuration
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 |
384
132
 
385
- | Env var | Effect |
386
- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
387
- | `LAKON_HOME` | Where to keep the log + backups + version cache (default `~/.lakon`) |
388
- | `LAKON_NO_TRACK` | Set to `1` to disable per-command logging |
389
- | `LAKON_NO_UPDATE_CHECK` | Set to `1` to disable the `SessionStart` npm check + terminal hint |
390
- | `LAKON_REGISTRY_URL` | Override the npm registry URL used by the update check (testing) |
391
- | `LAKON_COLOR` | `1` forces ANSI colors in `lakonai gain`; `0` disables; unset = TTY auto-detect |
392
- | `NO_COLOR` | Standard. Disables ANSI colors when set to any non-empty value. |
393
- | `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)**.
394
134
 
395
135
  ---
396
136
 
397
- ## Philosophy
137
+ ## Agents - what each one gets
398
138
 
399
- > _"Brevity is the soul of wit."_ — Shakespeare, _Hamlet_
400
- > _"Vēnī, vīdī, vīcī."_ — Julius Caesar, three words to describe winning a war.
401
- > _"If."_ — Spartans, refusing to be intimidated by a single conditional.
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 | ✅ |
402
144
 
403
- Every token your agent emits or reads is paid for — in latency, in money, in context budget. The fastest way to think clearly is to speak briefly. lakonai doesn't make your agent dumber; it makes it Spartan.
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).
404
150
 
405
151
  ---
406
152
 
407
- ## Development
153
+ ## Why "lakonai"
408
154
 
409
- ```bash
410
- git clone https://github.com/bargadev/lakonai
411
- cd lakonai
412
- npm install # only devDeps (jest for tests/coverage); zero runtime deps
413
- npm test # run the Jest suite
414
- npm run test:coverage # text + HTML coverage report (coverage/index.html)
415
- npm run test:coverage:check # enforce the coverage threshold
416
- node bin/lakonai.js --help
417
- ```
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.
418
158
 
419
- Zero runtime dependencies. Node ≥ 18.
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.
420
161
 
421
162
  ---
422
163
 
423
164
  ## Credits
424
165
 
425
- Built on ideas from two excellent projects:
426
-
427
- - [**caveman**](https://github.com/juliusbrussee/caveman) — terse-prose rule + auto-clarity carve-outs.
428
- - [**rtk**](https://github.com/rtk-ai/rtk) — CLI output filtering as a force multiplier for LLM agents.
429
-
430
- lakonai condenses both into one zero-dependency npm package with a single install command, automatic backups, and time-windowed savings tracking.
431
-
432
- ---
433
-
434
- ## 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.
435
170
 
436
- MIT. See [LICENSE](LICENSE).
437
-
438
- ---
439
-
440
- <p align="center">
441
- <strong>Speak less. Ship more.</strong>
442
- </p>
171
+ MIT - see [LICENSE](LICENSE).