|
| 1 | +--- |
| 2 | +title: "SWE Agents are Better with Codemods" |
| 3 | +sidebarTitle: "Devin" |
| 4 | +icon: "robot" |
| 5 | +iconType: "solid" |
| 6 | +--- |
| 7 | + |
| 8 | +Coding assistants like Cursor have introduced a new era of programming. But there's a class of programming tasks they can't handle: large-scale, systematic modifications across large codebases. You wouldn't ask an AI to delete all dead code or reorganize your entire component hierarchy - the tooling just isn't there. |
| 9 | + |
| 10 | +That's where codemods come in. A codemod is a program that operates on your codebase, and when you give an AI agent the ability to write and execute them, these tasks fall below the high-water mark of AI capabilities. |
| 11 | + |
| 12 | +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 trying to make 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. |
| 13 | + |
| 14 | +- [View the PR](https://github.com/codegen-sh/codegen/pull/660) |
| 15 | +- [View on Devin](app.devin.ai/sessions/a49eac87da644fa9ac1144fe130b847e) |
| 16 | + |
| 17 | +<Frame caption="Devin edits a codemod in response to linter errors"> |
| 18 | + <img src="/images/devin-edits-codemod.png" /> |
| 19 | +</Frame> |
| 20 | + |
| 21 | +This modifies over 40 files and correctly removes old code, passes lint + tests, etc. |
| 22 | + |
| 23 | +What made this work? |
| 24 | + |
| 25 | +Devin operates like a state machine: write a codemod, run it through the linter, analyze failures, and refine. Each iteration adds handling for new edge cases until the codemod successfully transforms the entire codebase. This is the same cycle developers use for many large-scale refactors, just automated. |
| 26 | + |
| 27 | +```mermaid |
| 28 | +flowchart LR |
| 29 | + style EditRun fill:#ff6b6b,stroke:#000,stroke-width:3px,color:#000,font-weight:bold,font-size:16px |
| 30 | + style Linter fill:#4dabf7,stroke:#000,stroke-width:3px,color:#000,font-weight:bold,font-size:16px |
| 31 | + style Success fill:#cc5de8,stroke:#000,stroke-width:3px,color:#000,font-weight:bold,font-size:16px |
| 32 | + |
| 33 | + EditRun["Edit + Run<br/>Codemod"] --> Linter["Run<br/>Linter"] |
| 34 | + Linter --"success?"--- Success["Success"] |
| 35 | + Linter --"errors found"--- EditRun |
| 36 | + |
| 37 | + linkStyle default stroke-width:2px |
| 38 | + classDef edgeLabel fill:#e9ecef,color:#000,font-weight:bold |
| 39 | + class success?,errors edgeLabel |
| 40 | +``` |
| 41 | + |
| 42 | +The nice part about this approach is that we don't have to blindly trust the AI. There's no magic - it's just a program we can run and verify through linter/test output. The codemod is easy to review, and we can update it if we need to add exceptions or edge cases. Much better than trying to manually review hundreds of individual edits. |
| 43 | + |
| 44 | +## Try it yourself |
| 45 | + |
| 46 | +Want to experience this with your own Devin instance? Install the Codegen CLI in your Devin box: |
| 47 | + |
| 48 | +```bash |
| 49 | +uv tool install codegen --python 3.13 |
| 50 | +``` |
| 51 | + |
| 52 | +Then use the following prompt: |
| 53 | + |
| 54 | +<Card title="Dead Code Deletion Prompt" icon="download" href={"https://gist.github.com/jayhack/d742b701a38a5b5274517afce2d253c2"}> |
| 55 | + Download System Prompt |
| 56 | +</Card> |
| 57 | + |
| 58 | +Or try it with other platform-level modifications supported by Codegen: |
| 59 | + |
| 60 | +<CardGroup cols={2}> |
| 61 | + <Card |
| 62 | + title="Convert Promises" |
| 63 | + icon="code-merge" |
| 64 | + href="/tutorials/promise-to-async-await" |
| 65 | + > |
| 66 | + Automatically convert Promise chains to async/await syntax across your codebase. |
| 67 | + </Card> |
| 68 | + <Card |
| 69 | + title="Organize Code" |
| 70 | + icon="folder-tree" |
| 71 | + href="/tutorials/organize-your-codebase" |
| 72 | + > |
| 73 | + Move and organize code safely with automatic import and dependency handling. |
| 74 | + </Card> |
| 75 | + <Card |
| 76 | + title="Modernize React" |
| 77 | + icon="react" |
| 78 | + iconType="brands" |
| 79 | + href="/tutorials/react-modernization" |
| 80 | + > |
| 81 | + Convert class components to hooks, standardize props, and organize components. |
| 82 | + </Card> |
| 83 | + <Card |
| 84 | + title="Migrate Tests" |
| 85 | + icon="vial" |
| 86 | + href="/tutorials/unittest-to-pytest" |
| 87 | + > |
| 88 | + Automatically convert unittest test suites to modern pytest style. |
| 89 | + </Card> |
| 90 | +</CardGroup> |
| 91 | + |
| 92 | +We'd love to hear how it works for you! Let us know in our [community](https://community.codegen.com) and share other tasks that it is helpful in performing. |
0 commit comments