latch-tree

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

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.

agentmods
npx agentmods add commands/open-latch/latch/latch-tree
Clone the repo
git clone --depth 1 https://github.com/open-latch/latch
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 516 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00012 $0.00516
Opus 5 $0.00006 $0.00258
Sonnet 5 $0.00002 $0.00103
Haiku 4.5 $0.00001 $0.00052

Measured 2d ago against content hash 0bc32d30c306, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 2d 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/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. 2d 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 2d ago), licensed Apache-2.0. It adds 12 tokens to every session and 516 once invoked, about $0.0001 per session on Opus 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.