/ca-prune — session transcript pruner
Long sessions die when their semantic history fills the context window with bulk: oversized tool
outputs, thinking blocks, MCP/shell noise, stale file reads, and host-specific sidecars. The shared
policy trims that bulk at safe quiescence boundaries while each host codec preserves its native
integrity model and the K most recent tool-bearing turns verbatim. Claude keeps byte-safe JSONL
serialization; Pi uses semantic entries and returns a native custom-compaction result.
Gains land at the host's next native resume/restart or compaction boundary, not by mutating the
running session's active file. Pi-native compaction is event-driven and never rewrites an active
Pi session file.
Argument
$ARGUMENTS is one of:
status (default) — report cumulative reduction and service state for this session from
~/.codearbiter/prune-state.json, and whether CODEARBITER_PRUNE is on/dry/off. When
the service has run in dry mode, every would-be prune is also recorded — one JSONL row per
decision, across all sessions — to the shared data-collection log
~/.codearbiter/metrics/prune-dry.jsonl (override with CODEARBITER_PRUNE_METRICS). That log is
the evidence base for the dry→on decision: a clean record (every row verdict: dry-run,
validation_errors: 0) over a representative set of sessions is the signal that enabling is safe.
Read context_bytes_freed / context_est_tokens_freed for model-context benefit and
file_bytes_freed / file_pct for disk and resume-parse benefit. sidecar-collapse is explicitly
file-only; it must not count toward the context-benefit or cold-cache decision.
The legacy freed_bytes, pct, and est_tokens_before / est_tokens_after fields remain
whole-file compatibility aliases; do not use them as model-context evidence.
dry — create a read-only semantic plan (or analyze a scratch copy where the host exposes a
serialized transcript); present the per-strategy reduction table with every strategy labeled
context or file-only. Never writes the active session.
run <path> — prune the target with --execute. Targets a copy or an old/inactive
transcript only — the tool refuses an active or recently-modified target by construction.
audit <path> — read-only integrity report: line-parse, uuid chain, tool-pair coverage,
condensation markers.
on / off — guidance on enabling or disabling the after-each-turn service.
Flow
status / dry / audit — run the backing tool and present its output verbatim:
python3 "<plugin-root>/hooks/prune-transcript.py" <subcommand> [<path>] || python "<plugin-root>/hooks/prune-transcript.py" <subcommand> [<path>]
For serialized hosts, dry analyzes <path>.copy.jsonl; Pi active sessions use the native
semantic planner and return a custom compaction result without session-file writes.
run — confirm the path is a copy or an inactive session, then:
python3 "<plugin-root>/hooks/prune-transcript.py" <path> --execute [--tier T] || python "<plugin-root>/hooks/prune-transcript.py" <path> --execute [--tier T]
Present the per-strategy reduction report; follow with audit on the result.
on/off — explain the after-each-turn service: UserPromptSubmit and PreCompact hooks
prune at safe quiescence points, always exit 0, and never block the prompt. Tiers: gentle
(sidecar + oversize clamp), standard (+ reasoning fold, aged/MCP/shell), aggressive
(+ stale-read, reminder dedup, image evict). Config via CODEARBITER_PRUNE (off|dry|on,
ships off), CODEARBITER_PRUNE_TIER, CODEARBITER_PRUNE_KEEP_RECENT (the K most recent
tool turns kept verbatim — each turn is an assistant tool_use plus its results),
CODEARBITER_PRUNE_MAXBYTES. Enabling is the user's explicit choice — never set it unbidden.
In dry mode the service writes no transcript but appends each would-be prune to
~/.codearbiter/metrics/prune-dry.jsonl (path override: CODEARBITER_PRUNE_METRICS) for
data collection; in on mode the executed prunes are recorded in ~/.codearbiter/prune.log.
If a prior service-mode prune was killed mid-write, the next run self-heals the transcript
from the newest backup in ~/.codearbiter/prune-backups/ before doing anything else.
Cold-miss nudge [Feature Forge — preview]: when CODEARBITER_PRUNE is on, an
optional submit-time speed bump warns once before a cold cache re-cache lands on bloated
context. Enable with CODEARBITER_PRUNE_NUDGE=on (default off). When all arming conditions
hold (idle ≥ CODEARBITER_PRUNE_NUDGE_IDLE_SECS, default 240 s; estimated model-context
tokens freed ≥
CODEARBITER_PRUNE_NUDGE_MIN_TOKENS, default 80 000), the hook blocks the submit once with
an advisory on stderr and returns exit code 2. File-only sidecar reduction never arms it. The
advisory names the approximate avoidable context-token count and the host-native actions that
move the re-cache to pruned context:
native compaction or a normal exit + resume/restart. Resubmitting immediately proceeds. The block fires at most
once per cold window; a subsequent warm submit (idle < floor) resets the window so the next
genuine cold stretch re-arms. The gate is strictly opt-in, never fires in dry/off mode,
and fails open on any error — a pruner fault will never block the session.
When NOT to use
- Context bar nowhere near compaction — the most recent turns are protected anyway.
- Install health →
/ca-doctor.
- Project progress →
/ca-status.
Hard gate
- MUST NOT run
--execute against the live session's transcript — the tool refuses a
recently-modified file by construction; manual run targets copies or old sessions only.
- MUST surface the native-boundary-only gains limitation whenever a user expects an immediate
active-file context drop.
- MUST NOT enable the service (
CODEARBITER_PRUNE=on) on behalf of the user — explain and let
them decide.
1---2name: ca-prune3description: Trim transcript clutter to extend session lifetime — analyze, prune a copy, or toggle the after-each-turn service. Dry-run by default; gains land at resume/compaction, not the current turn.4---5
6# /ca-prune — session transcript pruner
7
8Long sessions die when their semantic history fills the context window with bulk: oversized tool
9outputs, thinking blocks, MCP/shell noise, stale file reads, and host-specific sidecars. The shared
10policy trims that bulk at safe quiescence boundaries while each host codec preserves its native
11integrity model and the K most recent tool-bearing turns verbatim. Claude keeps byte-safe JSONL
12serialization; Pi uses semantic entries and returns a native custom-compaction result.
13Gains land at the host's next native resume/restart or compaction boundary, not by mutating the
14running session's active file. **Pi-native compaction** is event-driven and never rewrites an active
15Pi session file.
16
17## Argument
18
19`$ARGUMENTS` is one of:
20
21- `status` (default) — report cumulative reduction and service state for this session from
22 `~/.codearbiter/prune-state.json`, and whether `CODEARBITER_PRUNE` is `on`/`dry`/`off`. When
23 the service has run in `dry` mode, every would-be prune is also recorded — one JSONL row per
24 decision, across all sessions — to the shared data-collection log
25 `~/.codearbiter/metrics/prune-dry.jsonl` (override with `CODEARBITER_PRUNE_METRICS`). That log is
26 the evidence base for the `dry`→`on` decision: a clean record (every row `verdict: dry-run`,
27 `validation_errors: 0`) over a representative set of sessions is the signal that enabling is safe.
28 Read `context_bytes_freed` / `context_est_tokens_freed` for model-context benefit and
29 `file_bytes_freed` / `file_pct` for disk and resume-parse benefit. `sidecar-collapse` is explicitly
30 `file-only`; it must not count toward the context-benefit or cold-cache decision.
31 The legacy `freed_bytes`, `pct`, and `est_tokens_before` / `est_tokens_after` fields remain
32 whole-file compatibility aliases; do not use them as model-context evidence.
33- `dry` — create a read-only semantic plan (or analyze a scratch copy where the host exposes a
34 serialized transcript); present the per-strategy reduction table with every strategy labeled
35 `context` or `file-only`. Never writes the active session.
36- `run <path>` — prune the target with `--execute`. Targets a **copy or an old/inactive
37 transcript only** — the tool refuses an active or recently-modified target by construction.
38- `audit <path>` — read-only integrity report: line-parse, uuid chain, tool-pair coverage,
39 condensation markers.
40- `on` / `off` — guidance on enabling or disabling the after-each-turn service.
41
42## Flow
43
441. **status / dry / audit** — run the backing tool and present its output verbatim:
45 ```
46 python3 "<plugin-root>/hooks/prune-transcript.py" <subcommand> [<path>] || python "<plugin-root>/hooks/prune-transcript.py" <subcommand> [<path>]
47 ```
48 For serialized hosts, `dry` analyzes `<path>.copy.jsonl`; Pi active sessions use the native
49 semantic planner and return a custom compaction result without session-file writes.
50
512. **run** — confirm the path is a copy or an inactive session, then:
52 ```
53 python3 "<plugin-root>/hooks/prune-transcript.py" <path> --execute [--tier T] || python "<plugin-root>/hooks/prune-transcript.py" <path> --execute [--tier T]
54 ```
55 Present the per-strategy reduction report; follow with `audit` on the result.
56
573. **on/off** — explain the after-each-turn service: `UserPromptSubmit` and `PreCompact` hooks
58 prune at safe quiescence points, always exit 0, and never block the prompt. Tiers: `gentle`
59 (sidecar + oversize clamp), `standard` (+ reasoning fold, aged/MCP/shell), `aggressive`
60 (+ stale-read, reminder dedup, image evict). Config via `CODEARBITER_PRUNE` (`off`|`dry`|`on`,
61 ships **off**), `CODEARBITER_PRUNE_TIER`, `CODEARBITER_PRUNE_KEEP_RECENT` (the K most recent
62 tool **turns** kept verbatim — each turn is an assistant tool_use plus its results),
63 `CODEARBITER_PRUNE_MAXBYTES`. Enabling is the user's explicit choice — never set it unbidden.
64 In `dry` mode the service writes no transcript but appends each would-be prune to
65 `~/.codearbiter/metrics/prune-dry.jsonl` (path override: `CODEARBITER_PRUNE_METRICS`) for
66 data collection; in `on` mode the executed prunes are recorded in `~/.codearbiter/prune.log`.
67 If a prior service-mode prune was killed mid-write, the next run self-heals the transcript
68 from the newest backup in `~/.codearbiter/prune-backups/` before doing anything else.
69
70 **Cold-miss nudge** [Feature Forge — `preview`]: when `CODEARBITER_PRUNE` is `on`, an
71 optional submit-time speed bump warns once before a cold cache re-cache lands on bloated
72 context. Enable with `CODEARBITER_PRUNE_NUDGE=on` (default `off`). When all arming conditions
73 hold (idle ≥ `CODEARBITER_PRUNE_NUDGE_IDLE_SECS`, default 240 s; estimated model-context
74 tokens freed ≥
75 `CODEARBITER_PRUNE_NUDGE_MIN_TOKENS`, default 80 000), the hook blocks the submit once with
76 an advisory on stderr and returns exit code 2. File-only sidecar reduction never arms it. The
77 advisory names the approximate avoidable context-token count and the host-native actions that
78 move the re-cache to pruned context:
79 native compaction or a normal exit + resume/restart. Resubmitting immediately proceeds. The block fires at most
80 once per cold window; a subsequent warm submit (idle < floor) resets the window so the next
81 genuine cold stretch re-arms. The gate is strictly opt-in, never fires in `dry`/`off` mode,
82 and fails open on any error — a pruner fault will never block the session.
83
84## When NOT to use
85
86- Context bar nowhere near compaction — the most recent turns are protected anyway.
87- Install health → `/ca-doctor`.
88- Project progress → `/ca-status`.
89
90## Hard gate
91
92- MUST NOT run `--execute` against the **live** session's transcript — the tool refuses a
93 recently-modified file by construction; manual `run` targets copies or old sessions only.
94- MUST surface the native-boundary-only gains limitation whenever a user expects an immediate
95 active-file context drop.
96- MUST NOT enable the service (`CODEARBITER_PRUNE=on`) on behalf of the user — explain and let
97 them decide.