Recursive Language Model (RLM) Skill
Core Philosophy
"Context is an external resource, not a local variable."
When this skill is active, you are the Root Node of a Recursive Language Model system. Your job is NOT to read code, but to write programs (plans) that orchestrate sub-agents to read code.
Protocol: The RLM Loop
Phase 1: Choose Your Engine
Decide based on the nature of the data:
| Engine |
Use Case |
Tool |
| Native Mode |
General codebase traversal, finding files, structure. |
find, grep, bash |
| Strict Mode |
Dense data analysis (logs, CSVs, massive single files). |
python3 ~/.claude/skills/rlm/rlm.py |
Phase 2: Index & Filter (The "Peeking" Phase)
Goal: Identify relevant data without loading it.
- Native: Use
find or grep -l.
- Strict: Use
python3 .../rlm.py peek "query".
- RLM Pattern: Grepping for import statements, class names, or definitions to build a list of relevant paths.
Phase 3: Parallel Map (The "Sub-Query" Phase)
Goal: Process chunks in parallel using fresh contexts.
- Divide: Split the work into atomic units.
- Strict Mode:
python3 .../rlm.py chunk --pattern "*.log" -> Returns JSON chunks.
- Spawn: Use
background_task to launch parallel agents.
- Constraint: Launch at least 3-5 agents in parallel for broad tasks.
- Prompting: Give each background agent ONE specific chunk or file path.
- Format:
background_task(agent="explore", prompt="Analyze chunk #5 of big.log: {content}...")
Phase 4: Reduce & Synthesize (The "Aggregation" Phase)
Goal: Combine results into a coherent answer.
- Collect: Read the outputs from
background_task (via background_output).
- Synthesize: Look for patterns, consensus, or specific answers in the aggregated data.
- Refine: If the answer is incomplete, perform a second RLM recursion on the specific missing pieces.
Critical Instructions
- NEVER use
cat * or read more than 3-5 files into your main context at once.
- ALWAYS prefer
background_task for reading/analyzing file contents when the file count > 1.
- Use
rlm.py for programmatic slicing of large files that grep can't handle well.
- Python is your Memory: If you need to track state across 50 files, write a Python script (or use
rlm.py) to scan them and output a summary.
Example Workflow: "Find all API endpoints and check for Auth"
Wrong Way (Monolithic):
read src/api/routes.ts
read src/api/users.ts
- ... (Context fills up, reasoning degrades)
RLM Way (Recursive):
- Filter:
grep -l "@Controller" src/**/*.ts -> Returns 20 files.
- Map:
background_task(prompt="Read src/api/routes.ts. Extract all endpoints and their @Auth decorators.")
background_task(prompt="Read src/api/users.ts. Extract all endpoints and their @Auth decorators.")
- ... (Launch all 20)
- Reduce:
- Collect all 20 outputs.
- Compile into a single table.
- Identify missing auth.
Recovery Mode
If background_task is unavailable or fails:
- Fall back to Iterative Python Scripting.
- Write a Python script that loads each file, runs a regex/AST check, and prints the result to stdout.
- Read the script's stdout.
What Claude Does vs What You Decide
| Claude handles |
You provide |
| Orchestrating parallel agents |
Initial query and success criteria |
| Chunking large files for processing |
Judgment on result quality |
| Synthesizing results from subagents |
Final interpretation and action |
| Writing filtering scripts |
Validation of completeness |
| Managing context isolation |
Decision on when to stop recursing |
Skill Boundaries
This skill excels for:
- Codebases with >100 files
- Finding patterns across many files
- Audit tasks (security, auth, logging)
- Large file analysis (logs, data dumps)
This skill is NOT ideal for:
- Small projects (<50 files) → Direct reading faster
- Single file analysis → Overkill
- Tasks requiring file modification → Use different approach
Skill Metadata
name: rlm
category: meta
version: 2.0
author: GUIA
source_expert: Recursive Language Model pattern
difficulty: advanced
mode: cyborg
tags: [rlm, large-codebase, parallel-agents, map-reduce, context-management]
created: 2026-02-03
updated: 2026-02-03
1---2name: rlm3description: Process large codebases (>100 files) using the Recursive Language Model pattern. Treats code as an external environment, using parallel background agents to map-reduce complex tasks without context rot.4license: MIT5---6
7# Recursive Language Model (RLM) Skill
8
9## Core Philosophy
10**"Context is an external resource, not a local variable."**
11
12When this skill is active, you are the **Root Node** of a Recursive Language Model system. Your job is NOT to read code, but to write programs (plans) that orchestrate sub-agents to read code.
13
14## Protocol: The RLM Loop
15
16### Phase 1: Choose Your Engine
17Decide based on the nature of the data:
18
19| Engine | Use Case | Tool |
20|--------|----------|------|
21| **Native Mode** | General codebase traversal, finding files, structure. | `find`, `grep`, `bash` |
22| **Strict Mode** | Dense data analysis (logs, CSVs, massive single files). | `python3 ~/.claude/skills/rlm/rlm.py` |
23
24### Phase 2: Index & Filter (The "Peeking" Phase)
25**Goal**: Identify relevant data without loading it.
261. **Native**: Use `find` or `grep -l`.
272. **Strict**: Use `python3 .../rlm.py peek "query"`.
28 * *RLM Pattern*: Grepping for import statements, class names, or definitions to build a list of relevant paths.
29
30### Phase 3: Parallel Map (The "Sub-Query" Phase)
31**Goal**: Process chunks in parallel using fresh contexts.
321. **Divide**: Split the work into atomic units.
33 - **Strict Mode**: `python3 .../rlm.py chunk --pattern "*.log"` -> Returns JSON chunks.
342. **Spawn**: Use `background_task` to launch parallel agents.
35 * *Constraint*: Launch at least 3-5 agents in parallel for broad tasks.
36 * *Prompting*: Give each background agent ONE specific chunk or file path.
37 * *Format*: `background_task(agent="explore", prompt="Analyze chunk #5 of big.log: {content}...")`
38
39### Phase 4: Reduce & Synthesize (The "Aggregation" Phase)
40**Goal**: Combine results into a coherent answer.
411. **Collect**: Read the outputs from `background_task` (via `background_output`).
422. **Synthesize**: Look for patterns, consensus, or specific answers in the aggregated data.
433. **Refine**: If the answer is incomplete, perform a second RLM recursion on the specific missing pieces.
44
45## Critical Instructions
46
471. **NEVER** use `cat *` or read more than 3-5 files into your main context at once.
482. **ALWAYS** prefer `background_task` for reading/analyzing file contents when the file count > 1.
493. **Use `rlm.py`** for programmatic slicing of large files that `grep` can't handle well.
504. **Python is your Memory**: If you need to track state across 50 files, write a Python script (or use `rlm.py`) to scan them and output a summary.
51
52## Example Workflow: "Find all API endpoints and check for Auth"
53
54**Wrong Way (Monolithic)**:
55- `read src/api/routes.ts`
56- `read src/api/users.ts`
57- ... (Context fills up, reasoning degrades)
58
59**RLM Way (Recursive)**:
601. **Filter**: `grep -l "@Controller" src/**/*.ts` -> Returns 20 files.
612. **Map**:
62 - `background_task(prompt="Read src/api/routes.ts. Extract all endpoints and their @Auth decorators.")`
63 - `background_task(prompt="Read src/api/users.ts. Extract all endpoints and their @Auth decorators.")`
64 - ... (Launch all 20)
653. **Reduce**:
66 - Collect all 20 outputs.
67 - Compile into a single table.
68 - Identify missing auth.
69
70## Recovery Mode
71If `background_task` is unavailable or fails:
721. Fall back to **Iterative Python Scripting**.
732. Write a Python script that loads each file, runs a regex/AST check, and prints the result to stdout.
743. Read the script's stdout.
75
76---
77
78## What Claude Does vs What You Decide
79
80| Claude handles | You provide |
81|---------------|-------------|
82| Orchestrating parallel agents | Initial query and success criteria |
83| Chunking large files for processing | Judgment on result quality |
84| Synthesizing results from subagents | Final interpretation and action |
85| Writing filtering scripts | Validation of completeness |
86| Managing context isolation | Decision on when to stop recursing |
87
88---
89
90## Skill Boundaries
91
92### This skill excels for:
93- Codebases with >100 files
94- Finding patterns across many files
95- Audit tasks (security, auth, logging)
96- Large file analysis (logs, data dumps)
97
98### This skill is NOT ideal for:
99- Small projects (<50 files) → Direct reading faster
100- Single file analysis → Overkill
101- Tasks requiring file modification → Use different approach
102
103---
104
105## Skill Metadata
106
107```yaml
108name: rlm
109category: meta
110version: 2.0
111author: GUIA
112source_expert: Recursive Language Model pattern
113difficulty: advanced
114mode: cyborg
115tags: [rlm, large-codebase, parallel-agents, map-reduce, context-management]
116created: 2026-02-03
117updated: 2026-02-03
118```