Back to Skills

writing-openrewrite-recipes

verified

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 GitHub

Marketplace

openrewrite

openrewrite/rewrite-docs

Plugin

openrewrite-recipe

Repository

openrewrite/rewrite-docs
49stars

openrewrite-recipe-writer/skills/writing-openrewrite-recipes/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
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-recipes

Installation paths:

Claude
.claude/skills/writing-openrewrite-recipes/
Powered by add-skill CLI

Instructions

# 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

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
13686 chars