Use when creating/writing/building OpenRewrite recipes, working with .java recipe files, RewriteTest files, recipe YAML files, LST visitors, JavaTemplate, visitor patterns, or when discussing recipe types (declarative YAML, Refaster templates, imperative Java recipes) - guides creation of OpenRewrite recipes for automated code transformations, AST manipulation, custom refactoring rules, and code migration.
View on GitHubopenrewrite/rewrite-docs
openrewrite-recipe
openrewrite-recipe-writer/skills/writing-openrewrite-recipes/SKILL.md
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/openrewrite/rewrite-docs/blob/main/openrewrite-recipe-writer/skills/writing-openrewrite-recipes/SKILL.md -a claude-code --skill writing-openrewrite-recipesInstallation paths:
.claude/skills/writing-openrewrite-recipes/# OpenRewrite Recipe Writing Skill
## Overview
OpenRewrite recipes are automated refactoring operations that modify Lossless Semantic Trees (LSTs) representing source code. This skill guides through creating recipes efficiently and correctly.
## When NOT to Use This Skill
Do NOT use this skill for:
- General Java programming questions unrelated to OpenRewrite
- Questions about running existing OpenRewrite recipes (use OpenRewrite documentation)
- Build tool configuration unrelated to recipe development
- General refactoring advice without OpenRewrite context
## Quick Start Decision Tree
To determine the best approach quickly:
1. Can the transformation be expressed by composing existing recipes?
→ **Use Declarative YAML** (see Declarative YAML Recipes section below)
2. Is it a simple expression/statement replacement pattern?
→ **Use Refaster Template** (see Refaster Template Recipes section below)
3. Requires complex logic, conditional transformations, or custom analysis?
→ **Use Imperative Java Recipe** (see Imperative Recipe Development Workflow below)
For imperative recipes, proceed to "Imperative Recipe Development Workflow" below.
## Recipe Type Selection
Choose the appropriate recipe type based on your needs:
### Declarative YAML Recipes (Preferred)
**Use when:** Composing existing recipes with configuration
**Advantages:** No code, simple, maintainable
**Example use case:** Combining framework migration steps
```yaml
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.MyMigration
displayName: Migrate to Framework X
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: old.Type
newFullyQualifiedTypeName: new.Type
- com.yourorg.OtherRecipe
```
**Finding Recipes to Use:**
When building declarative YAML recipes, consult the recipe catalog CSV files in the `references/` directory:
- `references/recipes-top.csv` - 50 commonly used recipes across all categories (best starting point)
- `references