You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/settings/repo-rules.mdx
+68-3Lines changed: 68 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,10 @@ icon: "shield-check"
6
6
7
7
Repository Rules in Codegen act as a persistent set of instructions or a "system prompt" for the AI agent whenever it operates on a specific repository. These rules guide the agent's behavior by enforcing coding standards and repository-specific conventions through automated reminders to the language model (LLM) during each task.
8
8
9
+
Codegen supports two types of repository rules:
10
+
1.**Manual Repository Rules** - configured through the web interface
11
+
2.**Automatic Rule File Detection** - automatically discovered from your repository files
12
+
9
13
<Framecaption="Update repo rules at codegen.com/repos">
10
14
<imgsrc="/images/repo-rules.png" />
11
15
</Frame>
@@ -30,6 +34,69 @@ You can typically find and configure Repository Rules within the settings page f
30
34
31
35
In the text area provided (as shown in the image), you can specify any rules you want the agent to follow for this repository. Click "Save" to apply them.
32
36
37
+
## Automatic Rule File Detection
38
+
39
+
In addition to manual repository rules, Codegen automatically discovers and includes agent rule files from your repository when the agent starts working on it. This happens automatically whenever the `set_active_codebase` tool is used.
40
+
41
+
### Supported Rule File Patterns
42
+
43
+
Codegen automatically searches for the following types of rule files in your repository:
44
+
45
+
-**`.cursorrules`** - Cursor AI editor rules
46
+
-**`.clinerules`** - Cline AI assistant rules
47
+
-**`.windsurfrules`** - Windsurf AI editor rules
48
+
-**`**/*.mdc`** - Markdown files with `.mdc` extension anywhere in the repository
49
+
-**`.cursor/rules/**/*.mdc`** - Markdown files in the `.cursor/rules/` directory structure
50
+
51
+
### How Automatic Detection Works
52
+
53
+
1.**File Discovery**: When you switch to a repository, Codegen uses `ripgrep` to search for files matching the supported patterns
54
+
2.**Content Extraction**: The content of discovered files is read and processed
55
+
3.**Size Limitation**: All rule files combined are truncated to fit within 3,000 characters total to ensure optimal performance
56
+
4.**Context Integration**: The rule content is automatically included in the agent's context alongside any manual repository rules
57
+
58
+
### Example Rule Files
59
+
60
+
Here are examples of how you might structure automatic rule files in your repository:
61
+
62
+
**`.cursorrules` example:**
63
+
```
64
+
Use TypeScript for all new code
65
+
Follow the existing code style in the repository
66
+
Always add JSDoc comments for public functions
67
+
Prefer functional components over class components in React
68
+
```
69
+
70
+
**`.cursor/rules/backend.mdc` example:**
71
+
```markdown
72
+
# Backend Development Rules
73
+
74
+
## Database
75
+
- Use Prisma for database operations
76
+
- Always use transactions for multi-step operations
77
+
- Include proper error handling for all database calls
78
+
79
+
## API Design
80
+
- Follow REST conventions
81
+
- Use proper HTTP status codes
82
+
- Include request/response validation
83
+
```
84
+
85
+
### Benefits of Automatic Rule Files
86
+
87
+
-**Version Control**: Rule files are committed with your code, ensuring consistency across team members
88
+
-**Repository-Specific**: Different repositories can have different rule files without manual configuration
89
+
-**Developer-Friendly**: Developers can manage rules using familiar file-based workflows
90
+
-**Editor Integration**: Many AI-powered editors already support these file formats
91
+
92
+
<Tip>
93
+
Automatic rule files work alongside manual repository rules. Both types of rules are combined and provided to the agent for maximum context.
94
+
</Tip>
95
+
96
+
<Warning>
97
+
If your rule files exceed 3,000 characters combined, they will be automatically truncated. Consider keeping rule files concise or splitting them into multiple focused files.
98
+
</Warning>
99
+
33
100
## Common Use Cases and Examples
34
101
35
102
Repository rules are flexible and can be used for various purposes:
@@ -57,7 +124,5 @@ Repository rules are flexible and can be used for various purposes:
57
124
</Tip>
58
125
59
126
<Note>
60
-
Repository Rules are applied *in addition* to any global prompting strategies
61
-
or agent capabilities. They provide a repository-specific layer of
62
-
instruction.
127
+
Both manual repository rules and automatic rule files are applied *in addition* to any global prompting strategies or agent capabilities. They provide a repository-specific layer of instruction that helps ensure consistent behavior across your codebase.
0 commit comments