compact-safe

compact-safe is a command for Claude Code from sefaertunc/Worclaude. It costs 8 tokens per session (806 once invoked), scanned D, original, MIT.

A safer context-compaction command that checks for uncommitted work, unfinished tasks, recent failures, and other risks before shortening the conversation context.

In plain words
What is it for?
Use it before compacting a coding session to review risks and choose whether to commit, stash, proceed, or cancel.
Why use it?
Compaction can lose detailed file references and implementation context, especially when work is unfinished or destructive actions were recent.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/sefaertunc/worclaude/compact-safe
Clone the repo
git clone --depth 1 https://github.com/sefaertunc/Worclaude

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for compact-safe

README.md
[![agentmods](https://agentmods.dev/badge/commands/sefaertunc/worclaude/compact-safe.svg)](https://agentmods.dev/commands/sefaertunc/worclaude/compact-safe)
Your own site
<a href="https://agentmods.dev/commands/sefaertunc/worclaude/compact-safe"><img src="https://agentmods.dev/badge/commands/sefaertunc/worclaude/compact-safe.svg" alt="Measured on agentmods" height="20"></a>
Per session 8 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 806 The whole file, excluding the scripts and references it only reads on demand.
Security scan D 2 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00008 $0.00806
Opus 5 $0.00004 $0.00403
Sonnet 5 $0.00002 $0.00161
Haiku 4.5 $0.00001 $0.00081

Measured 4d ago against content hash d3d57483d287, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade D, and why

compact-safe scanned grade D with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

node -e 'const s = require("./.claude/settings.json"); console.log(JSON.stringify(s.hooks?.PostCompact || []))'

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

patterns: `rm -rf`, `git reset --hard`, `git push --force`, `DROP TABLE`,
.claude/commands/compact-safe.md · 90 lines

How it starts

The opening of the file, as written. The whole thing — 90 lines — stays where its author put it; the contents beside it link to each section on GitHub.

/compact-safe adds pre-flight safety checks to bare /compact. Compaction loses fine-grained conversation state; running it on a session with uncommitted work, mid-implementation TODOs, or recent destructive operations risks losing context the user expected to keep. This command surfaces those risks before triggering compaction.

Pre-flight safety checks

Run all four checks. Report the findings as a short table. Stop and ask the user for confirmation if any check trips.

1. Uncommitted changes

git status --porcelain

If output is non-empty, surface a warning: "You have N uncommitted changes. Compaction loses references to specific files and line numbers — consider committing or stashing first."

Offer via AskUserQuestion:

  • commit — write a WIP commit before compacting (reversible)
  • stash — stash changes, compact, then git stash pop after
  • proceed — compact anyway (you accept the risk)
  • cancel — abort compaction

2. In-flight work signals

Scan for indicators that compaction would lose useful context:

  • Recent test failures — check the last npm test / vitest / pytest output if available. If there are failing tests, warn the user and offer to run /verify first to capture the failure list before compacting.
  • Mid-implementation TODOsgrep -rn "TODO(claude)\|FIXME\|XXX" src/ on files changed in the last hour (git diff --name-only HEAD@{1.hour.ago} if available, otherwise --name-only HEAD~1). If matches exist, surface them — they may be context Claude needs to remember.

3. Recent destructive operations

Check the last 20 commands in transcript or shell history for destructive patterns: rm -rf, git reset --hard, git push --force, DROP TABLE, etc. If any were run within the last 30 minutes, warn the user — they may want to keep the conversation context until they verify the destructive op landed correctly.

4. PostCompact hook verification

Confirm .claude/settings.json has a PostCompact hook configured. Without it, compaction strips CLAUDE.md / PROGRESS.md context permanently. If the hook is missing, surface a warning and stop — compacting in this state silently breaks Claude's session orientation.

Read the full file on GitHub · 90 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 90 lines · 8 tokens per session scan D d3d57483d287

Subscribe to this mod's changes

compact-safe is a command published in the GitHub repository sefaertunc/Worclaude (4 stars, last pushed 25d ago), licensed MIT. It adds 8 tokens to every session and 806 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it D with 2 findings (reads agent configuration directories, recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.