Context mode provides a “lazy senior dev” approach to coding - minimal instructions, maximum efficiency.
Context mode follows these principles:
Context rules are injected into the system prompt:
# Context Rules
## Minimal Changes
- Only modify files directly related to the task
- Preserve existing code style
- Don't refactor unless asked
## Pattern Recognition
- Follow existing project patterns
- Use similar implementations as reference
- Maintain consistency
## Smart Defaults
- Use project's existing dependencies
- Follow established architecture
- Respect naming conventions
Context mode is automatically active. The AI will:
# Instead of creating new patterns
legion run "add user profile page"
# Context mode will:
# 1. Look at existing pages
# 2. Follow same structure
# 3. Use same components
# 4. Maintain same style
# Minimal fix approach
legion run "fix login validation bug"
# Context mode will:
# 1. Find the bug location
# 2. Understand the context
# 3. Apply minimal fix
# 4. Don't refactor surrounding code
Context settings in legion.json:
{
"context": {
"enabled": true,
"intensity": "normal",
"preserveStyle": true,
"minimalChanges": true
}
}
| Level | Description |
|---|---|
light |
Basic pattern following |
normal |
Standard context awareness |
deep |
Thorough analysis before changes |
Context mode integrates with:
// AI might create new patterns
export function authenticateUser(credentials: any) {
// New, inconsistent implementation
}
// AI follows existing patterns
export function authenticateUser(credentials: LoginCredentials): Promise<User> {
// Consistent with existing auth module
}
Project: React + TypeScript + Tailwind
Context Mode will:
- Use functional components with hooks
- Follow existing naming patterns
- Use same state management approach
- Maintain consistent styling
Project: Vanilla JS
Context Mode will:
- Infer patterns from existing code
- Follow file structure
- Use similar coding style
- Maintain consistency
Add to .legion/context-rules.md:
# Custom Context Rules
## Our Conventions
- Always use named exports
- Prefer composition over inheritance
- Error boundaries around all forms
- Memo expensive calculations
{
"context": {
"intensity": "deep",
"customRules": true,
"preserveStyle": false
}
}