OpenRewrite

Also known as: Rewrite, OpenRewrite recipes, Moderne OpenRewrite

OpenRewrite
OpenRewrite is an open-source, rule-based framework that automatically refactors and migrates source code by transforming a Lossless Semantic Tree — a type-aware, format-preserving model of the code. Maintained by Moderne, it applies reusable recipes deterministically, unlike probabilistic LLM migration tools.

OpenRewrite is an open-source framework that automatically refactors and migrates source code by applying rule-based recipes to a structured, format-preserving model of the code rather than editing text directly.

What It Is

Upgrading a framework version, swapping a deprecated library, or applying a security patch across hundreds of files is slow, repetitive, and easy to get wrong by hand. OpenRewrite exists to automate exactly that kind of large-scale, mechanical code change. For a team staring down a migration that touches an entire codebase, it turns weeks of manual edits into a repeatable command.

The framework works by parsing source code into a Lossless Semantic Tree (LST). According to OpenRewrite Docs, the LST is a type-attributed, format-preserving representation of code — meaning it records the type of every symbol and keeps the original spacing, comments, and style intact. This matters because a refactoring tool that loses your formatting produces a noisy, unreviewable diff. The LST lets a transformation change meaning while leaving everything else untouched.

Transformations are packaged as recipes. According to OpenRewrite Docs, a recipe is a group of search and refactoring operations applied to the LST, and recipes can be composed together into larger migrations. Developers run them through Maven or Gradle build plugins on a single project, or, for changes spanning many repositories at once, on the Moderne platform — the company that maintains OpenRewrite as open source. Each run is deterministic: the same recipe on the same code always produces the same result.

That determinism is what separates OpenRewrite from LLM-based migration tools. Where an AI agent reads code and generates a probable fix — which can vary between runs and needs human verification — OpenRewrite applies a fixed rule and guarantees the same transformation every time. Many modernization workflows now combine both: deterministic recipes for well-understood, mechanical changes, and LLM agents for the ambiguous, judgment-heavy rewrites that no rule can fully capture.

How It’s Used in Practice

The most common way teams meet OpenRewrite is a framework or dependency upgrade. A Java team moving from an older Spring Boot version to a newer one, for example, faces dozens of small, predictable API changes scattered across the codebase. Instead of hunting each one down, they add the relevant recipe to their build configuration and run it. The recipe rewrites the affected code, preserves formatting, and produces a clean diff the team can review like any other pull request.

A second, larger-scale use is organization-wide modernization: applying the same recipe — a security fix, a logging-library swap, a Java version migration — across many repositories at once. According to OpenRewrite’s GitHub repository, the build-tool plugins are actively developed, with the rewrite-maven-plugin reaching version 6.41.0 in a snapshot published in May 2026, so recipe behavior and catalog coverage keep evolving.

Pro Tip: Run a recipe on a throwaway branch first and read the diff before trusting it at scale. Recipes are deterministic, not omniscient — they apply exactly the rule they encode, so a recipe that fits most of your code can still mangle the edge cases it was never written for.

When to Use / When Not

ScenarioUseAvoid
Upgrading a framework or library version across many files
Applying the same mechanical change across hundreds of repositories
A one-off, creative rewrite that depends on business context
Migrating well-understood, rule-expressible API changes
Translating code to a different language with ambiguous idioms
Removing a deprecated pattern or enforcing a consistent style

Common Misconception

Myth: OpenRewrite uses AI to figure out how to migrate your code. Reality: OpenRewrite is deterministic and rule-based. It applies recipes written and tested in advance to a semantic model of your code. It does not learn, guess, or vary between runs — which is exactly why its output is reproducible and reviewable. LLM agents fill the gap where no fixed rule exists.

One Sentence to Remember

OpenRewrite automates the mechanical, rule-expressible parts of code migration with repeatable results, making it the deterministic complement to LLM agents rather than their competitor — if your change can be written as a rule, reach for a recipe before reaching for a model.

FAQ

Q: Does OpenRewrite use AI or LLMs to migrate code? A: No. OpenRewrite is deterministic and rule-based. It applies predefined recipes to a structured model of your code, producing the same result every run — unlike LLM agents, which generate probabilistic edits that need verification.

Q: What languages does OpenRewrite support? A: It started with Java and is strongest there, but recipes now cover other languages and formats such as XML, YAML, and properties files. Coverage depends on which language parser builds the semantic tree.

Q: How is OpenRewrite different from a codemod? A: Both automate code changes, but OpenRewrite operates on a type-aware Lossless Semantic Tree, so it understands symbol types and preserves formatting. Many codemods work on a plainer syntax tree with less type information.

Sources

  • OpenRewrite Docs: Lossless Semantic Trees (LST) - Explains the type-attributed, format-preserving code model OpenRewrite transforms.
  • OpenRewrite Docs: Recipes - Describes how search and refactoring operations are packaged and composed.

Expert Takes

Not text editing. Tree transformation. OpenRewrite parses code into a Lossless Semantic Tree that knows the type of every symbol and preserves the original formatting. Because the same recipe always produces the same output, the result is reproducible — a property probabilistic models cannot guarantee. The real science here is representation: choosing a structure rich enough to refactor safely, yet faithful enough to round-trip back to source.

Think of a recipe as a specification you can version, test, and reuse. Instead of describing a migration in a ticket and hoping each developer reads it the same way, you encode the transformation once and run it everywhere. That shifts modernization from manual interpretation toward executable intent — the same principle that makes infrastructure-as-code dependable applies to refactoring-as-code.

Legacy modernization used to be a cost center everyone deferred. Deterministic refactoring changes the math: upgrades that once stalled roadmaps become routine batch jobs. The strategic signal is clear — vendors are racing to own the migration layer, whether through rule engines or AI agents. Teams that automate modernization free their best engineers for product work instead of dependency bumps.

Determinism feels safe, and mostly it is. But a recipe encodes someone’s assumptions about what a correct migration looks like, applied across an entire codebase at once. When a transformation is wrong, it is wrong everywhere, silently. Who reviews the recipe? Who owns the outcome when an automated change breaks production months later? Automation does not remove judgment — it relocates it upstream, where fewer people are watching.