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: rlm
3description: 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.
4triggers:
5 - "analyze codebase"
6 - "scan all files"
7 - "large repository"
8 - "RLM"
9 - "find usage of X across the project"
10license: MIT
11metadata:
12 source: https://skillmd.com/skills/majiayu000/rlm
13 author: ClawFu
14 version: 1.0.0
15 mcp-server: "@clawfu/mcp-skills"
16---
17
18# Recursive Language Model (RLM) Skill
19
20## Core Philosophy
21**"Context is an external resource, not a local variable."**
22
23When 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.
24
25## Protocol: The RLM Loop
26
27### Phase 1: Choose Your Engine
28Decide based on the nature of the data:
29
30| Engine | Use Case | Tool |
31|--------|----------|------|
32| **Native Mode** | General codebase traversal, finding files, structure. | `find`, `grep`, `bash` |
33| **Strict Mode** | Dense data analysis (logs, CSVs, massive single files). | `python3 ~/.claude/skills/rlm/rlm.py` |
34
35### Phase 2: Index & Filter (The "Peeking" Phase)
36**Goal**: Identify relevant data without loading it.
371. **Native**: Use `find` or `grep -l`.
382. **Strict**: Use `python3 .../rlm.py peek "query"`.
39 * *RLM Pattern*: Grepping for import statements, class names, or definitions to build a list of relevant paths.
40
41### Phase 3: Parallel Map (The "Sub-Query" Phase)
42**Goal**: Process chunks in parallel using fresh contexts.
431. **Divide**: Split the work into atomic units.
44 - **Strict Mode**: `python3 .../rlm.py chunk --pattern "*.log"` -> Returns JSON chunks.
452. **Spawn**: Use `background_task` to launch parallel agents.
46 * *Constraint*: Launch at least 3-5 agents in parallel for broad tasks.
47 * *Prompting*: Give each background agent ONE specific chunk or file path.
48 * *Format*: `background_task(agent="explore", prompt="Analyze chunk #5 of big.log: {content}...")`
49
50### Phase 4: Reduce & Synthesize (The "Aggregation" Phase)
51**Goal**: Combine results into a coherent answer.
521. **Collect**: Read the outputs from `background_task` (via `background_output`).
532. **Synthesize**: Look for patterns, consensus, or specific answers in the aggregated data.
543. **Refine**: If the answer is incomplete, perform a second RLM recursion on the specific missing pieces.
55
56## Critical Instructions
57
581. **NEVER** use `cat *` or read more than 3-5 files into your main context at once.
592. **ALWAYS** prefer `background_task` for reading/analyzing file contents when the file count > 1.
603. **Use `rlm.py`** for programmatic slicing of large files that `grep` can't handle well.
614. **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.
62
63## Example Workflow: "Find all API endpoints and check for Auth"
64
65**Wrong Way (Monolithic)**:
66- `read src/api/routes.ts`
67- `read src/api/users.ts`
68- ... (Context fills up, reasoning degrades)
69
70**RLM Way (Recursive)**:
711. **Filter**: `grep -l "@Controller" src/**/*.ts` -> Returns 20 files.
722. **Map**:
73 - `background_task(prompt="Read src/api/routes.ts. Extract all endpoints and their @Auth decorators.")`
74 - `background_task(prompt="Read src/api/users.ts. Extract all endpoints and their @Auth decorators.")`
75 - ... (Launch all 20)
763. **Reduce**:
77 - Collect all 20 outputs.
78 - Compile into a single table.
79 - Identify missing auth.
80
81## Recovery Mode
82If `background_task` is unavailable or fails:
831. Fall back to **Iterative Python Scripting**.
842. Write a Python script that loads each file, runs a regex/AST check, and prints the result to stdout.
853. Read the script's stdout.
86
87---
88
89## What Claude Does vs What You Decide
90
91| Claude handles | You provide |
92|---------------|-------------|
93| Orchestrating parallel agents | Initial query and success criteria |
94| Chunking large files for processing | Judgment on result quality |
95| Synthesizing results from subagents | Final interpretation and action |
96| Writing filtering scripts | Validation of completeness |
97| Managing context isolation | Decision on when to stop recursing |
98
99---
100
101## Skill Boundaries
102
103### This skill excels for:
104- Codebases with >100 files
105- Finding patterns across many files
106- Audit tasks (security, auth, logging)
107- Large file analysis (logs, data dumps)
108
109### This skill is NOT ideal for:
110- Small projects (<50 files) → Direct reading faster
111- Single file analysis → Overkill
112- Tasks requiring file modification → Use different approach
113
114---
115
116## Skill Metadata
117
118```yaml
119name: rlm
120category: meta
121version: 2.0
122author: GUIA
123source_expert: Recursive Language Model pattern
124difficulty: advanced
125mode: cyborg
126tags: [rlm, large-codebase, parallel-agents, map-reduce, context-management]
127created: 2026-02-03
128updated: 2026-02-03
129```