Compress an OpenClaw .jsonl session file by trimming old messages while retaining active task context and basic message structure.
Session files are located at:
text
<OPENCLAW_DIR>\agents\main\sessions\*.jsonl
List files by size to find candidates:
powershell
Get-ChildItem <OPENCLAW_DIR>\agents\main\sessions\*.jsonl | Sort-Object Length -Descending | Select-Object Name, @{N='SizeMB';E={[math]::Round($_.Length/1MB,2)}}
Always dry run before modifying anything:
powershell
powershell -File scripts/compress.ps1 -FilePath "<path-to-file>" -DryRun
Review: how many messages will be kept, what the output size will be.
powershell
# In-place compress (overwrites original):
powershell -File scripts/compress.ps1 -FilePath "<path-to-file>"
# Compress to a new file (preserves original):
powershell -File scripts/compress.ps1 -FilePath "<path-to-file>" -OutputPath "<new-path>"
system role messages-KeepRecent)next step, todo, plan, task, pending, in progress, remember, dont forget, importantParameterDefaultDescription-FilePath(required)Path to the .jsonl file-KeepRecent30Number of recent turns to always keep-OutputPath(none)If set, writes to a new file instead of overwriting-DryRunoffPreview without modifying files
Each message in the output .jsonl retains:
role (system / user / assistant)content (as array of content blocks)timestamp-OutputPath is used.jsonl that OpenClaw can load normally