Project Rules
Define project-specific instructions in .codebuddy/rules.md. CodeBuddy loads them at workspace open, watches for changes, injects them into the Developer Agent’s system prompt in every conversation.
Supports dynamic values via {{js: EXPRESSION}} fragments (e.g. Current branch: {{js: host.gitBranch()}}) — see Sandboxed Scripts for the host bindings you can call.
Example .codebuddy/rules.md
Section titled “Example .codebuddy/rules.md”# Project rules
## Code style
- TypeScript strict mode- Prefer `const` over `let`- Named exports, not default exports- 100-char line max
## Testing
- Write tests for every new function- Vitest for unit tests- ≥ 80% coverage on new code
## Dependencies
- Use pnpm- Prefer well-maintained packages (> 1000 weekly downloads)- Pin dep versions
## Architecture
- Repository pattern for data access- Zod for all input validation- Keep controllers thin — business logic in servicesDiscovery order
Section titled “Discovery order”ProjectRulesService checks 4 locations, first one found wins:
| Priority | Path | Purpose |
|---|---|---|
| 1 | .codebuddy/rules.md | Primary location |
| 2 | .codebuddy/rules/index.md | Alternative for complex rule sets |
| 3 | .codebuddyrules | Root-level single file |
| 4 | CODEBUDDY.md | Convention-based |
Token budget
Section titled “Token budget”Rules go into the system prompt → they consume context window.
- Default budget: 2000 tokens (~8000 chars)
- Configurable:
codebuddy.rules.maxTokens - Truncation: if rules exceed the budget, truncated with a warning
How rules flow
Section titled “How rules flow”Each new conversation:
ProjectRulesServicereads the rules file.{{js:}}fragments expanded via the QuickJS pipeline (workspace context, git branch, glob results, etc.).- Rules appended to the system prompt under a
## Project rulessection. - Agent follows them for code generation, tool selection, and decisions.
- Custom rules from the
rules.customRulessetting (an array) are merged in.
Changes to the file are detected automatically — no editor restart.
Monorepo support
Section titled “Monorepo support”Rules at different levels:
my-monorepo/ .codebuddy/rules.md ← whole-repo default packages/ frontend/ .codebuddy/rules.md ← frontend overrides backend/ .codebuddy/rules.md ← backend overridesThe closest file to the active file wins.
Settings
Section titled “Settings”| Setting | Default | Purpose |
|---|---|---|
codebuddy.rules.enabled | true | Enable rules loading |
codebuddy.rules.maxTokens | 2000 | Token budget |
codebuddy.rules.showIndicator | true | Show rules status in the UI |
rules.customRules | [] | Extra rules (array) appended to the system prompt, merged with file rules |
Writing tips
Section titled “Writing tips”- Be specific. “Use Zod for validation” > “Validate inputs”.
- Include examples for nuanced conventions.
- Keep concise — every rule costs context tokens.
- Categorize (Code Style / Testing / Architecture) for scannability.
- Update as the project evolves — stale rules mislead the agent.
Related
Section titled “Related”- Skills — for capability-based conventions rather than free-form rules
- Context system — where rules fit in the per-turn context budget