https://github.com/llbbl/grepwrite
Ripgrep-style search plus safe, transactional, AST-aware rewrites with built-in undo. Designed first for LLM coding agents, useful for humans.
https://github.com/llbbl/grepwrite
Last synced: 24 days ago
JSON representation
Ripgrep-style search plus safe, transactional, AST-aware rewrites with built-in undo. Designed first for LLM coding agents, useful for humans.
- Host: GitHub
- URL: https://github.com/llbbl/grepwrite
- Owner: llbbl
- License: mit
- Created: 2026-05-31T15:33:06.000Z (28 days ago)
- Default Branch: main
- Last Pushed: 2026-05-31T18:04:53.000Z (28 days ago)
- Last Synced: 2026-05-31T18:12:07.295Z (28 days ago)
- Language: Rust
- Size: 180 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# grepwrite
[](https://crates.io/crates/grepwrite)
[](https://crates.io/crates/grepwrite)
[](LICENSE)
> Ripgrep-style search plus safe, transactional, AST-aware rewrites with built-in undo. Designed first for LLM coding agents, useful for humans.
**Binary:** `gw`
## Install
```bash
cargo install grepwrite
```
(Homebrew formula in progress. Prebuilt binaries: planned.)
## Usage
### `gw find [path]`
Locate matches via ripgrep, or via ast-grep with `--in function|class|imports|comments`.
```text
$ gw find TODO src/
src/lib.rs
1:4: // TODO: rename foo to bar
src/main.rs
2:8: // TODO: wire up cli
```
### `gw rewrite [path]`
Preview by default; `--apply` writes atomically with a git snapshot.
```text
$ gw rewrite 'foo' 'bar' src/ -o diff # preview
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,4 @@
-// TODO: rename foo to bar
-pub fn foo() -> u32 {
+// TODO: rename bar to bar
+pub fn bar() -> u32 {
42
}
...
$ gw rewrite 'foo' 'bar' src/ --apply # write
...
applied (snapshot: 2026-05-31T19-52-42-9ceabf)
```
### `gw undo [--snapshot ]`
Restores files exactly, refusing to clobber edits you made on top.
```text
$ gw undo
undone: 2026-05-31T19-52-42-9ceabf (2 files restored)
```
### `gw snapshots`
Lists snapshots, newest first.
```text
$ gw snapshots
2026-05-31T19-52-42-9ceabf 2026-05-31T19:52:42Z 3 edits -
```
### Output formats
`compact` (default — rg-style for `find`, unified diff for `rewrite`), `caveman` (LLM-token-minimal `path:line` per match), `json` (stable schema v1), `diff` (unified, `rewrite` only).
## Why
`gw` wraps two excellent existing tools — [ripgrep](https://github.com/BurntSushi/ripgrep) for regex search and [ast-grep](https://ast-grep.github.io/) for structural search — and adds the missing piece: a safe, transactional rewrite layer with built-in undo.
ripgrep deliberately stops at preview: `rg -r` prints what it would write without writing. The conventional workaround is to chain `rg` with `sed -i` and a read-after-write check, which works but is brittle in scripts and especially hostile to LLM coding agents — three tools, three failure modes, tokens spent reconciling each step.
`gw` collapses that chain into one binary: locate, plan, dry-run by default, and atomic per-file writes wrapped in a git-ref snapshot when you commit to `--apply`. The locate layer is unchanged — it's just ripgrep and ast-grep underneath — so search semantics are exactly what you already know.
## Documentation
- [Contributing & build instructions](docs/CONTRIBUTING.md) — build, test, lint, debug, credits.
- [Smoke testing in Docker](docs/SMOKE.md) — ephemeral fixtures for manual exploration.
- [Release procedure](docs/RELEASING.md) — versioning policy and release recipes.
## License
MIT. See [LICENSE](LICENSE).