rlm
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.
- License 许可
- MIT
- 最近更新
- 2026-04-16
- Stars
- ★ 52
- Forks
- 13
01 前言 Front Matter
- name
- rlm
- license
- MIT
- metadata
- { "author": "ClawFu", "version": "1.0.0", "mcp-server": "@clawfu/mcp-skills" }
- triggers
- [ "analyze codebase", "scan all files", "large repository", "RLM", "find usage of X across the project" ]
- description
- 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.
03 SKILL.md 正文
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
findorgrep -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.
- Strict Mode:
- Spawn: Use
background_taskto 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(viabackground_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_taskfor reading/analyzing file contents when the file count > 1. - Use
rlm.pyfor programmatic slicing of large files thatgrepcan'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.tsread 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
04 同仓库更多 Skills
what-if-oracle
Run structured What-If scenario analysis with multi-branch possibility exploration. Use this skill when the user asks speculative questions like "what if...", "what would happen if...", "what are the possibilities", "explore scenarios", "scenario analysis", "possibility space", "what could go wrong", "best case / worst case", "risk analysis", "contingency planning", "strategic options", or any question about uncertain futures. Also trigger when the user faces a fork-in-the-road decision, wants to stress-test an idea, or needs to think through consequences before committing.
venue-templates
Access comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
the-fool
Use when challenging ideas, plans, decisions, or proposals using structured critical reasoning. Invoke to play devil's advocate, run a pre-mortem, red team, or audit evidence and assumptions.
scientific-writing
Core skill for the deep research and writing tool. Write scientific manuscripts in full paragraphs (never bullet points). Use two-stage process with (1) section outlines with key points using research-lookup then (2) convert to flowing prose. IMRAD structure, citations (APA/AMA/Vancouver), figures/tables, reporting guidelines (CONSORT/STROBE/PRISMA), for research papers and journal submissions.
scientific-brainstorming
Creative research ideation and exploration. Use for open-ended brainstorming sessions, exploring interdisciplinary connections, challenging assumptions, or identifying research gaps. Best for early-stage research planning when you do not have specific observations yet. For formulating testable hypotheses from data use hypothesis-generation.
research-lookup
Look up current research information using the Parallel Chat API (primary) or Perplexity sonar-pro-search (academic paper searches). Automatically routes queries to the best backend. Use for finding papers, gathering research data, and verifying scientific information.