|
| 1 | +--- |
| 2 | +title: Custom Rules |
| 3 | +description: Configure Open SWE with project-specific rules using `AGENTS.md` |
| 4 | +--- |
| 5 | + |
| 6 | +# Custom Rules |
| 7 | + |
| 8 | +Custom rules allow you to provide project-specific context and guidelines to Open SWE through a markdown file in your repository root. |
| 9 | + |
| 10 | +## Getting Started |
| 11 | + |
| 12 | +The easiest way to get started is to have Open SWE itself write this file for you! The Open SWE UI provides a "Generate `AGENTS.md`" quick action which will insert a predefined prompt into the input. This prompt has been designed to generate a well-formatted `AGENTS.md` file from the agent. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## What is `AGENTS.md`? |
| 17 | + |
| 18 | +`AGENTS.md` is a markdown file that tells Open SWE about your project's: |
| 19 | + |
| 20 | +- Coding standards and conventions |
| 21 | +- Repository structure and architecture |
| 22 | +- Dependencies and installation procedures |
| 23 | +- Testing frameworks and practices |
| 24 | +- Pull request formatting requirements |
| 25 | + |
| 26 | +## Why Use Custom Rules? |
| 27 | + |
| 28 | +Custom rules help Open SWE: |
| 29 | + |
| 30 | +- Follow your project's specific conventions |
| 31 | +- Understand your codebase architecture |
| 32 | +- Use the correct package managers and tools |
| 33 | +- Write tests that match your testing patterns |
| 34 | +- Generate properly formatted pull requests |
| 35 | + |
| 36 | +Without custom rules, Open SWE uses generic best practices that may not align with your project. |
| 37 | + |
| 38 | +## Supported Sections |
| 39 | + |
| 40 | +### `<general_rules>` |
| 41 | + |
| 42 | +Project-specific coding standards and conventions: |
| 43 | + |
| 44 | +- Package manager preferences (e.g., "Always use Yarn") |
| 45 | +- Code style requirements |
| 46 | +- Import/export patterns |
| 47 | +- Architectural guidelines |
| 48 | +- Common scripts, and how to run them |
| 49 | + |
| 50 | +Example: "Run `yarn test` to run tests", or "Run `yarn build` to build the project" |
| 51 | + |
| 52 | +### `<repository_structure>` |
| 53 | + |
| 54 | +Description of your codebase organization: |
| 55 | + |
| 56 | +- Monorepo vs single package structure |
| 57 | +- Key directories and their purposes |
| 58 | +- Package relationships and dependencies |
| 59 | +- Build system configuration |
| 60 | + |
| 61 | +Include context about where/how to create new files, apps, packages, etc. in this section. |
| 62 | + |
| 63 | +Example: "When creating new packages, place them inside the `packages` directory." |
| 64 | + |
| 65 | +### `<dependencies_and_installation>` |
| 66 | + |
| 67 | +Package management and setup instructions: |
| 68 | + |
| 69 | +- Package manager commands |
| 70 | +- Installation procedures |
| 71 | +- Key dependencies and their purposes |
| 72 | +- Workspace configuration details |
| 73 | + |
| 74 | +This section should include information about the package manager(s) used in the project, and how/where to install dependencies. |
| 75 | + |
| 76 | +Example: "Always install dependencies inside the specific app/package where they're used, never in the root `package.json` unless adding a resolution." |
| 77 | + |
| 78 | +### `<testing_instructions>` |
| 79 | + |
| 80 | +Testing framework and practices: |
| 81 | + |
| 82 | +- Test runner configuration (Jest, Vitest, etc.) |
| 83 | +- Test file naming conventions |
| 84 | +- How to run different test types |
| 85 | +- Testing best practices for your project (e.g. what types of tests to write) |
| 86 | + |
| 87 | +Example: "Always run `yarn test` after making changes." |
| 88 | + |
| 89 | +### `<pull_request_formatting>` |
| 90 | + |
| 91 | +PR creation and formatting guidelines: |
| 92 | + |
| 93 | +- Title and description templates |
| 94 | +- Required sections or checklists |
| 95 | +- Review process requirements |
| 96 | +- Linking conventions |
| 97 | + |
| 98 | +Example: "The pull request body should include a `Testing Steps` section which includes bullet points describing how to test the changes." |
| 99 | + |
| 100 | +## File Names |
| 101 | + |
| 102 | +Open SWE reads custom rules from these files (in order of precedence): |
| 103 | + |
| 104 | +1. `AGENTS.md` (recommended) |
| 105 | +2. `AGENT.md` |
| 106 | +3. `CLAUDE.md` |
| 107 | +4. `CURSOR.md` |
| 108 | + |
| 109 | +<Note> |
| 110 | + Use `AGENTS.md` as the standard filename for consistency across projects. |
| 111 | +</Note> |
| 112 | + |
| 113 | +## Missing Sections |
| 114 | + |
| 115 | +If your custom rules file doesn't include XML section tags, the entire file content will be passed to the prompt inside a custom rules section. |
| 116 | + |
| 117 | +## Formatting Example |
| 118 | + |
| 119 | +If your custom rules file does include the proper XML section tags, only the content from inside the known tags will be passed to the system prompt. |
| 120 | + |
| 121 | +Known tags: |
| 122 | +- `<general_rules>` |
| 123 | +- `<repository_structure>` |
| 124 | +- `<dependencies_and_installation>` |
| 125 | +- `<testing_instructions>` |
| 126 | +- `<pull_request_formatting>` |
| 127 | + |
| 128 | +Each tag _must_ contain a proper closing tag. If a tag is missing a closing tag, the entire file content will be passed to the prompt inside a custom rules section. |
| 129 | + |
| 130 | +Here is an example showing what your `AGENTS.md` file should look like: |
| 131 | + |
| 132 | +```markdown |
| 133 | +<general_rules> |
| 134 | + |
| 135 | +- Always use Yarn as the package manager |
| 136 | +- Follow strict TypeScript practices |
| 137 | +- Use ESLint and Prettier for code quality |
| 138 | + </general_rules> |
| 139 | + |
| 140 | +<repository_structure> |
| 141 | +This is a Yarn workspace monorepo with three main packages: |
| 142 | + |
| 143 | +- apps/web: Next.js frontend |
| 144 | +- apps/api: Express backend |
| 145 | +- packages/shared: Common utilities |
| 146 | + </repository_structure> |
| 147 | + |
| 148 | +<dependencies_and_installation> |
| 149 | +Run `yarn install` from the repository root to install all dependencies. |
| 150 | +Key dependencies include React 18, TypeScript, and Jest for testing. |
| 151 | +</dependencies_and_installation> |
| 152 | + |
| 153 | +<testing_instructions> |
| 154 | + |
| 155 | +- Run `yarn test` for unit tests |
| 156 | +- Run `yarn test:e2e` for end-to-end tests |
| 157 | +- Test files use `.test.ts` extension |
| 158 | +- Use Jest with React Testing Library |
| 159 | + </testing_instructions> |
| 160 | + |
| 161 | +<pull_request_formatting> |
| 162 | +PR titles should follow: "feat: description" or "fix: description" |
| 163 | +Include a brief description and link any related issues. |
| 164 | +</pull_request_formatting> |
| 165 | +``` |
0 commit comments