# Reuse

Detects sessions that re-plan the same work and exports reviewable skeleton templates.

---

Reuse detects clusters of sessions that share a planning skeleton, meaning the structural shape of the agent's opening plan. When the same "patch release" or "triage" workflow gets re-planned dozens of times, each run re-buys a plan whose tool sequence was identical and only a version string changed. Reuse names that waste and exports each skeleton as a reviewable template.

```bash
tj optimize reuse
```

`reuse` is [skipped](/docs/optimize-more#when-an-analyzer-does-not-run) for a window an interactive coding agent dominates. An absent finding there means the analyzer never ran.

Reuse never reuses a plan for you. It reports "these plans look structurally identical." You review the skeleton and decide whether to template it.

## How it works

For each session, Reuse finds the first LLM call that precedes any tool call, the model's opening plan. It then clusters sessions by a signature, and the signature sharpens as more capture is available:

- **Mode 1 (always on).** The ordered tuple of tool names following the planning call. Works against any telemetry, including raw Claude Code backfills with no capture toggles set.
- **Mode 2 (`[capture] prompts = true`).** Also hashes a variable-stripped prefix of the planning prompt. Digits, ISO dates, and paths are normalized first, so "release v0.3.4 on 2026-06-15" and "release v0.3.5 on 2026-06-17" hash identically. The cluster key becomes the intersection of tool sequence and prompt prefix, which splits apart unrelated tasks that happen to share a tool sequence.

A cluster surfaces only when it clears all three thresholds: at least 3 sessions share the signature, average planning output is at least 200 tokens, and at least $0.01 is recoverable.

## Two recoverable numbers per cluster

Each cluster carries two framings side by side:

| Field | Heuristic | Meaning |
|---|---|---|
| cache-reuse | `avg_planning_cost × (repetitions − 1)` | Recoverable going forward by reusing the existing skeleton. Conservative — you already paid once. |
| script-replacement | `avg_planning_cost × repetitions` | Upper bound — replacing every planning call with a template eliminates all of it. |

The aggregate figure that the Lens Overview reads uses the conservative cache-reuse number. All dollar figures flow through the shared framing layer, so subscription users see token-share framing and local users see token counts.

## Report

```bash
tj report --reuse                 # all agents, 30d window
tj report --reuse my-agent        # scope to one agent
tj report --reuse --since 7d      # custom window
tj optimize reuse --export-templates   # Markdown skeletons only, no browser
```

The HTML report renders one section per cluster with the tool signature, both recoverable numbers, and the skeleton with variable regions highlighted as `{{slot_1}}`, `{{slot_2}}`, and so on. Each cluster also gets a Markdown sidecar you can paste straight into a slash command or saved prompt. Rendering the skeleton text needs `[capture] completions = true`; without it the clusters and numbers still show but the skeleton is replaced by a hint.

## Honesty caveat

Reuse confidence is `heuristic`, and every figure is **estimated recoverable**. It measures that planning calls repeat, not that the plans were interchangeable. The variable-slot highlighting is itself an honesty surface: when slots cover most of the skeleton, you can see the match is mostly placeholders. The caveat appears on every surface (CLI, HTML, Markdown):

> Structural skeleton match, not a guarantee the plans were interchangeable. Review the templates before reusing them.

## See also

- [Script](/docs/optimize-script) — tool sequences that could become a deterministic script
- [Cache](/docs/optimize-cache) — measure and improve prompt-cache usage