@brandry/claude-jsonl-compressor 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md CHANGED
@@ -1,345 +1,230 @@
1
- ---
2
- name: claude-jsonl-compressor
3
- description: Compress one Claude Code JSONL session with strict active-branch isolation, model-authored semantic summaries by default, recent raw context for rewind, validated compact-style output, transactional backup/replacement for one live .claude/projects file, and an independent byte-preserving Read.pages compatibility repair. Use for compressing, shrinking, summarizing, preflighting, replacing, or repairing Claude CLI/Claude Code JSONL transcripts.
4
- ---
5
-
6
- # Claude JSONL Compressor
7
-
8
- Operate on exactly one authoritative JSONL. Never merge another branch or session automatically.
9
-
10
- Public package: `1.0.0`. Internal engine: `v10`. Model-pack schema: `v11`.
11
-
12
- ## Safety Invariants
13
-
14
- 1. Model-assisted semantic summary generation is the default. Use deterministic summary only when the user explicitly requests fallback.
15
- 2. Determine the active branch from structure before reading text for semantic importance.
16
- 3. The physically last `type: "last-prompt"` record is the automatic authority. Do not skip a malformed latest pointer to revive an older one.
17
- 4. Rewound/inactive branch text must not enter the model pack, model summary, deterministic appendix, prior-summary verbatim block, recent raw records, side records, or output API-message chain.
18
- 5. Only the active-chain old segment may be summarized. The model cannot select a leaf, change the partition, or restore excluded records.
19
- 6. Preserve the recent active suffix byte-for-field except for the single parent edge that connects its first record to the new compact summary and optional explicit `sessionId` normalization.
20
- 7. Preserve unknown fields on retained records. Project the authoritative `last-prompt` object and retain its unknown fields; output exactly one final pointer.
21
- 8. Never install `tiktoken`, `regex`, PyYAML, or another package for this workflow. Runtime code uses the Python standard library.
22
- 9. Never write process files inside `.claude`. A live replacement may leave only the requested JSONL and its numbered backup beside it.
23
- 10. Do not run Claude CLI for validation unless the user explicitly asks. Structural validation is mandatory regardless.
24
- 11. Do not put project-specific facts, paths, identifiers, or prior-session content into this skill.
25
- 12. Treat the model summary as model-authored and source-anchored, not model-validated truth. Require v11 request binding and one exact source excerpt per mandatory semantic/prior-summary record.
26
-
27
- ## Resolve The Operation First
28
-
29
- ### Candidate Mode
30
-
31
- Use when the user provides distinct input and output paths.
32
-
33
- - Do not modify the input.
34
- - Write the candidate to the requested output.
35
- - Write `<output>.report.md` and `<output>.validation.json` beside it.
36
- - Refuse identical input/output paths.
37
- - Refuse a direct output under `.claude/projects`; use live replacement mode there.
38
-
39
- ### Live Replacement Mode
40
-
41
- Use when the user explicitly asks to compress one existing `.claude/projects/<project>/<session>.jsonl` in place, including prompts that give the same path as input and output.
42
-
43
- - Treat the path as `--input`; do not pass `--output`.
44
- - Require an existing regular `.jsonl` target under `.claude/projects`; use `--replace-original`, `--confirm-session-closed`, and a work directory outside the entire `.claude` tree. The flag records caller acknowledgement; it does not detect a process lock.
45
- - The script creates `<session>.jsonl.backup`, then `.backup1`, `.backup2`, and so on with exclusive creation.
46
- - Candidate, model pack, model summary, validation and report files stay under `--work-dir`.
47
- - The filename stem remains the target session ID unless the user explicitly supplies another one.
48
- - Replacement occurs only after candidate validation and a full-byte SHA-256 source recheck.
49
- - A failed post-replacement validation restores the original bytes and returns an error.
50
-
51
- ### Read.pages Compatibility Repair
52
-
53
- This is a separate operation. Do not invoke it implicitly during compression.
54
-
55
- - It removes only the exact `pages` member from structured assistant `tool_use` blocks whose name is exactly `Read`, whose `input.file_path` exists, and whose tool ID has a matching `tool_result` in the selected scope.
56
- - Default scope is the strict active chain. `--scope all` is explicit.
57
- - Pending calls are reported and left unchanged.
58
- - All bytes outside the planned JSON-member deletion spans remain identical, including BOM, CRLF/LF, escaping, Unicode and unknown fields.
59
-
60
- ## Mandatory Preflight
61
-
62
- Resolve the skill root without hardcoding a user's machine:
63
-
64
- ```powershell
65
- $skill = "$env:USERPROFILE\.codex\skills\claude-jsonl-compressor"
66
- ```
67
-
68
- Analyze the authoritative resume path before making a model pack or candidate:
69
-
70
- ```powershell
71
- python "$skill\scripts\compress_claude_jsonl.py" `
72
- --input "C:\path\session.jsonl" `
73
- --analyze-resume-path
74
- ```
75
-
76
- Use `reasonCode` as the exact machine-readable outcome and `status` only as its
77
- coarse category. The stable pairs are documented in
78
- `references/claude-jsonl-compression-format.md`.
79
-
80
- Strict active mode stops before writing any pack, candidate, sidecar or backup when the authority is absent, malformed, dangling, cyclic, has unsafe/recurring session lineage, has ordinary-message physical parent inversion, contains a malformed `parentUuid`, or is UUID-ambiguous.
81
-
82
- After partitioning, run the shared validator on the authoritative logical active chain plus its projected pointer. Old malformed tool exchanges, duplicate tool IDs, or compact-pair metadata on that chain must stop before semantic evidence generation; damage confined to excluded inactive branches remains excluded and does not become summary text.
83
-
84
- When strict preflight reports an unusual or ambiguous topology, stop with zero writes and explain the structural status without copying excluded transcript text. Ask the user to confirm a specific recovery control only when one is applicable. Do not infer confirmation from the original compression request, and never retry automatically in compatibility mode. The Python CLI remains non-interactive.
85
-
86
- Recovery controls:
87
-
88
- - Use `--resume-leaf UUID` only when the user explicitly identifies the desired leaf. The report marks `manualOverride: true` and labels the mode `active-chain-manual-override`, not default strict `active-chain`.
89
- - Use `--preserve-physical-tail` only when the user explicitly requests compatibility behavior. It does not provide inactive-branch exclusion guarantees.
90
- - Default post-pointer extension is zero. Use `--max-post-last-prompt-extension N` only for a physically post-pointer, direct, same-session, tool-result-only closure of every pending tool ID. Ordinary user/assistant conversation, system/hook records, partial closure and unrelated results are rejected.
91
-
92
- Observed-format compatibility remains narrow and deterministic:
93
-
94
- - An acyclic parent chain may contain physically inverted edges only when every such edge is same-session `attachment -> attachment`. Output serializes those records in logical parent order.
95
- - A mixed-session active chain is accepted only when session runs move forward without returning to an earlier session and both the final leaf and authoritative pointer use the final session. Every earlier session is forced into `summaryIndexes`; the recent raw suffix contains only the final session.
96
- - If tool pairing would move the raw cut back across that session transition, stop. Do not normalize or invent a cross-session raw exchange.
97
-
98
- ## Default Model-Assisted Workflow
99
-
100
- The Python program does not call a model. Codex performs the semantic step between two deterministic script passes.
101
-
102
- This addresses the 1M-versus-200k context problem by removing inactive branches, recent raw records, low-value payload repetition and non-semantic structure before model review. The bounded pack contains a complete full-text ledger of every non-empty older active human message and every older active assistant `text`/`thinking` message, plus selected source/tool evidence and line anchors. A source-text warning such as U+FFFD is reported but does not discard the rest of a mandatory record. The default pack ceilings are 500,000 characters and a conservative 150,000-token local estimate, leaving room in a typical 200k summarizer context. If mandatory evidence does not fit, generation stops instead of sampling it away; raise a ceiling only when the chosen model can read the result.
103
-
104
- ### Pass 1: Generate The Evidence Pack
105
-
106
- Use identical selection settings in both passes:
107
-
108
- ```powershell
109
- python "$skill\scripts\compress_claude_jsonl.py" `
110
- --input "C:\path\session.jsonl" `
111
- --write-model-pack "C:\work\run\session.model-pack.md" `
112
- --target-ratio 0.30 `
113
- --min-recent-records 120 `
114
- --summary-char-budget 60000 `
115
- --target-estimated-tokens 150000 `
116
- --model-pack-char-budget 500000 `
117
- --model-pack-estimated-token-budget 150000
118
- ```
119
-
120
- The two pack ceilings apply together. Complete human/assistant semantic records,
121
- prior summaries, handoff lines and required groups are mandatory. Optional
122
- source/tool/system/error evidence stops at either ceiling and reports
123
- `evidence_truncated`. Never install a tokenizer for this workflow.
124
-
125
- When the user gives an approximate compressed Messages-token ceiling, pass it directly instead of inventing a tokenizer workflow:
126
-
127
- ```powershell
128
- --target-estimated-tokens 150000
129
- ```
130
-
131
- This candidate-output gate is distinct from `--model-pack-estimated-token-budget`.
132
- It is the built-in zero-dependency estimate for transcript Messages only. It
133
- covers complete retained structured message payloads, including thinking,
134
- `tool_use.input`, `tool_result`, and `toolUseResult`. It excludes the system
135
- prompt, tool schemas, MCP, agents, skills, memory files and runtime additions.
136
- Never claim it predicts Claude `/context` total exactly. Treat `--target-ratio`
137
- only as approximate byte planning; only an explicit
138
- `--target-estimated-tokens` value is a hard candidate-output estimate gate.
139
-
140
- Require `--summary-char-budget >= 4000`. Do not weaken this floor or publish a blank compact summary.
141
-
142
- For `.claude` input, the pack path must be outside `.claude`.
143
-
144
- ### Model Step: Write The Summary
145
-
146
- Read the generated pack and write a Markdown summary from that pack only.
147
-
148
- Copy its leading metadata comment exactly. Schema v11 binds:
149
-
150
- - `source_sha256`
151
- - `summary_source_sha256`
152
- - `evidence_anchor_lines_digest`
153
- - `required_anchor_groups_digest`
154
- - `handoff_summary_digest`
155
- - `pack_request_digest`
156
- - `required_claim_sources_digest`
157
-
158
- Summary rules:
159
-
160
- 1. Cite every substantive JSONL-backed statement with one or more displayed `L<number>` anchors.
161
- 2. Cite every handoff-backed statement with a displayed `H<number>` anchor.
162
- 3. Never cite lines or H anchors absent from the pack. Cite at least one displayed L anchor from every required coverage group, including every individual human/assistant semantic record and each prior compact summary group.
163
- 4. Preserve chronology and event time. When decisions conflict, identify the later current decision and retain the earlier decision as superseded history with its reason.
164
- 5. Preserve user goals, exact constraints, final instructions, questions and wording that changes interpretation.
165
- 6. Preserve assistant/model research decisions, reasons, evidence checks, rejected routes, uncertainty and supersessions in any language.
166
- 7. Weight evidence in this order:
167
- - hard user constraints and current goals
168
- - current decisions and supersessions
169
- - assistant/model research conclusions with reasons and verification
170
- - source/tool/file evidence supporting those decisions
171
- - unresolved risks and unknowns
172
- - ordinary progress, repeated commands and low-information logs
173
- 8. For humanities, law, art, design, brand strategy, planning, history, feasibility and document research, preserve historical nuance, provenance, interpretive changes and minority/abandoned positions that explain the current conclusion.
174
- 9. For software and engineering, preserve contracts, architecture decisions, failure causes, migrations, compatibility constraints, tests and operational state.
175
- 10. Use all nine exact `##` sections printed under `Required Final Summary Shape`, in order; every section needs an L or H evidence anchor. Do not add HTML comments or Markdown headings beyond the exact leading metadata comment and required headings.
176
- 11. Use the exact whole line `Unknown from provided anchors.` when evidence is insufficient. Do not append a claim to that line; every other substantive line needs visible L/H support.
177
- 12. Treat every explicitly supplied handoff line as complete evidence. Cite every generated early/middle/late/latest H coverage group. If the complete handoff and mandatory pack sections do not fit either pack ceiling, stop; raise `--model-pack-char-budget` or `--model-pack-estimated-token-budget` only within the summarizing model's capacity.
178
- 13. Do not edit JSONL, UUIDs, parent links, tool pairs, compact records or pointer records manually.
179
- 14. Under `## Evidence and Source Anchors`, include exactly one `### Mandatory Evidence Coverage` subsection. For every anchor under `Required Claim Support`, add exactly `- L42 support_text_json="exact source substring" disposition=covered`; the JSON string must be a meaningful exact substring of that L record. Do not substitute generic anchor prose.
180
-
181
- Schema v11 gives each non-empty older active human message and each older active assistant `text`/`thinking` message its own full-text required L group and claim-source entry. It also reserves early/middle/late/latest, source/tool and prior-summary coverage. Every active-chain prior compact summary and every physical line of an explicitly supplied handoff are included in full. If mandatory evidence does not fit either pack ceiling, stop and report the capacity boundary. Do not truncate, sample or bypass the gate.
182
-
183
- ### Pass 2: Validate And Compress
184
-
185
- ```powershell
186
- python "$skill\scripts\compress_claude_jsonl.py" `
187
- --input "C:\path\session.jsonl" `
188
- --output "C:\path\compressed.jsonl" `
189
- --target-ratio 0.30 `
190
- --min-recent-records 120 `
191
- --summary-char-budget 60000 `
192
- --target-estimated-tokens 150000 `
193
- --model-pack-char-budget 500000 `
194
- --model-pack-estimated-token-budget 150000 `
195
- --model-summary "C:\work\run\session.model-summary.md"
196
- ```
197
-
198
- Repeat every non-default pass-1 option in pass 2, including candidate token target, checkpoint policy, explicit leaf, handoff file, both model-pack budgets, templates and prior-summary policy. The v11 `pack_request_digest` binds those options and loaded resources; the script rejects a summary whose request, source, evidence, claim-source hashes or anchors do not match the regenerated pack.
199
-
200
- Use this only on explicit request for deterministic fallback:
201
-
202
- ```powershell
203
- --deterministic-summary
204
- ```
205
-
206
- Do not silently choose deterministic fallback because model authoring is inconvenient.
207
-
208
- ## Live Replacement Commands
209
-
210
- Generate the model pack outside `.claude`, write the model summary, then run:
211
-
212
- ```powershell
213
- python "$skill\scripts\compress_claude_jsonl.py" `
214
- --input "$env:USERPROFILE\.claude\projects\PROJECT\SESSION.jsonl" `
215
- --replace-original `
216
- --confirm-session-closed `
217
- --work-dir "C:\work\claude-compression\SESSION-TIMESTAMP" `
218
- --model-pack-estimated-token-budget 150000 `
219
- --target-estimated-tokens 150000 `
220
- --model-summary "C:\work\claude-compression\SESSION-TIMESTAMP\session.model-summary.md"
221
- ```
222
-
223
- By default the backup stays beside the live JSONL. Use an external backup directory only when explicitly requested:
224
-
225
- ```powershell
226
- --backup-dir "C:\work\claude-compression\SESSION-TIMESTAMP\backups"
227
- ```
228
-
229
- Do not hand-copy a candidate over a live session after a refusal.
230
-
231
- ## Checkpoint Policy
232
-
233
- Conversation rewind topology and file checkpoints are separate planes.
234
-
235
- - `--checkpoint-policy active-correlated` is the default. It keeps only recent UUID-less `file-history-snapshot` records that structurally correlate to retained active records.
236
- - `--checkpoint-policy none` keeps no UUID-less file-history snapshots.
237
- - `--checkpoint-policy preserve-recent` is rejected in strict active-chain mode. It is meaningful only with explicit `--preserve-physical-tail`, whose report is labeled `physical-tail-compatibility` and which has no inactive-branch isolation guarantee.
238
- - `--max-file-history-snapshots N` caps retained snapshots.
239
-
240
- Never claim that compressed JSONL alone guarantees complete file-state rewind. The report states what snapshot side records were retained.
241
-
242
- ## Repeated Compression
243
-
244
- Default behavior folds old compact summaries into one current compact summary. The output must contain one current compact pair.
245
-
246
- Treat an older `preservedMessages` list as a historical snapshot. A later rewind may make its tail diverge from the current authoritative chain; report that warning, exclude the old tail, and continue only when the current chain itself is valid. Require every newly generated candidate to rebuild the snapshot so it exactly matches the candidate's current chain.
247
-
248
- When the user explicitly asks to preserve existing summaries verbatim, repeat this flag in both model-pack and compression passes:
249
-
250
- ```powershell
251
- --preserve-prior-summaries-verbatim
252
- ```
253
-
254
- The script may expand the summary character budget to 1.5x. If exact preservation still does not fit, it uses the normal folded path and reports `fallback-folded`. It does not stack old compact pairs into the active chain.
255
-
256
- For third and later rounds, apply chronology again. Prior summaries are historical evidence, not automatically current truth. Preserve old decisions and reasons while marking later supersessions.
257
-
258
- ## Read.pages Repair Commands
259
-
260
- Scan without writing:
261
-
262
- ```powershell
263
- python "$skill\scripts\repair_claude_jsonl.py" `
264
- --input "C:\path\session.jsonl" `
265
- --scan-only
266
- ```
267
-
268
- Write a separate candidate and require the expected patch count:
269
-
270
- ```powershell
271
- python "$skill\scripts\repair_claude_jsonl.py" `
272
- --input "C:\path\session.jsonl" `
273
- --output "C:\path\session.repaired.jsonl" `
274
- --expect-matches 2
275
- ```
276
-
277
- Replace one live session transactionally:
278
-
279
- ```powershell
280
- python "$skill\scripts\repair_claude_jsonl.py" `
281
- --input "$env:USERPROFILE\.claude\projects\PROJECT\SESSION.jsonl" `
282
- --replace-original `
283
- --confirm-session-closed `
284
- --work-dir "C:\work\claude-repair\SESSION-TIMESTAMP" `
285
- --expect-matches 2
286
- ```
287
-
288
- Use `--scope all` only when the user explicitly wants inactive physical branches repaired too.
289
-
290
- An automatic repair additionally requires exactly one later result with the same non-empty `sessionId` and a `sourceToolAssistantUUID` equal to the Read tool-use assistant UUID. Candidate publication must re-read and validate the actual published bytes and prove an idempotent second scan before success.
291
-
292
- ## Validation And Stop Condition
293
-
294
- Before reporting success, require fresh evidence for the selected operation:
295
-
296
- Compression:
297
-
298
- - candidate validation `ok: true`
299
- - no duplicate UUID, missing parent, cross-session parent or tool-pair error
300
- - no empty/duplicate active tool ID; a partial ordered-subset result is accepted only as an explicit compatibility warning and count
301
- - exactly one current Codex compact boundary/summary pair on the final pointer chain
302
- - one projected final `last-prompt`
303
- - dead-branch counts reported without branch text
304
- - any observed attachment-order/session-lineage compatibility is explicitly reported, and output raw records remain one current-session chain
305
- - explicit `--target-estimated-tokens` ceiling met under the complete-structure local estimate; an approximate ratio alone is not a hard success claim
306
- - input unchanged in candidate mode
307
- - backup bytes equal original bytes in live mode
308
- - replacement validation `ok: true` in live mode
309
-
310
- Repair:
311
-
312
- - expected match count satisfied when supplied
313
- - byte validation `ok: true`
314
- - UUID/parent and tool-ID signatures unchanged
315
- - second pass finds zero patchable matches
316
- - shared full-transcript validation `ok: true`
317
- - input unchanged in candidate mode
318
- - numbered backup equals original in live mode
319
-
320
- Structural validation alone is an observed-format check, not an Anthropic format guarantee. If the user permits Claude CLI testing, report `/resume`, `/context`, recent conversation rewind and recent file rewind as separate observations.
321
-
322
- ## Session Location
323
-
324
- Prefer an exact path or filename. To locate one session without reading transcript bodies:
325
-
326
- ```powershell
327
- python "$skill\scripts\claude_session_tools.py" `
328
- --root "$env:USERPROFILE\.claude\projects" `
329
- --query "SESSION.jsonl"
330
- ```
331
-
332
- Use `--scan-titles` only when the user supplies a title and permits title scanning. Multiple matches are an error. Never broaden a single-target run into directory-wide compression.
333
-
334
- ## Failure Rules
335
-
336
- - A strict topology failure produces no pack, candidate, sidecar or backup.
337
- - For a special or ambiguous topology, report the strict failure and pause. Offer only the exact explicit control that matches the diagnosis, state the lost guarantee, and require a new user confirmation before running it. Manual/spliced files generally require `--preserve-physical-tail`, which forfeits inactive-branch and rewind isolation.
338
- - A model-summary validation failure requires regenerating the pack/summary with identical settings; do not weaken validation.
339
- - A tool-pair failure requires moving the cut earlier or diagnosing source inconsistency; do not invent tool results.
340
- - A source hash change aborts live replacement.
341
- - Live replacement requires the Claude process for that session to be closed. The transaction validates immutable candidate bytes, exclusively creates and verifies a numbered backup, captures the actual old target, verifies its full SHA-256, installs the candidate, and verifies the published bytes and structure. If another process recreates the target during capture, preserve the external target and recovery backups and fail without publishing. Parent-directory fsync is best effort and reported because platform support differs.
342
- - A write/fsync/validation/replace failure returns nonzero. The transaction restores the captured original bytes when replacement began; if restoration itself fails, it raises a high-priority error and retains the numbered backup for recovery.
343
- - Each unique live-transaction temporary path is checked against its recorded filesystem identity and frozen bytes before cleanup. A detected mismatch is retained and reported; a pre-commit failure also includes any cleanup residue in its error. Portable pathname cleanup cannot atomically bind that final delete to the earlier identity check across Windows, Linux, and macOS, so require a closed session and no other writer. Do not claim protection from hostile same-account directory manipulation.
344
- - If a valid live replacement commits but final sidecar/report publication fails, return exit code 3 with `committed-report-failed` and the committed hashes/backup labels. Do not rerun blindly or describe that state as an uncommitted failure.
345
- - Keep reports and temporary work outside `.claude`; do not leave ad hoc files in live session directories.
1
+ ---
2
+ name: claude-jsonl-compressor
3
+ description: Compress one Claude Code JSONL using a source-anchored model summary, strict active-branch isolation and recent raw context, or explicitly repair historical Read.pages compatibility. Supports candidate output and transactional replacement of one closed live session.
4
+ ---
5
+
6
+ # Claude JSONL Compressor
7
+
8
+ Package **1.1.0**, engine **v10**, model-pack **v11**, report **1**.
9
+
10
+ Reduce Claude context/cache costs while preserving the user's required history.
11
+ Operate on exactly one authoritative JSONL. Never merge sessions or revive
12
+ rewound branches. Python uses only the standard library and calls no model or
13
+ network; Codex authors the semantic summary between two deterministic passes.
14
+ Do not install tokenizers, PyYAML or other packages. Do not run Claude CLI unless
15
+ the user explicitly requests it.
16
+
17
+ ## Choose the operation and unique source
18
+
19
+ - Prefer exact path, filename or session ID. For an explicitly requested title
20
+ lookup, run `scripts/claude_session_tools.py --root ROOT --query TITLE --scan-titles`.
21
+ Without title scanning the helper reads no transcript bodies. Exact ID/path
22
+ matches take precedence; multiple matches stop. It uses the latest attributable
23
+ custom title, falling back to automatic title. Old names are not aliases.
24
+ - **Candidate:** distinct input/output paths; source stays unchanged. Output,
25
+ report and validation live outside the entire `.claude` tree.
26
+ - **Live replacement:** user requests in-place compression of one existing
27
+ `.claude/projects/PROJECT/SESSION.jsonl` (including identical input/output).
28
+ Use input only, `--replace-original --confirm-session-closed --work-dir WORK`.
29
+ WORK and all process files must be outside `.claude`. Closed-session
30
+ acknowledgement is a caller assertion, not lock detection. Use the original
31
+ filename stem as session ID unless another is explicitly requested.
32
+ - **Read.pages repair:** a separate, explicitly requested operation; never run
33
+ it implicitly as part of compression. See the repair section below.
34
+
35
+ Resolve the skill directory from the environment, for example:
36
+
37
+ ```powershell
38
+ $skill = "$env:USERPROFILE\.codex\skills\claude-jsonl-compressor"
39
+ ```
40
+
41
+ ## Preflight and choose affordable evidence
42
+
43
+ Run `--preflight` before reading the source for semantic importance, using the
44
+ same selection settings intended for both passes. `--analyze-resume-path` remains
45
+ available as the smaller topology-only diagnostic.
46
+
47
+ ```powershell
48
+ python "$skill\scripts\compress_claude_jsonl.py" `
49
+ --input "C:\data\session.jsonl" --preflight `
50
+ --target-ratio 0.30 --min-recent-records 120 `
51
+ --summary-char-budget 60000 --target-estimated-tokens 150000 `
52
+ --tool-evidence full --citation-style scoped
53
+ ```
54
+
55
+ Choose settings deliberately:
56
+
57
+ - `--tool-evidence full` when document/research evidence lives in tool inputs or
58
+ results, or the user requires fine preservation of those contents. It includes
59
+ complete old active tool payloads, mixed text/tool records and auxiliary
60
+ results. Exact repeated long strings within one record use a visible alias;
61
+ different previews/results remain distinct. U+FFFD produces a warning, not
62
+ deletion of a complete record. Paths alone are not external file contents.
63
+ - CLI default `excerpt` is suitable when selected short tool evidence suffices;
64
+ it is not a full-payload fidelity guarantee. Do not silently downgrade a
65
+ research preservation requirement just to fit a budget.
66
+ - Use `--citation-style scoped` for new summaries, avoiding source labels like
67
+ L73/H1 being interpreted as citations. Legacy syntax remains a CLI option.
68
+ - To protect whole recent human-started turns, add `--min-recent-turns N`.
69
+ Only the final session after its latest compact is eligible. This may enlarge
70
+ raw context or leave nothing to summarize; never reduce a requested window
71
+ silently. Report actual human messages/snapshots, not promised rewind points.
72
+ - When the user requires existing summaries unchanged, use both
73
+ `--preserve-prior-summaries-verbatim --prior-summary-overflow error` in both
74
+ passes. This preserves exact old content including trailing whitespace and
75
+ appends a new layer inside one current compact summary. It stops on overflow.
76
+ The legacy default `fold` permits reported fallback-folded; do not use it for
77
+ an absolute no-rewrite request.
78
+
79
+ Preflight separates topology, selected-chain tool/compact validity, partition
80
+ and pack capacity. `nothing-to-summarize` needs no model work. A physical-tail
81
+ candidate and `end_turn` are diagnostics, not automatic authority. The latest
82
+ physical `last-prompt` remains authoritative even if malformed; reasonCode is
83
+ the machine-readable cause and status its coarse category. A selected chain
84
+ ending in tool_use may have a result later in the file; do not call the source
85
+ damaged solely because that selected window is incomplete.
86
+
87
+ The pack ceilings remain **500,000 characters / 150,000 local estimated tokens**.
88
+ The settings are `--model-pack-char-budget` and `--model-pack-estimated-token-budget`.
89
+ Full mandatory evidence that cannot fit stops before pack publication. Do not
90
+ automatically split into volumes, increase ceilings, invoke extra models or
91
+ repeatedly reread full history. Report the capacity boundary and available
92
+ choices. An explicit user request can authorize a larger budget or review
93
+ workflow within the model's capacity. `--target-estimated-tokens` gates candidate
94
+ Messages under a separate complete-structure local estimate; it does not predict
95
+ Claude `/context` total. `--target-ratio` is approximate byte planning only.
96
+
97
+ After successful preflight, freeze a numbered source backup before semantic
98
+ work and compare its SHA-256 with preflight. The locator's `--backup` creates
99
+ `.jsonl.backup`, `.backup1`, etc.; for an exact standalone file, its Python
100
+ `create_backup(Path(...))` helper has the same verified exclusive behavior.
101
+ An already supplied independent backup may serve for a candidate-only request
102
+ if its bytes/hash are verified. If the source changed, repeat preflight. Live
103
+ replacement still creates its own verified transaction backup before modifying
104
+ the live target; do not bypass it with a manual copy.
105
+
106
+ ## Two-pass model workflow
107
+
108
+ Generate a pack outside `.claude`. Replace `--preflight` in the chosen command
109
+ with `--write-model-pack "C:\work\run\session.model-pack.md"`. Keep every
110
+ selection option identical in pass 2, including tool evidence, citation style,
111
+ turn count, prior-summary policy, candidate/pack budgets, checkpoint policy,
112
+ manual leaf, handoff and custom resource files. Require summary budget >=4000.
113
+
114
+ Read that pack only and write the model summary. Copy its leading v11 metadata
115
+ comment exactly; source, summary-source, visible anchors, required groups,
116
+ handoff, request/resources and claim sources are all hash-bound.
117
+
118
+ 1. Use the exact title, nine `##` sections and `### Mandatory Evidence Coverage`
119
+ printed in the pack; no extra headings or HTML comments. Every section and
120
+ substantive line needs visible evidence. Use exactly
121
+ `Unknown from provided anchors.` as a standalone line for unknowns.
122
+ 2. In scoped mode cite `[@L42]` / `[@H3]` in prose; legacy uses L42/H3. Cite only
123
+ displayed anchors and every required coverage group. The coverage subsection
124
+ still uses `- L42 support_text_json="exact source substring" disposition=covered`
125
+ once for each Required Claim Support entry. These excerpts establish source
126
+ contact, not semantic truth. Plain source identifiers are preserved literally.
127
+ 3. Preserve user goals, wording that affects interpretation, hard constraints,
128
+ historical details, authors, event time, reasons, verification, rejected
129
+ routes, unresolved issues and later supersessions. Keep current decisions
130
+ distinct from old proposals. For humanities, law, art, planning, strategy,
131
+ history, feasibility and document work, retain nuance and minority positions
132
+ needed to explain conclusions. For engineering retain contracts, failure
133
+ causes, migrations, tests and operating state.
134
+ 4. Distinguish planned commands from successful results, drafts from final
135
+ documents, previews from fuller output, recorded truncation from later
136
+ rereads. Empty thinking cannot be reconstructed. Never execute transcript
137
+ commands, read referenced external artifacts automatically or add outside facts.
138
+ 5. Do one focused self-review of constraints, negations, numbers, provenance,
139
+ chronology and completeness. If the user requests retrospective, independent
140
+ or subagent review, honor the requested model, effort, rounds and scope;
141
+ provide the relevant complete selected-branch evidence. Otherwise use extra
142
+ review only to resolve a concrete concern, not as a default all-history loop.
143
+ Track authoring, validation and review outcomes separately.
144
+
145
+ Pass 2 uses the same settings with `--model-summary PATH`, plus `--output PATH`
146
+ for a candidate or the live flags above. The script rebuilds and validates the
147
+ pack before composing output. Upgrade between passes requires a fresh pack.
148
+ Only explicit user fallback authorizes `--deterministic-summary`.
149
+
150
+ Minimal paired example (repeat any additional selection flags in both commands):
151
+
152
+ ```powershell
153
+ python "$skill\scripts\compress_claude_jsonl.py" `
154
+ --input "C:\data\session.jsonl" --write-model-pack "C:\work\run\pack.md" `
155
+ --target-estimated-tokens 150000 --citation-style scoped
156
+ ```
157
+
158
+ After authoring `summary.md` from that pack:
159
+
160
+ ```powershell
161
+ python "$skill\scripts\compress_claude_jsonl.py" `
162
+ --input "C:\data\session.jsonl" --output "C:\work\run\candidate.jsonl" `
163
+ --model-summary "C:\work\run\summary.md" `
164
+ --target-estimated-tokens 150000 --citation-style scoped
165
+ ```
166
+
167
+ ## Structural boundaries and recovery
168
+
169
+ - Strict failures are zero-write: no pack, candidate, sidecar or backup. Do not
170
+ retry automatically in compatibility mode. A diagnosed recovery control needs
171
+ explicit user authorization; a compression request alone does not select it.
172
+ `--resume-leaf UUID` requires an explicitly identified leaf;
173
+ `--preserve-physical-tail` forfeits branch/rewind isolation and cannot use
174
+ positive `--min-recent-turns`.
175
+ - `--max-post-last-prompt-extension N` permits only a direct, same-session,
176
+ physically later tool-result-only closure of all pending calls. Ordinary
177
+ conversation, control records, branches and partial closure are rejected.
178
+ - Same-session attachment-only physical inversions can be serialized in logical
179
+ order. One-way mixed-session lineage can summarize earlier sessions while
180
+ retaining only the final session raw; tool pairs cannot cross that boundary.
181
+ - No inactive/rewound text may enter any evidence, prior-summary block, appendix,
182
+ raw history, side record or API chain. Older preservedMessages is historical;
183
+ rewind divergence warns without reviving the old tail. New compact metadata
184
+ must match the candidate chain, with exactly one current compact pair/pointer.
185
+ - Preserve unknown raw fields; only the first retained parent edge and explicit
186
+ session-ID normalization may change. Final attributable title metadata is
187
+ projected separately, including later renames, with unknown fields retained.
188
+ - Default checkpoint policy is `active-correlated`; `none` disables snapshots.
189
+ `preserve-recent` is only physical-tail compatibility. File rewind depends on
190
+ native snapshots, not JSONL alone; Bash file changes are not checkpointed.
191
+
192
+ ## Read.pages repair
193
+
194
+ ```powershell
195
+ python "$skill\scripts\repair_claude_jsonl.py" --input "C:\data\session.jsonl" --scan-only
196
+ ```
197
+
198
+ For a candidate add `--output PATH --expect-matches N`; live uses
199
+ `--replace-original --confirm-session-closed --work-dir WORK --expect-matches N`.
200
+ Default scope is strict active chain; `--scope all` needs explicit intent to
201
+ repair inactive records too. Exact Read tool_use pages deletion requires an
202
+ existing input.file_path member, one later same-session matching result and
203
+ matching sourceToolAssistantUUID. Pending calls stay unchanged. Bytes outside
204
+ planned member spans, UUID/parent/tool IDs, BOM/newlines/escaping remain identical.
205
+
206
+ ## Completion and transaction evidence
207
+
208
+ Compression requires fresh candidate `ok: true`, valid UUID/parent/session/tool
209
+ pairing, one current compact pair and projected pointer, branch counts without
210
+ branch text, exact title projection and any requested token ceiling. Explicit
211
+ ordered-subset tool results are warnings/counts, not silently complete exchanges.
212
+ Candidate mode must leave input unchanged. Repair also requires expected match
213
+ count, exact byte validation, published-byte reread and idempotent second scan.
214
+
215
+ Live mode additionally requires backup bytes equal original, source hash
216
+ recheck, published bytes/structure validation and correct transaction state.
217
+ Target/explicit backup directories need hard links; capability probes run first.
218
+ Source races, write/fsync/install/validation failures stop; replacement failures
219
+ restore captured original or retain numbered recovery assets and report failure.
220
+ Never overwrite an external claimant. Parent-directory fsync and temporary
221
+ identity cleanup are best effort, not hostile-writer or power-loss guarantees.
222
+ Committed report failure returns **exit 3 / committed-report-failed**; do not
223
+ rerun blindly or call it an uncommitted failure. Keep all process files/reports
224
+ outside `.claude`; only requested JSONL/numbered backups remain in live storage.
225
+
226
+ For unusual topology, detailed status pairs, snapshot/transaction semantics or
227
+ repair constraints, read [the format reference](references/claude-jsonl-compression-format.md)
228
+ only as needed. Structural validation is an observed-format check, not an
229
+ Anthropic guarantee. If runtime testing is authorized, report `/resume`,
230
+ `/context` Messages, conversation rewind and file rewind as separate observations.