# SWE Agents are Better with Codemods

By **Codegen Technical Staff**  
· Updated August 26, 2025

**Coding assistants like Cursor have brought us into a new era of programming.**

But there’s a class of programming tasks that remain outside their reach: large-scale, systematic modifications across large codebases. You wouldn’t ask an AI to delete all your dead code or reorganize your entire component hierarchy—the tooling just isn’t there.

That’s where **codemods** come in.

A codemod is a program that operates on a codebase, and when you give an AI agent the ability to write and execute them, these platform-level tasks fall below the high-water mark of AI capabilities.

**Here’s a real example:**

We asked [Devin](https://docs.devin.ai/get-started/devin-intro) (an autonomous SWE agent) to _“delete all dead code”_ from our codebase. Instead of making hundreds of individual edits, Devin [wrote and debugged a program](https://github.com/codegen-sh/codegen/pull/660/files#diff-199b0c459adf1639f664fed248fa48bb640412aeacbe61cd89475d6598284b5f) that systematically removed unused code while handling edge cases like tests, decorators, and indirect references.

This modifies over 40 files and correctly removes old code, passes lint and tests, etc.

* * *

### What made this work?

Devin operates like a state machine: write a codemod → run it through the linter → analyze failures → refine.

Each iteration adds handling for new edge cases until the codemod successfully transforms the codebase.

This mirrors the same cycle developers use for large-scale refactors—just automated.

The best part? **You don’t have to blindly trust the AI.**

The codemod is a program you can review, run, and verify with linter and test output. You can edit it to add exceptions or improve coverage—much better than reviewing hundreds of individual diffs.

* * *

## Try it yourself

Want to try this with your own Devin instance?

Install the Codegen CLI:

```
uv tool install codegen --python 3.13
```

Then use this prompt:

[Download Dead Code Deletion Prompt](https://gist.github.com/jayhack/d742b701a38a5b5274517afce2d253c2)

* * *

### Supported Codemods with Codegen

- **Convert Promises to async/await:**  
Automatically convert Promise chains to async/await syntax across your codebase.
- **Organize Codebase:**  
Move and reorganize code safely with automatic import and dependency handling.
- **Modernize React:**  
Convert class components to hooks, standardize props, and organize components.
- **Migrate Tests to Pytest:**  
Convert unittest test suites to modern pytest style.

* * *

We’d love to hear how it works for you.

Join our [community](https://community.codegen.com/) and share your experience developing codemods with Devin or other code assistants.
