---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://sourcecraft.dev/portal/docs/en/code-assistant/operations/chat-rules.md
  - https://sourcecraft.dev/portal/docs/ru/code-assistant/operations/chat-rules.md
title: Custom rules in SourceCraft Code Assistant
description: How to create and use custom rules in SourceCraft Code Assistant to personalize your assistant behavior.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Custom rules in SourceCraft Code Assistant

<!-- source: en/_includes/code-assistant/only-in-vscode.md -->
{% note warning %}

This feature is only available in Visual Studio Code.

{% endnote %}
<!-- endsource: en/_includes/code-assistant/only-in-vscode.md -->

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 {#rules-location}

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 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M3 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3M9.5 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m5 0a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0" clip-rule="evenodd"/></svg> in the top panel and selecting **Modes**.

### Global rules directory {#global-rules-location}

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 {#workspace-rules-location}

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

* The `.codeassistant/rules/` directory is the preferred method:

  ```text
  .
  ├── .codeassistant/
  │   └── rules/ # Workspace-wide rules
  │       ├── 01-general.md
  │       └── 02-coding-style.txt
  └── ... (other project files)
  ```

* Alternatively, use the `.codeassistantrules` file:

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

### Mode-specific rules {#mode-rules-location}

Rules in these locations apply only to a specific [mode](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/chat-prompts.md), e.g., `code`.

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

  ```text
  .
  ├── .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:

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

Rules are uploaded in the following order: global rules first, then workspace rules. Workspace rules can override global rules.

## Setting global custom rules {#install-global-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 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M3 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3M9.5 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m5 0a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0" clip-rule="evenodd"/></svg> and select **Modes**.
1. Under **Custom Instructions for All Modes**, enter your rules.

## How rules are merged {#how-rules-are-merged}

Provide your rules in a system prompt formatted as follows:

```text
====
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 info %}

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.

{% endnote %}

#### Useful links {#see-also}

* [Skills in SourceCraft Code Assistant](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/agent/skills.md)
* [Slash (/) commands in SourceCraft Code Assistant](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/agent/slash-commands.md)
* [Using modes in SourceCraft Code Assistant](https://sourcecraft.dev/portal/docs/en/code-assistant/operations/chat-prompts.md)