CLI ToolsMay 12, 2026·2 min read

GritQL — Declarative Code Rewrite CLI

GritQL is a declarative language + CLI for searching and rewriting codebases with snippet-like patterns, making large refactors repeatable and reviewable.

Intro

GritQL is a declarative language + CLI for searching and rewriting codebases with snippet-like patterns, making large refactors repeatable and reviewable.

  • Best for: teams doing recurring migrations (logging, API renames, lint fixes) across 10k–10M+ LOC repos
  • Works with: polyglot repos (TS/Python/Go/etc.), CI-driven codemods, branch-based review workflows
  • Setup time: 5 minutes

Practical Notes

  • Designed for scale: README claims it can handle 10M+ line repositories
  • Reuse library patterns: supports 200+ shared patterns via a built-in module system (README)

A Practical Refactor Loop for Agents

If you’re using coding agents, the bottleneck is often “how do we apply the same change consistently across many files?”

GritQL helps by making the change declarative:

  1. Start with a search-only pattern to learn the surface area.
  2. Add a rewrite (=>) once you’re confident the match is precise.
  3. Run on a small folder first, then the whole repo.
  4. Review the diff like any other migration (tests + lint + code review).

Example rewrite from the README:

grit apply '`console.log($msg)` => `winston.log($msg)`'

If the repo is large, treat the migration as a batch job: run it once in CI, then keep it as a reusable “codemod” command for future consistency.

FAQ

Q: Do I need to learn ASTs? A: No. The README emphasizes snippet-like patterns as valid queries without deep AST knowledge.

Q: Is it only for JavaScript? A: No. It supports many target languages (TS/Python/Go/etc.) via its language support matrix.

Q: How do I keep it safe? A: Run in a branch, start small, and use CI tests + code review like any refactor.

🙏

Source & Thanks

Source: https://github.com/biomejs/gritql > License: MIT > GitHub stars: 4,493 · forks: 121

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets