lancet
Surgical code, AST, and multi-format document search/read/edit CLI for AI coding agents — one Rust binary replacing rg + fd + ast-grep + cat + sed + patch, with a built-in MCP server (stdio).
Documentation
Lancet
Find, read, and change code and documents — on one coordinate system, at index speed.
Website & live demo · Docs · 한국어 · Benchmarks · How it works · Why one tool
Lancet is one Rust binary for AI coding agents and the people working beside them. It replaces the rg + fd + ast-grep + cat + sed + patch chain, and every step shares one index and one set of line numbers: find files, search text and syntax, read exact ranges and symbols, and edit — in source code, PDFs, spreadsheets, Korean HWP documents and archives alike.
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 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.
A minute with lancet
lancet index . # optional: build the index once; it keeps itself fresh
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
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. They were measured on one Apple Silicon Mac; reproductions on Linux x86_64 are welcome as an issue.
| What was compared | |
|---|---|
| 0 / 800 updates lost | Four agents doing read → change → write back on the same files. With no lock or version check, 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. |
| 9–10× faster than ripgrep | Rare-literal searches on Linux and LLVM in the default auto mode (9.7× and 8.9×), 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: 123× and 335× (459× and 866× 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, so results are identical to a scan. Files edited since indexing are found by
(mtime, size, ctime, inode)and re-read — 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. - Every write is a compare-and-swap.
readreports arev(a hash of the bytes);edit,ast --applyandpatchwrite only if the file still has it, under a file lock, and refuse edits that add syntax errors.
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) |
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
- MCP:
claude mcp add --transport stdio lancet -- lancet mcp --root .(other clients) - Skill: copy
skills/lancet/to~/.claude/skills/,~/.codex/skills/or.agents/skills/ - AGENTS.md / CLAUDE.md: paste docs/agent-instructions.md
License
Dual-licensed under either of Apache License 2.0 or MIT, at your option.