Search · read · edit — for AI coding agents

Find, read and change code at index speed.

One Rust binary replaces the rg + fd + ast-grep + cat + sed chain. Every step shares one index and one coordinate system, results are always fresh, and edits from two agents never silently overwrite each other.

ripgrep-compatible output, byte for byte 24 Tree-sitter languages PDF · Office · HWP · archives MIT / Apache-2.0
curl -fsSL https://raw.githubusercontent.com/CREE1116/lancet/main/install.sh | sh
~/lancet — an agent's session

    
How it works

Three ideas, one binary.

The index only decides which files not to open. Search, read and edit agree on every line number. Every write is a compare-and-swap.

lancet '"spin_lock"'
Linux v6.12, measured
files in the tree86,218
opened and verified (9.1%)0
matching files (8.2%)0
never opened opened, no match match edited after lancet index

1 · search

$ lancet rg -w retries src
src/net.rs:2:    let retries = 3;
src/net.rs:3:    retries

2 · read — same line numbers

$ lancet read src/net.rs --json
rev e70d5a898f122a62
1 | pub fn retry_limit() -> u32 {
2 |     let retries = 3;
3 |     retries
4 | }

3 · edit — guarded by rev

$ lancet edit src/net.rs \
    --find 'let retries = 3;' \
    --with 'let retries = 5;' \
    --rev e70d5a898f122a62 --apply
-    let retries = 3;
+    let retries = 5;
applied: lines 2-2, rev 1486bdffbc06c68f
src/net.rs rev e70d…
agent A
agent B
4 agents, read → change → write back (plain files)600 / 800updates lost, every write exited 0
the same 4 agents with lancet edit --rev0 / 800updates lost; losers got conflict and retried
Features

Everything an agent does to a codebase.

Index speed, fresh by default

A trigram index picks candidate files; every candidate is checked by the same evaluator a full scan uses. Files edited since indexing are found by mtime/size/ctime/inode and scanned live. No daemon to run.

ripgrep, byte for byte

lancet rg takes ripgrep's flags and prints ripgrep's output, checked byte for byte on 8 codebases. It reads .gitignore, .rgignore, globs and --type the same way.

Structural search & rewrite

lancet ast '$X.unwrap()' --rewrite '$X?' in 24 Tree-sitter languages, with $$$ARGS and statement metavariables. A rewrite is a dry-run diff until --apply.

Exact reads, small context

read --symbol, line ranges, PDF pages and spreadsheet cells, all under a token budget. On the same lookups it used 5–30× less context than reading whole files.

Safe edits for many agents

edit, patch and AST rewrites write through one locked compare-and-swap. A stale --rev gets conflict and writes nothing. Symlinks, hard links and file mode are kept, and edits that add syntax errors are refused.

Documents in scope

PDF, DOCX, PPTX, XLSX, HWP, EPUB, ZIP and TAR are extracted in-process, with caps against decompression bombs. A hit on line 42 of a .docx is line 42 in read too.

Benchmarks

8 codebases, 7 languages, same output as ripgrep.

Speedup over ripgrep on rare-literal queries. auto checks freshness on every query (the default); trust answers from the index alone (--trust-index). Every text result was compared byte for byte with ripgrep's.

Speedup vs ripgrep (log scale, min–max across queries)

auto (always fresh)trust (--trust-index)
Show as table
CodebaseFilesIndex build · sizeauto vs rgtrust vs rgAST vs ast-grep

Where lancet doesn't win: regexes with no literal text (the index can't narrow them, so it runs at ripgrep's speed or up to 1.4× slower) and AST patterns with no literal text (0.6–1.0× ast-grep's speed). Benchmarks & competitor tradeoffs → · Full tables →

Why one tool

Tool chains fail between the steps.

Each row was reproduced with the real tools by bench/failure_modes.py.

ChainWhat happenedlancet
rg -n → two sed -i editsThe second edit hit the wrong line; both exited 0edit --edits uses the original line numbers
4 agents: read → change → write back600 of 800 updates lost, silentlyedit --rev: 0 of 800 lost
patch -p1 with one stale hunkOne file changed, one rejected: half-appliedpatch: nothing written, conflict
sed renameAlso rewrote comments and strings (0.3–11.7% of occurrences)refs / ast only touch code
rga → pandoc on a .docx0 of 40 lines read held the hit40 of 40: search and read share one extraction
zoekt right after editing 20 filesNew text found in 0, deleted text still found in 20auto mode: 20 and 0
sed -i / perl -piBroke hard links and symlinks, lost mode 0640Same file: links, mode and owner kept
Get started

Install, index once, hand it to your agent.

terminal

# optional: build the index once (it updates itself afterwards)
lancet index .

lancet fd --tree --dirs --max-depth 2 .
lancet refs --rank '*Service' --kind class src
lancet rg -w spin_lock src
lancet read src/search.rs --symbol execute_one
lancet ast '$X.unwrap()' src --lang rs --rewrite '$X?'
lancet edit src/net.rs --find 'retries = 3' \
  --with 'retries = 5' --rev <REV> --apply
lancet rename src/net.rs:12 old_var new_var --rev <REV> --apply
git diff | lancet patch --apply

MCP & Official Skill

# 1. Register built-in MCP server (Claude Code)
claude mcp add --transport stdio lancet -- lancet mcp --root .
# Cursor / Codex / Antigravity: see docs/guides/agents-mcp.html

# 2. Install official skill (SKILL.md + references/)
# Copy skills/lancet/ to ~/.claude/skills/, ~/.codex/skills/,
# ~/.gemini/config/skills/, or .agents/skills/

# 3. Optional 1-liner in AGENTS.md / CLAUDE.md:
Use lancet (lancet_* MCP or CLI) instead of rg/fd/ast-grep/cat/sed;
follow the lancet skill for read --rev -> edit --apply.