From rlm
Processes large files, logs, repos exceeding context limits via 6-step RLM protocol using Python/Bash scripts for metadata, peeking, search, extraction, and summarization.
npx claudepluginhub lets7512/rlm-skill --plugin rlmThis skill uses the workspace's default tool permissions.
Based on MIT's RLM paper (arXiv:2512.24601) and DSPy's structured REPL pattern. Instead of stuffing data into the token window, explore it programmatically through a structured protocol. Only printed results enter context.
Based on the Recursive Language Models (RLM) research by Zhang, Kraska, and Khattab (2025), this skill provides strategies for handling tasks that exceed comfortable context limits through programmatic decomposition and recursive self-invocation. Triggers on phrases like "analyze all files", "process this large document", "aggregate information from", "search across the codebase", or tasks involving 10+ files or 50k+ tokens.
Uses dspy.RLM to reason over large contexts (>100k tokens) like codebases, logs, or documents via recursive chunking and sandboxed Python REPL code execution.
Share bugs, ideas, or general feedback.
Based on MIT's RLM paper (arXiv:2512.24601) and DSPy's structured REPL pattern. Instead of stuffing data into the token window, explore it programmatically through a structured protocol. Only printed results enter context.
Tokens are CPU, not storage. Never dump raw data into context. Write code to extract what matters, print only the summary.
| Size | Protocol |
|---|---|
| < 5KB | Read directly — no RLM needed |
| 5KB–500KB | Steps 1-3 only (METADATA, PEEK, SEARCH) |
| 500KB+ | Full protocol steps 1-6 with sub-agent decomposition |
Follow these steps IN ORDER. Each step uses python3 -c (or python -c on Windows) via Bash/shell. Raw data never enters context — only stdout does.
Windows note: Use
pythoninstead ofpython3. PowerShell commands likeGet-Content,Select-Stringare also intercepted by the RLM hook — prefer python scripts over PowerShell for data processing.
Assess the file before touching it.
For multi-file discovery: Use Glob (Claude Code) or glob tool (OpenCode) to find files by pattern. Never use find via Bash — Glob is faster and keeps output compact.
WebFetch is blocked. Never use WebFetch/fetch to pull remote data into context. Instead, download via python3 -c using urllib/requests, save to a local file, then process that file through the protocol.
python3 -c "
import os
path = '/path/to/file'
size = os.path.getsize(path)
print(f'File: {path}')
print(f'Size: {size:,} bytes ({size/1024/1024:.1f}MB)')
print(f'Type: {os.path.splitext(path)[1] or \"unknown\"}')
with open(path, 'rb') as f:
head = f.read(200)
try: preview = head.decode('utf-8', errors='replace')
except: preview = repr(head)
print(f'Preview: {preview[:200]}')
try:
with open(path) as f:
lines = sum(1 for _ in f)
print(f'Lines: {lines:,}')
except: pass
"
Log: python3 -c "import sys; sys.path.insert(0,'${CLAUDE_PLUGIN_ROOT}/src'); from stats import log_event; log_event('rlm_metadata','FILE_PATH',SIZE_BYTES,1)"
Sample strategically — head, tail, random slices, structure detection.
python3 -c "
with open('/path/to/file') as f:
lines = f.readlines()
print('=== HEAD (first 20 lines) ===')
for l in lines[:20]: print(l.rstrip())
print(f'\n=== TAIL (last 10 lines) ===')
for l in lines[-10:]: print(l.rstrip())
print(f'\n=== SAMPLE (every {max(1,len(lines)//10)}th line, 10 samples) ===')
step = max(1, len(lines)//10)
for i in range(0, len(lines), step):
print(f'L{i}: {lines[i].rstrip()[:120]}')
"
Log: python3 -c "import sys; sys.path.insert(0,'${CLAUDE_PLUGIN_ROOT}/src'); from stats import log_event; log_event('rlm_peek','FILE_PATH',SIZE_BYTES,1)"
Targeted extraction based on what PEEK revealed.
python3 -c "
import re
with open('/path/to/file') as f:
content = f.read()
# Adapt search to what you're looking for:
matches = re.findall(r'PATTERN', content)
print(f'Found {len(matches)} matches')
for m in matches[:30]:
print(m[:200])
"
Log: python3 -c "import sys; sys.path.insert(0,'${CLAUDE_PLUGIN_ROOT}/src'); from stats import log_event; log_event('rlm_search','FILE_PATH',SIZE_BYTES,2)"
Decompose into sub-queries. Max 15 sub-queries.
Both Claude Code and OpenCode support sub-agents for parallel analysis.
For each chunk identified in SEARCH, spawn a sub-agent:
To extract a chunk for a sub-agent:
python3 -c "
with open('/path/to/file') as f:
lines = f.readlines()
chunk = lines[START:END]
print(f'=== Chunk N ({len(chunk)} lines) ===')
for l in chunk: print(l.rstrip())
"
Log each sub-agent: python3 -c "import sys; sys.path.insert(0,'${CLAUDE_PLUGIN_ROOT}/src'); from stats import log_event; log_event('rlm_analyze','FILE_PATH',CHUNK_SIZE,2)"
Sub-query types:
Combine findings from all sub-queries. Cross-reference. Resolve conflicts. This is reasoning — no code needed unless aggregating data.
Log: python3 -c "import sys; sys.path.insert(0,'${CLAUDE_PLUGIN_ROOT}/src'); from stats import log_event; log_event('rlm_synthesize','FILE_PATH',SIZE_BYTES,2)"
Always end with an explicit SUBMIT block:
=== RLM SUBMIT ===
Query: [original question]
Confidence: [high/medium/low]
Protocol: [steps executed, e.g. METADATA->PEEK->SEARCH->ANALYZE->SYNTHESIZE]
Sub-queries: [N spawned, N completed]
Data processed: [size of original file]
Context used: [estimated tokens that entered context]
[Final structured answer here]
=== END ===
Log: python3 -c "import sys; sys.path.insert(0,'${CLAUDE_PLUGIN_ROOT}/src'); from stats import log_event; log_event('rlm_submit','FILE_PATH',SIZE_BYTES,2)"
Confidence levels:
| Parameter | Limit |
|---|---|
| Max REPL iterations | 20 |
| Max output per step | 15,000 chars |
| Max sub-queries | 15 |
If you hit max iterations without resolving, SUBMIT with confidence: low.
Use rlm-cli which adds recursive sub-LLM decomposition:
# With local Ollama
rlm-cli query "Find all security issues" --file /path/to/large.log --backend openai --model qwen3:8b --base-url http://localhost:11434/v1
# With local vLLM
rlm-cli query "Find bugs" --repo /path/to/repo --backend openai --model Qwen/Qwen3-8B --base-url http://localhost:8000/v1
# With Anthropic API
rlm-cli query "Analyze architecture" --repo /path/to/repo --backend anthropic --model claude-sonnet-4-6
Log: python3 -c "import sys; sys.path.insert(0,'${CLAUDE_PLUGIN_ROOT}/src'); from stats import log_event; log_event('rlm_cli','FILE_PATH',SIZE_BYTES,3)"