Recursive Decomposition logo

Recursive Decomposition

Community
massimodeluisa
recursive-decomposition

Decompose dense codebase-wide, multi-document, PDF, and aggregation work even when the input fits the context window, following Recursive Language Models (Zhang, Kraska, Khattab, 2025). Use when the user asks to analyse all files, a whole repo, all docs, large PDFs, or to aggregate or multi-hop across scattered sources. Skip one file, one function, a single needle, or a one-page PDF conversion. Triggers: long context, context rot, large codebase, many files, all files, big document, multi-document, PDF, aggregate, summarize everything, codebase-wide, multi-hop, recursive, sub-agents, map-reduce.

Overview

Publishermassimodeluisa
Repositoryrecursive-decomposition-skill
Skill namerecursive-decomposition
Stars
53
Forks
2
Bundled files
7
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 7 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by massimodeluisa on GitHub. Read the source before you install it.

Installation

Install the Recursive Decomposition AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/massimodeluisa/recursive-decomposition-skill/tree/main/skills/recursive-decomposition
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/massimodeluisa/recursive-decomposition-skill.git /tmp/recursive-decomposition-skill
mkdir -p .claude/skills
cp -r /tmp/recursive-decomposition-skill/skills/recursive-decomposition .claude/skills/recursive-decomposition
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Recursive Decomposition in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Recursive Decomposition on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Recursive Decomposition is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Recursive Decomposition

Long inputs rot. Details get missed, distant parts get glued together by guesswork, and the reasoning drifts. The RLM paper calls it context rot. Do not load the whole input into the window. Treat it as an environment you query: size it, narrow it, split it, hand independent parts to sub-agents, verify on a small window, synthesise in code. Based on Recursive Language Models (Zhang, Kraska, Khattab, 2025).

How to use

  • /recursive-decomposition: apply the protocol below to the current task.
  • /recursive-decomposition <path or question>: size that input first, then run the protocol on it.

When it applies

Fit is not the test. Dense work can rot inside a million-token window. In the paper, OOLONG-Pairs is 32k tokens and GPT-5 scores 0.1% F1; RLM(depth=1) reaches 58.0% (arXiv:2512.24601, Table 1). 30k and 50k below are harness caps.

SituationApproach
One file, one function, or a single needleRead directly
Linear aggregate or list-everything, and completeness mattersDecompose (this skill)
Pairwise, quadratic, or multi-hop across scattered sourcesDecompose, even under 30k tokens
10+ files or 50k+ tokensDecompose
Under 30k tokens and a localised answerRead directly

Protocol

  1. Size the input before reading anything: count files (glob, find), lines (wc -l), bytes (ls -lh), pages for PDFs.
  2. Filter the search space with searches (content search, file patterns, keywords, file types) before opening any file. Chain filters: file type, then keyword, then meaning.
  3. Chunk what remains: natural units (functions, classes, sections), line ranges, or keyword partitions. Batches of 5 to 10 files.
  4. Recurse at depth 1: one sub-agent per independent batch, self-contained brief (files, question, output schema); run one parallel wave. Write the batch count first. If more batches remain, run the next wave after the merge. Sub-agents answer; they do not spawn sub-agents.
  5. Verify the synthesised answer on a smaller window: extract the minimal evidence and re-check it; settle disagreements with a targeted re-read.
  6. Synthesise programmatically: aggregate the structured results, deduplicate, categorise, then write the answer with file and line references.

Rules

  • MUST size the input before reading it
  • MUST search before reading a directory; NEVER list a tree recursively as a substitute for search
  • MUST read large files by line range: over 2,000 lines or 50 KB never in one read; PDFs over 100 pages or 30 MB by metadata or split
  • MUST convert PDFs and Office files to markdown before reasoning. Prefer local anydoc (npx -y @firecrawl/anydoc FILE -o .firecrawl/FILE.md) from the Firecrawl convert-documents-to-markdown skill. Use cloud firecrawl parse for OCR (--ocr hosted / firecrawl parse), -Q, or -S. Never dump the binary into context. Cloud parse caps at 50 MB and about 1 credit per PDF page; split first if larger.
  • NEVER load more than 5 files into the main context without a written batch plan
  • MUST give every sub-agent its own context: the files, the question, the output schema
  • MUST keep recursion depth at 1: sub-agents answer; they MUST NOT launch sub-agents
  • MUST write the batch count before launch; one parallel wave, then merge; further waves only after that merge
  • MUST spot-check the synthesised result against the sources before answering
  • SHOULD read definitions first (grep -n "function") and bodies later; tables of contents and abstracts before full text
  • NEVER run the same query over the same content in several sub-agents; partition once into disjoint batches
  • NEVER raise depth because the merge looks thin; re-read the disagreement instead

Tools, agent-agnostic

NeedUse
Find filesthe file search or glob tool, or find
Find contentthe content search or grep tool, never a full read
Sizewc -l, ls -lh, page count (pdfinfo if present)
Readthe file reader with an offset and a limit, or sed -n 'START,ENDp'
PDF or Office fileanydoc first (npx -y @firecrawl/anydoc FILE -o .firecrawl/out.md), then grep the markdown. Cloud firecrawl parse for OCR, -Q, or -S. Else pdfinfo and a split. Never a full binary read
Delegatethe sub-agent or task tool, one brief per batch
Aggregatea scratch file or structured notes, then one final pass

Tool names differ between agents (Claude Code, Codex, Cursor, Gemini CLI); map the row to your agent's equivalent.

Patterns

Codebase analysis

"Find all error handling patterns." Glob the source files, grep catch|throw|Error|except, batch the matches by module (5 to 10 files), one sub-agent per batch with a fixed report schema, merge into a categorised summary with file references. Worked example: references/codebase-analysis.md.

Multi-document question answering

"What features are planned across all PRDs?" Glob the documents, size them, define an extraction schema (name, priority, status, quarter), one sub-agent per document group, deduplicate and categorise, spot-check three entries against the sources. Worked example: references/document-aggregation.md.

Aggregation

"Summarise all TODO comments." Grep TODO|FIXME|HACK, group by module, extract context and priority per group, produce a prioritised list.

Large PDFs

Glob *.pdf, size bytes and page count (pdfinfo). Over 100 pages or 30 MB: do not ingest. Convert with anydoc to .firecrawl/ (Firecrawl skill convert-documents-to-markdown), then grep and chunk the markdown. If anydoc exits 3 (scanned pages), rerun with --ocr hosted or firecrawl parse (Firecrawl skill firecrawl-parse, 50 MB / ~1 credit per page). Batch by document, depth 1, spot-check titles against PDF metadata.

A one-page convert-to-markdown job is not this skill. Hand it to anydoc or firecrawl parse alone.

Long output

Split the output into sections, generate each independently, store intermediate results in a file, stitch them with a coherence pass.

Cost and quality

Decomposition spends coordination tokens. In the paper (arXiv:2512.24601, Table 1 and Figure 1), RLM(GPT-5, depth=1) scored 91.3% on BrowseComp-Plus (6 to 11M tokens) at $0.99 average, versus 70.5% for compaction. On OOLONG it beat GPT-5 by 28.4%. On OOLONG-Pairs it reached 58.0% F1 against a 0.1% base. Figure 1 scales inputs from 2^13 to 2^20 tokens. Median cost stays comparable to the base model; averages can rise on outlier trajectories. Thresholds: references/cost-analysis.md.

Anti-patterns

Anti-patternFix
Reading everything first "to get context"Size, filter, then read by range
Dumping a PDF binary into the windowParse to markdown, then grep and chunk
Decomposing a single needle or one-file lookupRead directly
Sub-agents without the question or the schemaSelf-contained briefs
Sub-agents that spawn sub-agentsDepth 1: they answer, they do not delegate
Trusting the merged answerSpot-check on a small window
Re-querying the same content in several sub-agentsPartition once, disjoint batches

References

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Recursive Decomposition AI skill do?

Decompose dense codebase-wide, multi-document, PDF, and aggregation work even when the input fits the context window, following Recursive Language Models (Zhang, Kraska, Khattab, 2025). Use when the user asks to analyse all files, a whole repo, all docs, large PDFs, or to aggregate or multi-hop across scattered sources. Skip one file, one function, a single needle, or a one-page PDF conversion. Triggers: long context, context rot, large codebase, many files, all files, big document, multi-document, PDF, aggregate, summarize everything, codebase-wide, multi-hop, recursive, sub-agents, map-re...

Why use Recursive Decomposition on TypingMind?

Because you install it once and use it with any model. Recursive Decomposition is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Recursive Decomposition in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/massimodeluisa/recursive-decomposition-skill/tree/main/skills/recursive-decomposition. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Recursive Decomposition?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Recursive Decomposition?

As many as you like. As long as a model supports skills, you can use Recursive Decomposition with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Recursive Decomposition AI skill free?

Yes. It is published on GitHub by massimodeluisa under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇