lancet
CLI quirúrgica para buscar, leer y editar código, AST y documentos en múltiples formatos para agentes de programación con IA: un único binario de Rust que reemplaza rg + fd + ast-grep + cat + sed + patch, con un servidor MCP integrado (stdio).
Documentación
Lancet
Fast, safe file tools for many agents working one repository at once.
Website & live demo · Docs · 한국어 · Benchmarks · How it works · Why one tool
Existing tools each pick one corner. A full scan is fresh but slow, an index is fast but stale, and a plain write is simple but loses edits. With one agent that's fine; with dozens on one directory every corner breaks at once, and the tools still exit 0. lancet doesn't make you pick.
| With dozens of agents | Full scan (rg, fd) | Index (zoekt) | lancet |
|---|---|---|---|
| Speed on a large repository | Slow: every query reads everything | Fast | Fast |
| Finds what another agent just wrote | ✓ | ✗ until re-indexed | ✓ by default |
| Index size | none | 2.1–2.8× the source | 10–30% of the source |
| Simultaneous edits | lost (sed, plain writes) | — | none lost: version check, all files or none |
And it can be either one. Same command, same output; only the flag changes:
--no-index (like rg) ◀── auto, the default ──▶ --trust-index (like zoekt)
Fresh when correctness matters, index-only when speed matters most. The choice is always yours, and stale results are never the default.
Also in the same binary:
- Drop-in.
lancet rgandlancet fdtake ripgrep's and fd's flags and print the same output (300 parity cases in CI).lancet agents installmakes Claude Code, Codex and Antigravity run their ownrg/fdthrough lancet. - Edits that commit like transactions.
readgives each file arev;edit,write,patch,renameandast --applywrite only if the file still has it, under a lock, and a change to several files lands in all or none. Claude Code's Edit already refuses its own stale writes; lancet makes that hold across agents and tools. - Mistakes refused, not written. An ambiguous
--old-string, a new syntax error, a second edit landing on a shifted line, a write to a document or binary.renamere-resolves scopes in 17 languages and leaves comments and strings alone. - Documents on the same line numbers. PDFs, spreadsheets, Korean HWP documents and archives.
Under load
32 simulated agents (processes, no model) searching, reading and editing one Django checkout for 20 s on GitHub's 4-vCPU Linux runner (bench/concurrency.py, run 46720661887). After each edit an agent searches for what it just wrote.
| 32 agents, one directory | lancet | rg + plain read/write |
|---|---|---|
| Search, median | 483 ms | 974 ms |
| Operations per second | 58 | 40 |
| Edits lost | 0 of 241 (190 conflicts caught and retried) | 14 of 164 |
| Searches missing a write made a moment ago | 0 | 0 |
| Memory in use, all agents | 114 MiB | 150 MiB |
On the Linux kernel tree (60k files) the median search is 4.7 s against ripgrep's 9.9 s at 32 agents: four cores are saturated either way, and every query still checks every file for changes. --trust-index answers in 0.3 s there but misses every write made since indexing. The op mix (40% rare-literal search, 15% common-identifier count, 25% range read, 20% edit) is an assumption, stated in the script.
Install
curl -fsSL https://raw.githubusercontent.com/CREE1116/lancet/main/install.sh | sh # macOS / Linux
irm https://raw.githubusercontent.com/CREE1116/lancet/main/install.ps1 | iex # Windows
brew tap CREE1116/lancet https://github.com/CREE1116/lancet && brew install lancet # Homebrew
The install scripts verify the archive's SHA-256 before installing, and every release archive carries signed build provenance (gh attestation verify <archive> --repo CREE1116/lancet). Also on crates.io: cargo install lancet. The full binary is ~40 MB (every grammar and document adapter); more options, including cargo and a 4 MB text-only build, are in the installation guide, along with how to uninstall.
A minute with lancet
lancet index . # optional; results stay current without re-running it
lancet fd -e rs # fd's flags and output
lancet rg -w retries src # ripgrep's flags and output, from the index
lancet read src/net.rs --symbol retry_limit # one function, with its rev
lancet refs retry_limit src # definition and every use
lancet ast '$X.unwrap()' src --lang rs --rewrite '$X?' # structural rewrite, dry run
lancet edit src/net.rs --old-string 'retries = 3' --new-string 'retries = 5' --rev <REV> --apply
git diff | lancet patch --apply # all files or none
After large changes (a branch switch, a big refactor) run lancet index . again to keep searches fast; results are correct either way. Every write is a diff until --apply (-q for just the summary and new rev). Try these in the browser on a small project — the outputs there are recorded from the real binary.
Why lancet
Agents chain tools, and the failures happen between them. Each number below is reproduced by a script in this repository (bench/failure_modes.py, bench/suite.py, CI parity jobs), and each says what it compares. Timings come from the latest release benchmark on GitHub Actions ubuntu-latest (4 vCPU x86_64) (bench.yml), rewritten on every release.
| What was compared | |
|---|---|
| 0 / 800 updates lost | Four agents doing read → change → write back on the same files. With a plain read and write-back and no version check (as sed, scripts and many tools do), 600 of 800 updates were lost. The same workflow with lancet's --rev check lost none: the loser gets conflict and retries. |
| 300 / 300 parity cases | lancet rg and lancet fd against ripgrep 16 and fd 10.5 in CI (167 + 133 cases): same output, same exit codes. The flags a model already knows just work. |
| 2× faster than ripgrep | Rare-literal searches on Linux and LLVM in the default auto mode (2.1× and 2.1×), which still re-reads every file changed since indexing, so results equal a full scan. The same search with --trust-index, which skips that check: 16× and 68× (143× and 245× for a literal with no hits). A regex with no literal to look up runs at ripgrep's speed. |
| 40 / 40 reads on the right line | Searching a .docx with rga, then reading the hit's line with pandoc: 0 of 40 reads held the hit, because the two tools extract text differently. lancet's search and read share one extraction. |
The full case, with the multi-agent protocol, file identity and the critiques we took seriously: docs/why-one-tool.md.
How it works, in three lines
- The index only decides which files not to open. Every candidate is checked by the same code a full scan uses. Files edited since indexing are found by
(mtime, size, ctime, inode)and re-read, with no watcher daemon. (What that check can miss.) - One coordinate system. A hit on line 42 is line 42 in
readandedit, even inside a PDF, spreadsheet orarchive.zip!entry.read --symbol,outline,refsandastshare the same Tree-sitter spans. - One write path. Every command that writes goes through the same core: revision check, lock, syntax check, all-or-nothing commit.
Index format, compaction, AST prefiltering and the full benchmark tables: docs/how-it-works.md and docs/benchmarks.md.
Commands
| Command | What it does |
|---|---|
lancet rg | ripgrep's flags and output on lancet's index and document extractors (parity) |
lancet fd | fd's flags, output and exit codes, plus --tree and --type-class (parity) |
lancet ast | Tree-sitter search and --rewrite in 27 languages (vs ast-grep) |
lancet read | Line ranges, --symbol, PDF pages, spreadsheet cells, archive entries, token budgets |
lancet edit / write | Change lines, a symbol, exact text or many hunks at once; guarded by --rev |
lancet patch | Apply git diff / diff -u across files, all or nothing |
lancet refs / outline | Definitions and uses (comments and strings skipped; lexical, so same-named symbols in other scopes are listed too); declaration skeletons, fitted to a token budget with --budget-tokens |
lancet rename | Rename a local variable with scope resolution (17 languages: Rust, Python, JS/TS, Go, C/C++, Java, C#, Kotlin, Swift, Ruby, PHP and more) |
lancet index | Build or update the index |
lancet mcp | MCP server for clients without a shell |
lancet completions | Shell completions (the installers set them up) |
lancet agents | Hook Claude Code, Codex and Antigravity so their rg / fd run as lancet; on / off / strict |
Documents and archives: PDF, DOCX, PPTX, ODT, HWP, HWPX, EPUB, XLSX/XLS/ODS, ZIP, TAR, GZ — extracted in-process with size caps.
Using lancet with agents
- Let the agent set itself up: tell it to read docs/agent-setup.md and follow it.
- Hook (Claude Code, Codex, Antigravity):
lancet agents installmakes the agent's ownrgandfdcommands run as lancet, with the same output.lancet agents off/onswitch it for every agent at once. - Skill: copy
skills/lancet/to~/.claude/skills/,~/.codex/skills/or.agents/skills/ - AGENTS.md / CLAUDE.md: paste docs/agent-instructions.md
- No shell (Claude Desktop and other chat apps): register
lancet mcpas an MCP server (configs). Agents that can run commands don't need it.
License
Dual-licensed under either of Apache License 2.0 or MIT, at your option.