Skip to content

Mode-specific rules are applied to all agents instead of only the active agent #7507

@kilo-code-bot

Description

@kilo-code-bot

Problem

Mode-specific rule files (e.g. .kilocoderules-code, .kilo/rules-code/*.md) are loaded into the generic instructions array alongside non-mode-specific rules. This means all mode-tagged rules are injected into the system prompt for every agent, regardless of which agent/mode is currently active.

For example, if a project has:

  • .kilocoderules-code (rules for the code mode)
  • .kilocoderules-architect (rules for the architect mode)
  • .kilo/rules/general.md (generic rules)

All three files are included in the system prompt even when only the code agent is active. The architect-specific rules should not be present when running in code mode, and vice versa.

Additional issue: custom mode rules are never discovered

Custom modes defined in .kilocodemodes are not scanned for rule directories. The rule discovery logic uses a hardcoded KNOWN_MODES list (code, architect, ask, debug, orchestrator), so if a user defines a custom mode (e.g. translate) and creates a corresponding .kilo/rules-translate/ directory, those rules are silently ignored.

Expected behavior

  1. Mode-specific rules should only be injected into the system prompt for the matching active agent/mode. Generic rules (non-mode-tagged) should continue to apply to all agents.
  2. Custom modes defined in .kilocodemodes should have their rule directories discovered alongside the built-in modes, so that .kilo/rules-{custom-mode}/*.md and .kilocoderules-{custom-mode} files are properly loaded.

Steps to reproduce

  1. Create a project with mode-specific rules for multiple modes:
    .kilocoderules-code    -> "# Code-only rules"
    .kilocoderules-architect -> "# Architect-only rules"
    
  2. Start a session with the code agent
  3. Inspect the system prompt — both code and architect rules are present

For the custom mode issue:

  1. Define a custom mode translate in .kilocodemodes
  2. Create .kilo/rules-translate/glossary.md
  3. Start a session with the translate agent
  4. The glossary rules are never loaded

Related PR

#7478

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIKilo Code CLIbugSomething isn't working

    Type

    No type

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions