About codemod
A best-practices skill for AI agents and LLMs working with Codemod, JSSG, ast-grep, and migration workflows. Its 48 rules cover the full process, from AST matching and edits to testing and package structure.
Key features
- 0148 prioritized rules across 11 categories
- 02Guidance for JSSG and ast-grep
- 03AST parsing, traversal, and edits
- 04Workflow design and validation
- 05Testing, state, and security guidance
Use cases
- 01Writing or reviewing codemods
- 02Debugging pattern matching and AST traversal
- 03Designing migration workflows
- 04Testing code transforms before full runs
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ pproenca/ dot-skills --skill codemodAfter installing, type/codemodin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
AGENTS.mdmetadata.jsonREADME.mdassets/templates/_template.mdreferences/_sections.mdast-check-null-before-access.mdast-explore-before-writing.mdast-field-access-for-structure.mdast-understand-named-vs-anonymous.mdast-use-kind-for-precision.mdedit-add-imports-correctly.mdedit-batch-before-commit.mdedit-handle-overlapping-ranges.mdedit-preserve-formatting.mdedit-use-flatmap-for-conditional.mdparse-early-return-non-applicable.mdparse-handle-embedded-languages.mdparse-provide-pattern-context.mdparse-select-correct-parser.mdpattern-avoid-overly-generic.mdpattern-combine-with-rules.mdpattern-ensure-idempotency.mdpattern-use-constraints.mdpattern-use-meta-variables.mdpattern-use-relational-patterns.mdpkg-organize-by-convention.mdpkg-use-semantic-versioning.mdpkg-write-descriptive-metadata.mdsecurity-minimize-capabilities.mdsecurity-review-before-running-third-party.mdDetails
From the project READMECodemod Best Practices
Comprehensive best practices guide for Codemod (JSSG, ast-grep, workflows), designed for AI agents and LLMs. Contains 48 rules across 11 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new codemods with JSSG or ast-grep
- Designing workflow configurations for migrations
- Debugging pattern matching or AST traversal issues
- Reviewing codemod code for performance and safety
- Setting up test fixtures for transform validation
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | AST Understanding | CRITICAL | ast- |
| 2 | Pattern Efficiency | CRITICAL | pattern- |
| 3 | Parsing Strategy | CRITICAL | parse- |
| 4 | Node Traversal | HIGH | traverse- |
| 5 | Semantic Analysis | HIGH | semantic- |
| 6 | Edit Operations | MEDIUM-HIGH | edit- |
| 7 | Workflow Design | MEDIUM-HIGH | workflow- |
| 8 | Testing Strategy | MEDIUM | test- |
| 9 | State Management | MEDIUM | state- |
| 10 | Security and Capabilities | LOW-MEDIUM | security- |
| 11 | Package Structure | LOW | pkg- |
Quick Reference
1. AST Understanding (CRITICAL)
ast-explore-before-writing- Use AST Explorer before writing patternsast-understand-named-vs-anonymous- Understand named vs anonymous nodesast-use-kind-for-precision- Use kind constraint for precisionast-field-access-for-structure- Use field access for structural queriesast-check-null-before-access- Check null before property access
2. Pattern Efficiency (CRITICAL)
pattern-use-meta-variables- Use meta variables for flexible matchingpattern-avoid-overly-generic- Avoid overly generic patternspattern-combine-with-rules- Combine patterns with rule operatorspattern-use-constraints- Use constraints for reusable matching logicpattern-use-relational-patterns- Use relational patterns for contextpattern-ensure-idempotency- Ensure patterns are idempotent
3. Parsing Strategy (CRITICAL)
parse-select-correct-parser- Select the correct parser for file typeparse-handle-embedded-languages- Handle embedded languages with parseAsyncparse-provide-pattern-context- Provide context for ambiguous patternsparse-early-return-non-applicable- Early return for non-applicable files
4. Node Traversal (HIGH)
traverse-use-find-vs-findall- Use find() for single match, findAll() for multipletraverse-single-pass-collection- Collect multiple patterns in single traversaltraverse-use-stopby-for-depth- Use stopBy to control traversal depthtraverse-use-siblings-efficiently- Use sibling navigation efficientlytraverse-cache-repeated-lookups- Cache repeated node lookups
5. Semantic Analysis (HIGH)
semantic-use-file-scope-first- Use file scope semantic analysis firstsemantic-check-null-results- Handle null semantic analysis resultssemantic-verify-file-ownership- Verify file ownership before cross-file editssemantic-cache-cross-file-results- Cache semantic analysis results
6. Edit Operations (MEDIUM-HIGH)
edit-batch-before-commit- Batch edits before committingedit-preserve-formatting- Preserve surrounding formatting in editsedit-handle-overlapping-ranges- Handle overlapping edit rangesedit-use-flatmap-for-conditional- Use flatMap for conditional editsedit-add-imports-correctly- Add imports at correct position
7. Workflow Design (MEDIUM-HIGH)
workflow-order-nodes-by-dependency- Order nodes by dependencyworkflow-use-matrix-for-parallelism- Use matrix strategy for parallelismworkflow-use-manual-gates- Use manual gates for critical stepsworkflow-validate-before-run- Validate workflows before runningworkflow-use-conditional-steps- Use conditional steps for dynamic workflows
8. Testing Strategy (MEDIUM)
test-use-fixture-pairs- Use input/expected fixture pairstest-cover-edge-cases- Cover edge cases in test fixturestest-use-strictness-levels- Choose appropriate test strictness leveltest-update-fixtures-intentionally- Update test fixtures intentionallytest-run-on-subset-first- Test on file subset before full run
9. State Management (MEDIUM)
state-use-for-resumability- Use state for resumable migrationsstate-make-transforms-idempotent- Make transforms idempotent for safe rerunsstate-log-progress-for-observability- Log progress for long-running migrations
10. Security and Capabilities (LOW-MEDIUM)
security-minimize-capabilities- Minimize requested capabilitiessecurity-validate-external-inputs- Validate external inputs before usesecurity-review-before-running-third-party- Review third-party codemods before running
11. Package Structure (LOW)
pkg-use-semantic-versioning- Use semantic versioning for packagespkg-write-descriptive-metadata- Write descriptive package metadatapkg-organize-by-convention- Organize package by convention
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Full Compiled Document
For a complete guide with all rules expanded, see AGENTS.md.