← 返回
未分类

session-compress

Compress OpenClaw session .jsonl files by trimming old messages while preserving system messages, recent turns, and task-relevant context.
压缩 OpenClaw 会话 .jsonl 文件,裁剪旧消息,保留系统消息、最近轮次和任务相关上下文。
zzqsama066 zzqsama066 来源
未分类 clawhub v1.0.1 1 版本 99714.3 Key: 无需
★ 0
Stars
📥 349
下载
💾 0
安装
1
版本
#latest#openclaw#utility

概述

session-compress

Compress an OpenClaw .jsonl session file by trimming old messages while retaining active task context and basic message structure.

When to Use

  • User asks to compress, shrink, or trim a session file
  • Session context is too large and causing performance issues
  • Before archiving an old session but wanting to preserve task memory

Workflow

Step 1: Identify the target file

Session files are located at:

<OPENCLAW_DIR>\agents\main\sessions\*.jsonl

List files by size to find candidates:

Get-ChildItem <OPENCLAW_DIR>\agents\main\sessions\*.jsonl | Sort-Object Length -Descending | Select-Object Name, @{N='SizeMB';E={[math]::Round($_.Length/1MB,2)}}

Step 2: Dry run first

Always dry run before modifying anything:

powershell -File scripts/compress.ps1 -FilePath "<path-to-file>" -DryRun

Review: how many messages will be kept, what the output size will be.

Step 3: Compress

# 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>"

Compression Logic

  1. Always kept: All system role messages
  2. Always kept: Last 30 message turns (configurable via -KeepRecent)
  3. Conditionally kept (task context keywords): messages containing keywords like next step, todo, plan, task, pending, in progress, remember, dont forget, important
  4. Summarized: Culled messages are replaced with a single placeholder message — preserving the file structure so OpenClaw can still load it
  5. Deduplicated: No message appears twice in the output

Parameters

ParameterDefaultDescription
---------------------------------
-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

What Gets Preserved

Each message in the output .jsonl retains:

  • role (system / user / assistant)
  • content (as array of content blocks)
  • timestamp

What Gets Removed

  • Older messages not in the recent window and not flagged as task-relevant
  • Tool call metadata is stripped (content blocks are kept as text)

Important Notes

  • Always dry run first — compression is destructive unless -OutputPath is used
  • This skill is for the main agent session files only
  • After compression the file remains a valid .jsonl that OpenClaw can load normally

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-07 10:31 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 677 📥 325,784
ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,086 📥 813,822
ai-agent

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,231 📥 268,182