latch-compact

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

A command that summarizes the current coding-agent session into latch’s per-project knowledge base. It runs separately in the background so the session stays usable.

In plain words
What is it for?
Use it to compact the current session, or specify another session to compact, while continuing to work.
Why use it?
It preserves the latest session state without making the active conversation wait for the summary to finish.

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 Claude Code.

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

Good fit Use it to compact the current session, or specify another session to compact, while continuing to work.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/open-latch/latch/latch-compact
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-compact

README.md
[![agentmods](https://agentmods.dev/badge/commands/open-latch/latch/latch-compact/github.svg)](https://agentmods.dev/commands/open-latch/latch/latch-compact)
Your own site
<a href="https://agentmods.dev/commands/open-latch/latch/latch-compact"><img src="https://agentmods.dev/badge/commands/open-latch/latch/latch-compact/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-compact

Your own site · 80×15
<a href="https://agentmods.dev/commands/open-latch/latch/latch-compact"><img src="https://agentmods.dev/badge/commands/open-latch/latch/latch-compact.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 11 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 564 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.00011 $0.00564
Opus 5.5 $0.00004 $0.00226
Sonnet 5.5 $0.00002 $0.00113
Haiku 4.5 $0.00001 $0.00056

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

Security

Grade A, and why

latch-compact 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-compact.md · 56 lines

What it actually says

Run a compaction pass for the current Claude Code session against the per-project knowledge base under <KB_HOME>.

The compaction runs in a separate claude -p subprocess that takes its own context — it does NOT consume tokens from this session. We launch it in the background so the main session stays interactive while compaction runs.

This combines/overwrites the prior session_summary node with the latest state (see src/latch/pipeline/compactor.py).

Steps:

  1. The wrapper targets the invoking session automatically: it reads $CLAUDE_CODE_SESSION_ID (set by Claude Code on the Bash subprocess) and selects that session's transcript explicitly — a concurrent session's newer transcript is never picked. An explicit session id can be passed as the first positional arg to compact a different session.

  2. Launch the compactor with the Bash tool in the background so the main session is not blocked while compaction runs (a full compact can take 30–90s):

    Bash(
      command="bash <KB_HOME>/bin/run_compact_now.sh",
      run_in_background=true,
      description="Run KB compaction in background"
    )
    

    Return control to the user immediately with the background shell id. Do not poll — the harness will notify you when the subprocess exits. Omit --final — manual /latch-compact is a rolling compact, not a session end. The session_summary node stays in staging status.

  3. While the compactor is running, the project lock at <KB_HOME>/projects/<sanitized-cwd>/compactor.lock is held. Any latch_insert / latch_update / latch_link / latch_unlink calls made by the main session will block for up to 60s waiting for the compactor to finish, then return {"ok": false, "reason": "compaction_in_progress", "retry_after_s": 10} if it still hasn't finished. This is the deterministic write-side serialization — the busy payload's message tells you what to do: retry the write once, and if it is still locked, ask the user whether to retry again or investigate. Don't chase the lock.

  4. When the harness notifies that the background shell completed, fetch its stdout and report which summary_node_id was updated and a one-line gist.

If anything fails, check <KB_HOME>/compactor.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 096b9b6697d3
  2. 1mo ago First seen · 56 lines · 11 tokens per session scan A e0d4f2590f46

Subscribe to this mod's changes

latch-compact is a command published in the GitHub repository open-latch/latch (9 stars, last pushed 7d ago), licensed Apache-2.0. It adds 11 tokens to every session and 564 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.