cc-compact

A command that saves the current phase state, decisions, pending work, changed files, and related details so a long conversation can be shortened and continued later.

In plain words
What is it for?
Use it at the end of a planning, specification, implementation, or review phase when the conversation needs to be compacted.
Why use it?
It preserves handoff information before context is compacted, reducing the risk of losing what has already been decided.

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/yeisonrestrepo/code-conductor/cc-compact
Clone the repo
git clone --depth 1 https://github.com/yeisonrestrepo/code-conductor
Per session 13 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,501 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.00013 $0.01501
Opus 5 $0.00006 $0.00750
Sonnet 5 $0.00003 $0.00300
Haiku 4.5 $0.00001 $0.00150

Measured 2d ago against content hash 461ab9cc3e0c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cc-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 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.

global/commands/cc-compact.md · 50 lines

How it starts

The opening of the file, as written. The whole thing — 50 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Run git rev-parse HEAD to get the current commit SHA (the full 40-char hash — NOT --short, whose abbreviation length auto-scales with repo size and is unstable across growth). Lowercase and trim it; if it does not match /^[0-9a-f]{7,40}$/, or the command exits non-zero (non-git workspace, no commits, git absent, or permission-denied), use "0000000". Wrap the call with shell timeout only when command -v timeout (or gtimeout) succeeds; otherwise run it unwrapped. This same value is sys.c and the sessions / snapshots git-hash key.

Determine sys.s: take the active specification file path from this phase's context, split on / and \, keep the last segment, strip a trailing .md extension, truncate to 200 characters. If no active spec file exists, use "none".

Collect from the current conversation context:

  • Phase (sys.ph): spec | plan | impl | rev, the phase that just completed
  • Decisions (mem.d): finalized decisions this phase, max 10 elements, each ≤300 chars (JSON-serialized length)
  • Pending (ops.n): next immediate step(s), max 3 elements, each ≤200 chars
  • Files Touched (ops.f): each entry <relpath>:C|M|D (uppercase only); replace any backslash in the path with /; if the path contains a literal :, percent-encode it as %3A before appending the suffix; max 20 elements, each ≤300 chars
  • Constraints (mem.x): hard constraints next phase must respect, max 5 elements, each ≤200 chars

For all four array fields: filter out empty/whitespace-only strings, deduplicate by exact case-sensitive string equality (first occurrence wins), then truncate each surviving element to its per-element cap (Unicode-safe: Array.from(str).slice(0, cap).join('')), then if the array still exceeds its cap, drop from the head (oldest first) until it fits. Empty arrays are valid and must still be serialized (never omitted).

Serialize by piping a flat JSON object {ph, c, s, n, f, d, x} (no pr) on stdin to node .claude/scripts/snap-build.mjs; its stdout is the canonical single-line v1 SNAP JSON. snap-build performs all array normalization (filter/dedup/per-element cap/head-drop) and the 4096-char size trim internally — do not pre-serialize. If snap-build exits non-zero (malformed field object), report the error and stop; do not write the handoff file, do not run the DB tail, do not print the compact prompt.

Write the single JSON line, followed by exactly one trailing newline, to .claude/memory/session-snapshot.json.

If .claude/memory/session-snapshot.md exists, delete it as part of this write.

Idempotently append .claude/memory/session-snapshot.json to the project's .gitignore: read the file; if any line, after stripping leading/trailing whitespace, exactly equals .claude/memory/session-snapshot.json, skip the append. Otherwise, check whether the last byte of .gitignore is a newline; if not, prepend a newline before the appended entry. If .gitignore cannot be read or written (permission or lock error), log a non-fatal warning to stderr and continue; do not block the snapshot write.

If writing the snapshot fails (e.g., missing .claude/memory/ directory), report the error and stop. Do NOT output the compact prompt.

Once the snapshot is written successfully, output exactly:

Snapshot written. Run /compact now to clear history.


Fail-open DB tail (best-effort, synchronous)

After the handoff file is written and the compact prompt is ready — and only if the authoritative write succeeded — run this synchronous, fail-open tail. Any failure here is non-fatal: never revert the handoff file, never suppress the compact prompt.

  1. Ensure .conductor/ exists (mkdir -p .conductor, best-effort). If that fails, skip the tail entirely.
  2. Resolve the session id: id="$(node .claude/scripts/session-id.mjs 2>>.conductor/last-write.log)".
  3. Upsert the session row (Node-flag probe applies — same as the cc-implement Step 6 hook: no-flag-first, else --experimental-sqlite --no-warnings, else skip):

Read the full file on GitHub · 50 lines

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 · 50 lines · 13 tokens per session scan A 461ab9cc3e0c

Subscribe to this mod's changes

cc-compact is a command published in the GitHub repository yeisonrestrepo/code-conductor (6 stars, last pushed 1mo ago), licensed MIT. It adds 13 tokens to every session and 1,501 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.