agentleFS
qyndexqyndex/claude-init/.claude/skills/codemod/SKILL.md

codemod

Skill2 starsChanged 5 months agoMITView on GitHub

Large-scale refactor via AST-aware transforms — jscodeshift (JS/TS), ts-morph (TS), comby (any language), bowler (Python). Dry-run → review → apply loop. Use for React 18→19, Node 22→24, or any change touching 50+ call sites.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Dry run before write: Always preview the diff.

    line 78
  2. Distinctive:

    One transform per PR: Don't combine codemods with feature work.

    line 79
  3. Very specific:

    When /upgrade <pkg> --major is invoked, this skill is the first call:

    line 86
  4. Distinctive:

    Read the upgrade guide

    line 87

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Codemod — refactor at scale

50+ call sites of the same change is a codemod, not 50 manual edits.

Tools

ToolLanguagesWhen to use
jscodeshiftJS/TS via Babel ASTReact's official codemod tool; large ecosystem of community codemods
ts-morphTypeScript with type infoType-aware refactors; renames; signature changes
combyAny language via pattern matchingCross-language; no AST setup; quick one-shot
bowlerPython via LibCSTType-aware Python; preserves comments
ast-grepAny language via TreeSitterPattern matching with structural awareness
Semgrep autofixAnyWhen you already have a Semgrep rule

Process

  1. Define the transform — write or find a codemod. Express as: "for every <pattern>, replace with <replacement>".
  2. Dry run on a few files — verify the transform does what you expect.
  3. Dry run on the whole codebase — generates a diff but doesn't write.
  4. Review the diff — visual review of the proposed changes. Look for false positives.
  5. Apply — run with --write. Commit the diff with a "codemod:" prefix.
  6. Verify — tests + typecheck + lint pass.
  7. Open the PR — descriptive title + body explaining the codemod source.

Example: jscodeshift for a React API rename

// codemods/rename-useLayoutEffect.js
module.exports = function(fileInfo, api) {
  const j = api.jscodeshift;
  return j(fileInfo.source)
    .find(j.CallExpression, { callee: { name: 'useLayoutEffect' } })
    .replaceWith(p => j.callExpression(j.identifier('useInsertionEffect'), p.value.arguments))
    .toSource();
};

Run:

npx jscodeshift -t codemods/rename-useLayoutEffect.js src/ --dry --print  # preview
npx jscodeshift -t codemods/rename-useLayoutEffect.js src/                  # apply

Example: ts-morph for type-aware rename

// codemods/rename-method.ts
import { Project } from "ts-morph";
const project = new Project({ tsConfigFilePath: "tsconfig.json" });
project.getSourceFiles().forEach(sf => {
  sf.forEachDescendant(node => {
    if (node.getKindName() === 'MethodDeclaration' && node.getName() === 'oldName') {
      node.rename('newName');  // type-aware; updates all call sites
    }
  });
});
project.save();

Example: comby (language-agnostic)

# Rename all `foo(:[args])` to `bar(:[args])` across all .ts files
comby 'foo(:[args])' 'bar(:[args])' -d src -extensions ts -in-place

Hard rules

  • Dry run before write. Always preview the diff.
  • One transform per PR. Don't combine codemods with feature work.
  • Verify with tests + typecheck. A codemod that breaks the type checker is a codemod that introduced a bug.
  • Save the codemod script in codemods/ for future re-runs and as historical record.
  • Document false positives in the PR description if you had to skip files.

Integration with /upgrade

When /upgrade <pkg> --major is invoked, this skill is the first call:

  1. Read the upgrade guide
  2. Find or write the matching codemods
  3. Dry-run → review → apply per codemod
  4. Then run the test suite + ship

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.