Codegen enables you to create reusable code transformations using Python functions decorated withDocumentation Index
Fetch the complete documentation index at: https://codegeninc-fix-system-prompt-typo.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
@codegen.function. These codemods can be shared, versioned, and run by your team.
Creating Codemods
The easiest way to create a new codemod is using the CLI create command:.codegen/codemods directory:
Codemods are stored in
.codegen/codemods/name/name.py and are tracked in Git for easy sharing.AI-Powered Generation with -d
You can use AI to generate an initial implementation by providing a description:
- Generate an implementation based on your description
- Create a custom system prompt that you can provide to an IDE chat assistant (learn more about working with AI)
- Place both files in the codemod directory
Running Codemods
Once created, run your codemod using:- Codegen parses your codebase into a graph representation
- Your codemod function is executed against this graph
- Changes are tracked and applied to your filesystem
- A diff preview shows what changed
Codemod Structure
A codemod consists of three main parts:- The
@codegen.functiondecorator that names your codemod - A
runfunction that takes aCodebaseparameter - Your transformation logic using the Codebase API