# Rlm

> Run a Recursive Language Model-style loop for long-context tasks using a persistent local REPL.

- Skill: `twistingmercury/rlm` (Agent Skill, multi-file: 9 files)
- Install (CLI): `npx skillmds@latest add twistingmercury/rlm`
- Raw SKILL.md: https://api.skillmd.com/api/skills/twistingmercury/rlm/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: twistingmercury (https://skillmd.com/u/twistingmercury)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/twistingmercury/rlm

---


# rlm (Recursive Language Model workflow)

Use this skill when:
- The user provides a large context file or document directory.
- You need iterative search/chunk/extract over that context.
- You want to reuse loaded context across multiple queries.

## Inputs

Required:
- `context=<path>`: file path (single-file mode) or directory path (corpus mode)
- `query=<question>`: question/task to run against the loaded context

Optional:
- `chunk_chars=<int>` (default ~200000)
- `overlap_chars=<int>` (default 0)
- `strict=true` (corpus mode only, fail on first parse error)

If arguments are missing, ask for:
1. context path
2. query

Resolve `<skill-dir>` to the directory containing this `SKILL.md` before running bundled scripts. Do not assume the repository working directory contains `scripts/rlm_repl.py`.

## Workflow

1. Initialize state.

   Single-file mode:

   ```bash
   python3 <skill-dir>/scripts/rlm_repl.py init <context_path>
   python3 <skill-dir>/scripts/rlm_repl.py status
   ```

   Corpus mode (recursive, honors `.rlmignore` if present):

   ```bash
   python3 <skill-dir>/scripts/rlm_repl.py init-corpus <context_dir>
   python3 <skill-dir>/scripts/rlm_repl.py status
   ```

   Corpus strict mode:

   ```bash
   python3 <skill-dir>/scripts/rlm_repl.py init-corpus <context_dir> --strict
   ```

2. Check/install optional parsers when needed.

   ```bash
   python3 <skill-dir>/scripts/rlm_repl.py check-deps
   python3 <skill-dir>/scripts/rlm_repl.py install-deps --all --dry-run
   ```

   Install missing dependencies only with user approval.

3. Scout the loaded context.

   ```bash
   python3 <skill-dir>/scripts/rlm_repl.py exec -c "print(peek(0, 3000))"
   python3 <skill-dir>/scripts/rlm_repl.py exec -c "print(peek(len(content)-3000, len(content)))"
   ```

4. Materialize chunks for subagent analysis.

   ```bash
   python3 <skill-dir>/scripts/rlm_repl.py exec <<'PY'
   paths = write_chunks('.mnemonic/rlm_state/chunks', size=200000, overlap=0)
   print(len(paths))
   print(paths[:5])
   PY
   ```

5. Use the host's available subagent mechanism for chunk analysis when useful, then synthesize results. If subagents are unavailable, analyze chunks sequentially.

## Guardrails

- Do not paste large raw chunks into chat.
- Quote only needed excerpts.
- Keep scratch/state files under `.mnemonic/rlm_state/`.
- For first iteration, refresh manually when sources change:
  - run `python3 <skill-dir>/scripts/rlm_repl.py reset`
  - then reinvoke the skill with `context=... query=...`

## Notes

- Optional document parsers:
  - PDF: `pypdf`
  - DOCX: `python-docx`
  - ODT: `odfpy`
- Default corpus excludes: `.git/`, `node_modules/`, `bin/`, `_archive/`.
- Additional reference docs are in `references/`.

