Recursive Language Model (RLM) Skill
Adapted from the RLM skill by BowTiedSwan
for the Claude Code CLI environment.
License notice: The original repository does not specify a license.
This adaptation is provided with attribution; upstream licensing status is unresolved.
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 every file yourself, but to orchestrate sub-agents that read code
in parallel and report back summaries.
Protocol: The RLM Loop
Phase 1: Choose Your Engine
| Engine |
Use Case |
Tool |
| Native Mode |
General codebase traversal, finding files, structure. |
Glob, Grep, Bash |
| Strict Mode |
Dense data analysis (logs, CSVs, massive single files). |
python3 ~/.claude/skills/rlm/scripts/rlm.py |
Phase 2: Index & Filter (The "Peeking" Phase)
Goal: Identify relevant data without loading it into your main context.
- Native: Use
Glob for file patterns, Grep with output_mode: "files_with_matches" for content.
- Strict: Use
python3 ~/.claude/skills/rlm/scripts/rlm.py peek "query".
Phase 3: Parallel Map (The "Sub-Query" Phase)
Goal: Process chunks in parallel using fresh agent contexts.
- Divide: Split the work into atomic units (one file or chunk per agent).
- Strict Mode:
python3 ~/.claude/skills/rlm/scripts/rlm.py chunk --pattern "*.log" -> JSON chunks.
- Spawn: Use the Task tool to launch parallel sub-agents.
- Launch 3-5+ agents in parallel for broad tasks.
- Give each agent one specific file or chunk and a focused question.
- Use
subagent_type="Explore" for read-only analysis, subagent_type="general-purpose" if the agent needs to write.
- Set
run_in_background=true for true parallelism.
Example — launch in a single message with multiple Task tool calls:
Task(subagent_type="Explore", run_in_background=true,
prompt="Read src/api/routes.ts. Extract all endpoints and their @Auth decorators.")
Task(subagent_type="Explore", run_in_background=true,
prompt="Read src/api/users.ts. Extract all endpoints and their @Auth decorators.")
...
Phase 4: Reduce & Synthesize (The "Aggregation" Phase)
Goal: Combine results into a coherent answer.
- Collect: Read background agent outputs via the
Read tool on output_file paths,
or use TaskOutput to retrieve results.
- 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 missing pieces.
Critical Instructions
- NEVER read more than 3-5 files into your main context at once.
- ALWAYS prefer the Task tool for reading/analyzing files when 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, then src/api/users.ts, then ... (context fills up, reasoning degrades)
RLM Way (Recursive):
- Filter:
Grep(pattern="@Controller", output_mode="files_with_matches") -> 20 files.
- Map: Launch 20 Task agents in parallel (background), each extracting endpoints + auth decorators from one file.
- Reduce: Collect all 20 outputs. Compile into a single table. Identify missing auth.
Recovery Mode
If Task tool agents are unavailable or failing:
- Fall back to Iterative Python Scripting.
- Write a Python script that loads each file, runs a regex/AST check, and prints results to stdout.
- Read the script's stdout via Bash.
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. Use when asked to "analyze codebase", "scan all files", deal with a "large repository", or "find usage of X across the project".4---56# Recursive Language Model (RLM) Skill78> Adapted from the [RLM skill by BowTiedSwan](https://github.com/BowTiedSwan/rlm-skill)9> for the Claude Code CLI environment.10>11> **License notice:** The original repository does not specify a license.12> This adaptation is provided with attribution; upstream licensing status is unresolved.1314## Core Philosophy1516**"Context is an external resource, not a local variable."**1718When this skill is active, you are the **Root Node** of a Recursive Language Model system.19Your job is NOT to read every file yourself, but to orchestrate sub-agents that read code20in parallel and report back summaries.2122## Protocol: The RLM Loop2324### Phase 1: Choose Your Engine2526| Engine | Use Case | Tool |27| --------------- | ------------------------------------------------------- | ------------------------------------------------------- |28| **Native Mode** | General codebase traversal, finding files, structure. | `Glob`, `Grep`, `Bash` |29| **Strict Mode** | Dense data analysis (logs, CSVs, massive single files). | `python3 ~/.claude/skills/rlm/scripts/rlm.py` |3031### Phase 2: Index & Filter (The "Peeking" Phase)3233**Goal**: Identify relevant data without loading it into your main context.34351. **Native**: Use `Glob` for file patterns, `Grep` with `output_mode: "files_with_matches"` for content.362. **Strict**: Use `python3 ~/.claude/skills/rlm/scripts/rlm.py peek "query"`.3738### Phase 3: Parallel Map (The "Sub-Query" Phase)3940**Goal**: Process chunks in parallel using fresh agent contexts.41421. **Divide**: Split the work into atomic units (one file or chunk per agent).43 - **Strict Mode**: `python3 ~/.claude/skills/rlm/scripts/rlm.py chunk --pattern "*.log"` -> JSON chunks.442. **Spawn**: Use the **Task tool** to launch parallel sub-agents.45 - Launch 3-5+ agents in parallel for broad tasks.46 - Give each agent **one specific file or chunk** and a focused question.47 - Use `subagent_type="Explore"` for read-only analysis, `subagent_type="general-purpose"` if the agent needs to write.48 - Set `run_in_background=true` for true parallelism.4950```51Example — launch in a single message with multiple Task tool calls:5253Task(subagent_type="Explore", run_in_background=true,54 prompt="Read src/api/routes.ts. Extract all endpoints and their @Auth decorators.")55Task(subagent_type="Explore", run_in_background=true,56 prompt="Read src/api/users.ts. Extract all endpoints and their @Auth decorators.")57...58```5960### Phase 4: Reduce & Synthesize (The "Aggregation" Phase)6162**Goal**: Combine results into a coherent answer.63641. **Collect**: Read background agent outputs via the `Read` tool on `output_file` paths,65 or use `TaskOutput` to retrieve results.662. **Synthesize**: Look for patterns, consensus, or specific answers in the aggregated data.673. **Refine**: If the answer is incomplete, perform a second RLM recursion on the missing pieces.6869## Critical Instructions70711. **NEVER** read more than 3-5 files into your main context at once.722. **ALWAYS** prefer the Task tool for reading/analyzing files when count > 1.733. **Use `rlm.py`** for programmatic slicing of large files that Grep can't handle well.744. **Python is your Memory**: If you need to track state across 50+ files, write a Python75 script (or use `rlm.py`) to scan them and output a summary.7677## Example Workflow: "Find all API endpoints and check for Auth"7879**Wrong Way (Monolithic)**:80- Read `src/api/routes.ts`, then `src/api/users.ts`, then ... (context fills up, reasoning degrades)8182**RLM Way (Recursive)**:831. **Filter**: `Grep(pattern="@Controller", output_mode="files_with_matches")` -> 20 files.842. **Map**: Launch 20 Task agents in parallel (background), each extracting endpoints + auth decorators from one file.853. **Reduce**: Collect all 20 outputs. Compile into a single table. Identify missing auth.8687## Recovery Mode8889If Task tool agents are unavailable or failing:901. Fall back to **Iterative Python Scripting**.912. Write a Python script that loads each file, runs a regex/AST check, and prints results to stdout.923. Read the script's stdout via Bash.