latch-tree

latch-tree is a command for Claude Code, Cursor from open-latch/latch. It costs 12 tokens per session (520 once invoked), scanned A, original, Apache-2.0.

A command that rebuilds the project's hierarchical knowledge tree. It groups related records and creates summaries for groups large enough to need one.

In plain words
What is it for?
Use it to retire old summaries, cluster stored project knowledge by similarity, attach grouped records to new summaries, and leave small or unrelated groups unchanged.
Why use it?
It refreshes outdated summaries while preserving frequently used records and keeping unrelated topics from being merged through a single misleading connection.

Command for Claude CodeCursor

Written for Cursor and Claude Code: shipped in a Cursor plugin, but also a Claude Code command (commands/*.md). Also seen: mentions Codex.

Part of the latch plugin — 10 skills, 9 commands shipped together

Good fit Use it to retire old summaries, cluster stored project knowledge by similarity, attach grouped records to new summaries, and leave small or unrelated groups unchanged.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/open-latch/latch/latch-tree
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/open-latch/latch

Made for: Claude Code, Cursor.

Or install latch, the plugin that ships this one along with the rest of its 10 skills, 9 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for latch-tree

README.md
[![agentmods](https://agentmods.dev/badge/commands/open-latch/latch/latch-tree/github.svg)](https://agentmods.dev/commands/open-latch/latch/latch-tree)
Your own site
<a href="https://agentmods.dev/commands/open-latch/latch/latch-tree"><img src="https://agentmods.dev/badge/commands/open-latch/latch/latch-tree/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for latch-tree

Your own site · 80×15
<a href="https://agentmods.dev/commands/open-latch/latch/latch-tree"><img src="https://agentmods.dev/badge/commands/open-latch/latch/latch-tree.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 12 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 520 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00012 $0.00520
Opus 5.5 $0.00005 $0.00208
Sonnet 5.5 $0.00002 $0.00104
Haiku 4.5 $0.00001 $0.00052

Measured 1mo ago against content hash 4160d25a9bc4, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

latch-tree scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/latch-tree.md · 43 lines

What it actually says

Full rebuild of the RAPTOR-style tree for the per-project knowledge base under <KB_HOME>. One pass:

  1. Retire prior summaries — all existing depth > 0 nodes are marked stale (audit trail preserved, excluded from retrieval). Their children's parent_id is cleared.
  2. Landmarks — leaf nodes with ref_count >= 5 are preserved as-is: they stay at depth=0 with parent_id=NULL. Frequently-consulted knowledge sits alongside summaries rather than being absorbed.
  3. Cluster the rest — bounded average-linkage (UPGMA) agglomerative clustering on cosine similarity (default threshold 0.65, max cluster size 40). Average-linkage merges only on mean pairwise similarity, so a single bridge edge can't chain unrelated topics into one mega-cluster (the single-link percolation collapse; KB id=1529/id=1560). Single-link remains available as a non-default linkage="single" fallback. Clusters with >= 3 members earn one LLM-generated summary node (kind='summary', status='canonical', depth=1). Members' parent_id is set to the summary.
  4. Singletons and sub-minimum clusters stay at depth=0 with parent_id=NULL.

Each summary LLM call uses the selected maintenance model backend (Claude by default; adapter env can select Codex) and counts against the daily budget. If the cap is hit mid-run, the remaining clusters are left without summaries this cycle — report that via budget_blocked.

Run with the Bash tool:

python "<KB_HOME>/src/latch/pipeline/maintenance.py" tree "$(pwd)"

Report the JSON summary: linkage, leaves, landmarks, clusters, largest_cluster, p95_cluster_size, summaries_generated, singletons, oversized_skipped, budget_blocked, llm_failed, prior_summaries_staled.

Retrieval is unchanged — summary nodes live in the same FTS+vector pool as leaves (collapsed-tree search). If anything fails, check <KB_HOME>/maintenance.log and tree.log.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed 4160d25a9bc4
  2. 1mo ago First seen · 43 lines · 12 tokens per session scan A 0bc32d30c306

Subscribe to this mod's changes

latch-tree is a command published in the GitHub repository open-latch/latch (9 stars, last pushed 7d ago), licensed Apache-2.0. It adds 12 tokens to every session and 520 once invoked, about $0.0000 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.