Legion CLI assembles system prompts from multiple sources to provide comprehensive context to the AI model.
The system prompt is built in src/session/system.ts and src/session/llm/request.ts:
┌─────────────────────────────────────┐
│ 1. Soul (identity & personality) │ src/kilocode/soul.txt
├─────────────────────────────────────┤
│ 2. Brain (behavioral rules) │ src/kilocode/brain.txt
├─────────────────────────────────────┤
│ 3. Provider prompt │ src/session/prompt/*.txt
├─────────────────────────────────────┤
│ 4. Memory (LEGION.md + session) │ src/kilocode/memory/
├─────────────────────────────────────┤
│ 5. Environment (context info) │ src/kilocode/system-prompt.ts
├─────────────────────────────────────┤
│ 6. Skills (available skills) │ src/skill/
├─────────────────────────────────────┤
│ 7. ELC Rules (language-specific) │ src/kilocode/elc/rules.ts
├─────────────────────────────────────┤
│ 8. Context Rules (lazy senior dev) │ src/kilocode/context/rules.ts
├─────────────────────────────────────┤
│ 9. User/system instructions │ From config and user input
└─────────────────────────────────────┘
src/kilocode/soul.txt)Core identity and personality. Defines who the AI is and its fundamental behavior.
src/kilocode/brain.txt)Behavioral rules and safety guidelines. Controls how the AI operates, what it can/cannot do, and safety constraints.
src/session/prompt/*.txt)Model-specific prompts optimized for different providers:
| File | Target |
|---|---|
anthropic.txt |
Anthropic Claude models |
gpt.txt |
OpenAI GPT models |
gemini.txt |
Google Gemini models |
codex.txt |
Codex models |
beast.txt |
High-capability models |
ling.txt |
Ling models |
kimi.txt |
Kimi models |
kilocode-gpt-5.5.txt |
GPT-5.5 specific |
copilot-gpt-5.txt |
Copilot GPT-5 |
trinity.txt |
Trinity models |
default.txt |
Fallback default |
src/kilocode/memory/)Project-specific context loaded from:
LEGION.md in project root~/.legion/LEGION.md (global)~/.legion/legion-memory.jsonsrc/kilocode/system-prompt.ts)Runtime context injected automatically:
src/kilocode/elc/rules.ts)Language-specific coding rules from Everything Legion Code:
src/kilocode/context/rules.ts)Lazy senior dev mode rules for efficient coding patterns.
You are Legion, a highly skilled software engineer...
Contains behavioral rules, safety guidelines, tool usage policies, and coding conventions.
Model-specific instructions optimized for each AI provider’s strengths and limitations.
# Project Memory
The following memory has been loaded from LEGION.md and session memory.
Use this context to inform your responses about project conventions...
# LEGION.md content
...
Create LEGION.md in project root:
# Project Conventions
- Use TypeScript strict mode
- Follow Airbnb style guide
- All functions must have JSDoc comments
Create ~/.legion/LEGION.md:
# Global Preferences
- Prefer functional programming
- Use async/await over callbacks
- Always handle errors explicitly
The system automatically selects the appropriate provider prompt based on the model being used.