Skip to main content
Glama
README.md
<div align="center">

# Lancet

**Find, read, and change code and documents — on one coordinate system, at index speed.**

[![CI](https://github.com/CREE1116/lancet/actions/workflows/ci.yml/badge.svg)](https://github.com/CREE1116/lancet/actions/workflows/ci.yml)
[![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](#license)

[Website & live demo](https://cree1116.github.io/lancet/) · [Docs](https://cree1116.github.io/lancet/docs/) · [한국어](./README.ko.md) · [Benchmarks](./docs/benchmarks.md) · [How it works](./docs/how-it-works.md) · [Why one tool](./docs/why-one-tool.md)

</div>

<p align="center">
  <img src="docs/assets/bench-suite.svg" width="100%" alt="Across 8 codebases and 7 languages (338,763 files), lancet answers rare-literal queries 2.8–9.7× faster than ripgrep in always-fresh auto mode and 21–335× faster with --trust-index, with output byte-identical to ripgrep.">
</p>

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

```bash
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](https://cree1116.github.io/lancet/docs/).

## A minute with lancet

```bash
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](https://cree1116.github.io/lancet/#try) 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/failure_modes.py), [`bench/suite.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](./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](./docs/how-it-works.md#what-the-freshness-check-can-miss).)
- **One coordinate system.** A hit on line 42 is line 42 in `read` and `edit`, even inside a PDF, spreadsheet or `archive.zip!entry`. `read --symbol`, `outline`, `refs` and `ast` share the same Tree-sitter spans.
- **Every write is a compare-and-swap.** `read` reports a `rev` (a hash of the bytes); `edit`, `ast --apply` and `patch` write 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](./docs/how-it-works.md) and [docs/benchmarks.md](./docs/benchmarks.md).

## Commands

| Command | What it does |
|---|---|
| `lancet rg` | ripgrep's flags and output on lancet's index and document extractors ([parity](./docs/rg-parity.md)) |
| `lancet fd` | fd's flags, output and exit codes, plus `--tree` and `--type-class` ([parity](./docs/fd-parity.md)) |
| `lancet ast` | Tree-sitter search and `--rewrite` in 27 languages ([vs ast-grep](./docs/ast-grep-parity.md)) |
| `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](./docs/mcp.md))
- **Skill:** copy [`skills/lancet/`](./skills/lancet/) to `~/.claude/skills/`, `~/.codex/skills/` or `.agents/skills/`
- **AGENTS.md / CLAUDE.md:** paste [docs/agent-instructions.md](./docs/agent-instructions.md)

## License

Dual-licensed under either of [Apache License 2.0](./LICENSE-APACHE) or [MIT](./LICENSE-MIT), at your option.