This document explains how custom modes are implemented in Roo Code, covering both the user experience and the technical implementation details.
Custom modes in Roo Code allow you to define specialized versions of the AI assistant with specific capabilities, permissions, and behaviors. Each mode serves a particular purpose and has access to different tools.
Roo Code includes several built-in modes:
- Code (default): Full-featured development mode with access to all tools
- Architect: Planning and diagramming mode (limited to editing markdown files)
- Ask: Question-answering mode without code modification capabilities
- Debug: Specialized mode for systematic problem diagnosis and resolution
Custom modes can be configured in two ways:
- Global Custom Modes: Available across all workspaces
- Project-Specific Custom Modes: Configured for a specific project
Global modes are stored in:
~/.roo/settings/custom_modes.json
Project modes are stored in:
.roomodes
(In the root directory of your workspace)
When modes with the same slug exist in both files, the project-specific version takes precedence. This allows projects to override global modes or define project-specific modes.
Both configuration files follow this JSON structure:
{
"customModes": [
{
"slug": "designer",
"name": "Designer",
"roleDefinition": "You are Roo, a UI/UX expert specializing in design systems and frontend development. Your expertise includes:\n- Creating and maintaining design systems\n- Implementing responsive and accessible web interfaces\n- Working with CSS, HTML, and modern frontend frameworks\n- Ensuring consistent user experiences across platforms",
"groups": [
"read",
"edit",
"browser",
"command"
],
"customInstructions": "Additional instructions for the Designer mode"
}
]
}
- slug: A unique identifier (lowercase letters, numbers, and hyphens)
- name: Display name for the mode
- roleDefinition: Detailed description of the mode's role and capabilities
- groups: Array of allowed tool groups (determines capabilities)
The customInstructions field is optional.
Each mode can be configured with access to specific tool groups:
- read: File reading operations (read_file, search_files, etc.)
- edit: File modification operations (write_to_file, apply_diff)
- browser: Web browsing capabilities
- command: System command execution
- mcp: Model Context Protocol tools
- modes: Tools for mode management
You can restrict which files a mode can edit by configuring the edit group with a regex pattern:
["edit", { "fileRegex": "\\.md$", "description": "Markdown files only" }]
This example restricts the mode to only edit files with the .md
extension (Markdown files).
The custom modes feature is implemented through several components:
The mode structure is defined in shared/modes.ts
and validated using Zod schemas in schemas/index.ts
. The ModeConfig
interface includes:
interface ModeConfig {
slug: string;
name: string;
roleDefinition: string;
customInstructions?: string;
groups: GroupEntry[];
source?: "global" | "project";
}
The CustomModesManager
class (in core/config/CustomModesManager.ts
) manages:
- Loading custom modes from both global and project-specific files
- Merging modes with proper precedence (project overrides global)
- Updating and deleting modes
- Watching for file changes to reload configurations
The isToolAllowedForMode
function in shared/modes.ts
enforces permissions:
export function isToolAllowedForMode(
tool: string,
modeSlug: string,
customModes: ModeConfig[],
toolRequirements?: Record<string, boolean>,
toolParams?: Record<string, any>,
): boolean {
// Implementation checking if the tool is allowed
// for the specified mode
}
This function throws a FileRestrictionError
when a file operation violates mode constraints.
Mode switching is handled through:
- The
switchModeTool
allowing the AI to request a mode switch - The
handleModeSwitch
method in theClineProvider
class
When a mode is activated, the system generates a custom prompt combining:
- The mode's role definition
- Custom instructions
- Mode-specific rules from
.roo/rules-{mode}/
or.roorules-{mode}
- Mode-specific system prompt file overrides everything
- Project-specific modes override global modes
- Custom mode prompts override built-in mode definitions
- Built-in modes provide the base configuration
- Be Specific: Define clear, focused roles for each mode
- Use File Restrictions: Limit editing capabilities to prevent unintended changes
- Custom Instructions: Include detailed instructions for complex behaviors
- Use
.roomodes
for project-specific configurations - Include it in version control to share with team members
- Override global modes to customize behavior for specific projects
- Let the AI recommend mode switches when appropriate
- Use the appropriate mode for the task at hand:
- Architect for planning
- Code for implementation
- Ask for information retrieval
- Debug for troubleshooting
- Mode configurations are loaded from both global and project settings
- Configurations are merged with project settings taking precedence
- When a mode is selected, the appropriate tools are enabled/disabled
- File operations are checked against mode restrictions
- The system prompt is regenerated to reflect the current mode
This architecture provides a flexible system for users to define different AI assistant personas with specific capabilities, making Roo Code adaptable to different workflows and project requirements.