Skip to content

Project Rules

Project rules let you define project-specific instructions that CodeBuddy follows in every conversation. The ProjectRulesService loads rules at workspace open, watches for file changes, and injects them into the agent’s system prompt.

Create a .codebuddy/rules.md file in your project root:

# Project Rules
## Code Style
- Use TypeScript strict mode
- Prefer `const` over `let`
- Use named exports, not default exports
- Maximum line length: 100 characters
## Testing
- Write tests for every new function
- Use Vitest for unit tests
- Minimum 80% code coverage for new code
## Dependencies
- Use pnpm as the package manager
- Prefer well-maintained packages with >1000 weekly downloads
- Always pin dependency versions
## Architecture
- Follow the repository pattern for data access
- Use Zod for all input validation
- Keep controllers thin — business logic goes in services

The ProjectRulesService checks four locations in order, using the first one found:

PriorityPathDescription
1.codebuddy/rules.mdPrimary location
2.codebuddy/rules/index.mdAlternative for complex rule sets
3.codebuddyrulesRoot-level single file
4CODEBUDDY.mdConvention-based (similar to CONTRIBUTING.md)

Rules are injected into the system prompt, so they consume context window tokens. To prevent rules from crowding out working context:

  • Default budget: 2,000 tokens (~8,000 characters)
  • Configurable: codebuddy.rules.maxTokens setting
  • Truncation: If rules exceed the budget, they are truncated with a warning

When CodeBuddy starts a new conversation in your project:

  1. ProjectRulesService reads the rules file
  2. Rules are appended to the Developer Agent’s system prompt under a ## Project Rules section
  3. The agent follows these rules for all code generation, tool use, and decisions.
  4. Rules can also be merged with custom rules from the codebuddy.rules.customRules setting

Changes to the rules file are detected automatically — no need to restart the editor.

For monorepos, define rules at different levels:

my-monorepo/
.codebuddy/rules.md ← applies to the whole repo
packages/
frontend/
.codebuddy/rules.md ← overrides for frontend
backend/
.codebuddy/rules.md ← overrides for backend
SettingTypeDefaultDescription
codebuddy.rules.enabledbooleantrueEnable project rules loading
codebuddy.rules.maxTokensnumber2000Maximum token budget for rules
codebuddy.rules.showIndicatorbooleantrueShow rules status in the UI
codebuddy.rules.customRulesstring""Additional rules from editor settings (merged with file-based rules)
  • Be specific — “Use Zod for validation” is better than “Validate inputs”
  • Include examples when conventions are nuanced
  • Keep rules concise — They’re loaded into every conversation
  • Update rules as your project evolves
  • Use categories (Code Style, Testing, Architecture) for readability