Custom rules in SourceCraft Code Assistant

Warning

This feature is only available in Visual Studio Code.

With custom rules, you can personalize Code Assistant behavior by providing specific instructions that shape responses, coding style, decision-making processes, documentation standards, testing requirements, workflow recommendations, and more.

Rule file locations

You can set custom rules via global rules, which apply to all projects, workspace rules, which are project-specific, or the chat interface by clicking in the top panel and selecting Modes.

Global rules directory

Rules from these directories automatically apply to all projects:

  • Linux/macOS: ~/.codeassistant/rules/ and ~/.codeassistant/rules-{modeSlug}/.
  • Windows: %USERPROFILE%\.codeassistant\rules\ and %USERPROFILE%\.codeassistant\rules-{modeSlug}\.

Workspace rules directory

Rules in these directories apply only to the current project and can override global rules.

  • The .codeassistant/rules/ directory is the preferred method:

    .
    ├── .codeassistant/
    │   └── rules/ # Workspace-wide rules
    │       ├── 01-general.md
    │       └── 02-coding-style.txt
    └── ... (other project files)
    
  • Alternatively, use the .codeassistantrules file:

    .
    ├── .codeassistantrules # Single file containing all workspace rules
    └── ... (other project files)
    

Mode-specific rules

Rules in these locations apply only to a specific mode, e.g., code.

  • The .codeassistant/rules-{modeSlug}/ directory is the preferred method:

    .
    ├── .codeassistant/
    │   └── rules-code/ # Rules for the `code` mode
    │       ├── 01-js-style.md
    │       └── 02-ts-style.md
    └── ... (other project files)
    
  • Alternatively, use the .codeassistantrules-{modeSlug} file:

    .
    ├── .codeassistantrules-code # Single file containing all rules for the `code` mode
    └── ... (other project files)
    

Remember to upload rules in the following order: global rules first, then workspace rules. Workspace rules can override global rules.

Setting global custom rules

These rules apply to all workspaces and maintain your preferences regardless of which project you are working on.

  1. In the chat's top panel, click and select Modes.
  2. Under Custom Instructions for All Modes, enter your rules.

How rules are merged

Provide your rules in a system prompt formatted as follows:

====
CUSTOM RULES

These additional rules have been provided by the user for you to follow to the best of your ability and in compliance with tool usage rules.

Preferred language:
[Preferred language, if set]

Global rules:
[Global rules from the Modes tab]

Mode-specific rules:
[Mode-specific rules from the Modes tab]

Rules:

# Rules from rules-{modeSlug} directories:
[Contents of ALL files from ~/.codeassistant/rules-{modeSlug}/ AND .codeassistant/rules-{modeSlug}/, if they exist]

# Rules from .codeassistantrules-{modeSlug}:
[Contents of the .codeassistantrules-{modeSlug} file, only if no files exist in the mode-specific rules directories]

# Rules from .codeassistantignore:
[Rules related to .codeassistantignore, if applicable]

# Standard for agent rules (AGENTS.md):
[Contents of AGENTS.md or AGENT.md from the workspace root, if present and enabled]

# Rules from rules directories:
[Contents of ALL files from ~/.codeassistant/rules/ AND .codeassistant/rules/, if they exist]

# Rules from .codeassistantrules:
[Contents of the .codeassistantrules file, only if no files exist in the general rules directories]
====

Note

The system uploads rules from all applicable directories, both global (~/.codeassistant/) and workspace-specific (.codeassistant/), not just the first one containing files. Mode-specific rules precede general rules. Directories have priority over fallback files only when selecting the method; the system reads all applicable directories.