Add compact

From sbusso/claudeclaw · View interactive version

Add compact is an AI agent skill from the GitHub repository sbusso/claudeclaw. Add /compact command for manual context compaction. Solves context rot in long sessions by forwarding the SDK's built-in /compact slash command. Main-group or trusted sender only.

How to use this skill

Skill file

Add /compact Command

Adds a /compact session command that compacts conversation history to fight context rot in long-running sessions. Uses the Claude Agent SDK's built-in /compact slash command — no synthetic system prompts.

Session contract: /compact keeps the same logical session alive. The SDK returns a new session ID after compaction (via the init system message), which the agent-runner forwards to the orchestrator as newSessionId. No destructive reset occurs — the agent retains summarized context.

Phase 1: Pre-flight

Check if src/session-commands.ts exists:

test -f src/session-commands.ts && echo "Already applied" || echo "Not applied"

If already applied, skip to Phase 3 (Verify).

Phase 2: Apply Code Changes

Merge the skill branch:

git fetch upstream skill/compact
git merge upstream/skill/compact

Note: upstream is the remote pointing to sbusso/claudeclaw. If using a different remote name, substitute accordingly.

This adds:

Validate

npm test
npm run build

Rebuild container

./src/runtimes/docker/build.sh

Service name: Derived from the directory name: com.claudeclaw.<dirname> (macOS) / claudeclaw-<dirname> (Linux). For example, if cwd is my-assistant, the service is com.claudeclaw.my-assistant. Determine the correct service name before running service commands below.

Restart service

launchctl kickstart -k gui/$(id -u)/com.claudeclaw  # macOS
# Linux: systemctl --user restart claudeclaw

Phase 3: Verify

Integration Test

  1. Start ClaudeClaw in dev mode: npm run dev
  2. From the main group (self-chat), send exactly: /compact
  3. Verify:
  1. From a non-main group as a non-admin user, send: @<assistant> /compact
  2. Verify:
  1. From a non-main group as the admin (device owner / is_from_me), send: @<assistant> /compact
  2. Verify:
  1. While an active container is running for the main group, send /compact
  2. Verify:
  1. Send a normal message, then /compact, then another normal message in quick succession (same polling batch):
  2. Verify:
  1. From a non-main group as a non-admin user, send @<assistant> /compact:
  2. Verify:
  1. From a non-main group (with requiresTrigger enabled) as a non-admin user, send bare /compact (no trigger prefix):
  2. Verify:
  1. After compaction, verify no auto-compaction behavior — only manual /compact triggers it

Validation on Fresh Clone

git clone <your-fork> /tmp/claudeclaw-test
cd /tmp/claudeclaw-test
claude  # then run /add-compact
npm run build
npm test
./src/runtimes/docker/build.sh
# Manual: send /compact from main group, verify compaction + continuation
# Manual: send @<assistant> /compact from non-main as non-admin, verify denial
# Manual: send @<assistant> /compact from non-main as admin, verify allowed
# Manual: verify no auto-compaction behavior

Security Constraints

What This Does NOT Do

Troubleshooting

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.