100,000+ power users trust Cozempic to keep their Claude Code sessions lean. Context cleaning for Claude Code — remove the bloat, keep everything that matters, protect Agent Teams from context loss.
FAQ
cozempic is a Claude Code plugin with 5 hand-picked skills for development work, indexed on Flowy. Install it with the command on its page. It includes cozempic-doctor, diagnose, guard. Its skills do not fire on their own yet. Request auto-invocation to have Flowy route them as you prompt. Free and open source.
> /plugin marketplace add Ruya-AI/cozempic> /plugin install cozempic@cozempic
100,000+ power users trust Cozempic to keep their Claude Code sessions lean.
Context cleaning for Claude Code — remove the bloat, keep everything that matters, protect Agent Teams from context loss.
Claude Code sessions fill up with dead weight: progress ticks, thinking blocks, stale file reads, duplicate CLAUDE.md injections, base64 screenshots, oversized tool outputs, and metadata bloat. A typical session carries 8-46MB — most of it noise that inflates every API call.
Cozempic removes it with 18 composable strategies across 3 prescription tiers, while your actual conversation, decisions, and working context stay untouched. The guard daemon runs automatically — install once, forget about it.
cozempic reload, so interactive users get cozempic's higher-fidelity prune+resume on their own terms instead of falling back to lossy autocompact. Takes no action on its own; silence with COZEMPIC_NUDGE_OFF=1usage fields, cache hit rate, context % barZero external dependencies. Python 3.10+ stdlib only.
Pick your package manager. uvx/pipx/npm/pip are the lowest-friction (no Homebrew trust prompt — see the note below):
# uv — persistent install, always on PATH (recommended)
uv tool install cozempic
# uvx — run once without installing (handy to try it, but the guard daemon
# can't auto-start from an ephemeral env — use `uv tool install` for that)
uvx cozempic --help
# pipx — isolated user install, always on PATH
pipx install cozempic
# npm — global install
npm install -g cozempic
# pip (Python ≥ 3.10)
pip install cozempic
# Homebrew (macOS / Linux) — use the fully-qualified name (see note below)
brew install Ruya-AI/cozempic/cozempic
# Nix flake
nix profile install github:Ruya-AI/cozempic?dir=packaging/nix
Homebrew tap trust: recent Homebrew versions gate non-official taps behind an explicit trust step. The fully-qualified
brew install Ruya-AI/cozempic/cozempicabove trusts just this formula inline — no extra command. A barebrew install cozempic/brew upgrade cozempicwill instead error with "Refusing to load formula … from untrusted tap"; if you hit that, runbrew trust Ruya-AI/cozempiconce (or just prefer one of the install methods above, none of which have this gate).
AUR (yay -S cozempic) and MacPorts (port install py-cozempic) submissions are in progress — see packaging/README.md for status and PKGBUILD/Portfile sources.
That's it. Cozempic auto-initializes on first use — hooks are wired globally, guard daemon auto-starts on every Claude Code session. No manual setup needed. Opt out with COZEMPIC_NO_GLOBAL_INIT=1.
Cozempic auto-updates from PyPI by default, on purpose: Claude Code ships frequent changes to its session/context format, and auto-update is how a compatibility fix reaches you before a stale release can mishandle and lose your context. For most users that safety outweighs the convenience cost, so we recommend leaving it on. If you'd rather control it, set one of these — ideally in your shell profile (~/.zshrc / ~/.bashrc) so it applies before the first session wires anything:
| Goal | Set |
|---|---|
| Hold a specific reviewed version, keep hooks + guard running | export COZEMPIC_PIN=1.8.30 |
| Stop all auto-updates, keep hooks + guard running | export COZEMPIC_NO_AUTO_UPDATE=1 |
| No global hooks / no daemon at all (manual CLI only) | export COZEMPIC_NO_GLOBAL_INIT=1 |
Both COZEMPIC_NO_AUTO_UPDATE and COZEMPIC_PIN are honored by the Python updater, the SessionStart hook's shell upgrade, and the npm installer. COZEMPIC_PIN disables auto-update and warns (not auto-installs) if your running version drifts from the pin, so you stay on a version you've reviewed with a human in the loop. (Releases are published from CI via PyPI Trusted Publishing — no long-lived upload token — to reduce the chance of a compromised publish in the first place.)
Install cozempic (any method above), then inside Claude Code:
/plugin marketplace add Ruya-AI/cozempic
/plugin install cozempic
This gives you MCP tools, skills (/cozempic:diagnose, /cozempic:treat, etc.), and auto-wired hooks.
# Auto-detect and diagnose the current session
cozempic current --diagnose
# Dry-run the standard prescription
cozempic treat current
# Apply with backup
cozempic treat current --execute
# Go aggressive on a specific session
cozempic treat <session_id> -rx aggressive --execute
# Check for session corruption
cozempic doctor
# View behavioral digest rules
cozempic digest show
# Show all strategies & prescriptions
cozempic formulary
| # | Strategy | Tier | What It Does | Expected |
|---|---|---|---|---|
| 1 | compact-summary-collapse | gentle | Remove all pre-compaction messages (already in the summary) | 85-95% |
| 2 | attribution-snapshot-strip | gentle | Strip attribution-snapshot metadata entries | 0-2% |
| 3 | progress-collapse | gentle | Collapse consecutive and isolated progress tick messages | 40-48% |
| 4 | file-history-dedup | gentle | Deduplicate file-history-snapshot messages | 3-6% |
| 5 | metadata-strip | gentle | Strip token usage stats, stop_reason, costs | 1-3% |
| 6 | thinking-blocks | standard | Remove/truncate thinking content + signatures | 2-5% |
| 7 | tool-output-trim | standard | Trim large tool results (>8KB or >100 lines), microcompact-aware | 1-8% |
| 8 | tool-result-age | standard | Compact old tool results by age — minify mid-age, stub old | 10-40% |
| 9 | stale-reads | standard | Remove file reads superseded by later edits | 0.5-2% |
| 10 | system-reminder-dedup | standard | Deduplicate repeated system-reminder tags | 0.1-3% |
| 11 | tool-use-result-strip | standard | Strip toolUseResult envelope field (Edit diffs, never sent to API) | 5-50% |
| 12 | image-strip | aggressive | Strip old base64 image blocks, keep most recent 20% | 1-40% |
| 13 | http-spam | aggressive | Collapse consecutive HTTP request runs | 0-2% |
| 14 | error-retry-collapse | aggressive | Collapse repeated error-retry sequences |
| Prescription | Strategies | Risk | Typical Savings |
|---|---|---|---|
gentle | 5 | Minimal | 85-95% (with compact boundary) |
standard | 11 | Low | 25-45% |
aggressive | 18 | Moderate | 35-60% |
Dry-run is the default. Nothing is modified until you pass --execute. Backups are always created.
The guard daemon monitors your session and prunes automatically:
# Auto-starts via SessionStart hook after cozempic init
# Or run manually:
cozempic guard --daemon
4-tier proactive pruning (every 30s):
| Tier | Threshold | Action | Reload? |
|---|---|---|---|
| Soft | 25% | gentle file cleanup | No |
| Hard | 55% | standard prune | Yes (interactive: at a breakpoint; deferred if agents active) |
| Hard2 | 80% | aggressive prune | Yes (gated by the safe-point check) |
| User | 90% | manual aggressive | Yes |
Interactive sessions — instead of a surprise reload mid-work, the guard surfaces a nudge and reloads only once you pause between turns, after warning you. Near the wall (≈88%) it reloads even mid-turn — a higher-fidelity prune beats hitting autocompact. Detection is automatic (COZEMPIC_INTERACTIVE=auto); on/off force it. Headless/CI sessions reload immediately as before.
Safe-point reload — a reload terminates and resumes the Claude process, so the guard validates first: if a Workflow, a background subagent, an agent team, or an open tool call is in flight, the reload defers (read-only checkpoint) rather than destroying that work. Tune the near-wall force point with COZEMPIC_FORCE_RELOAD_PCT (default 0.88).
Reactive overflow recovery — kqueue/polling file watcher detects inbox-flood overflow within milliseconds, auto-prunes with escalating prescriptions, circuit breaker prevents loops.
tmux/screen — reload resumes in the same pane via send-keys. Plain terminals open a new window.
Token thresholds auto-detect — 200K and 1M models detected automatically. Override with COZEMPIC_CONTEXT_WINDOW=200000 for Pro plan.
Cozempic extracts your corrections and persists them across compactions:
# View extracted rules
cozempic digest show
# Manually extract from current session
cozempic digest update
# Sync rules to Claude Code's memory system
cozempic digest inject
How it works:
~/.claude/projects/<cwd>/memory/)When Claude's auto-compaction fires, Agent Teams lose coordination state. Cozempic prevents this with five layers:
cozempic doctor # Diagnose issues
cozempic doctor --fix # Auto-fix where possible
| Check | What It Detects | Auto-Fix |
|---|---|---|
trust-dialog-hang | Resume hangs on Windows | Reset flag |
claude-json-corruption | Truncated/corrupted JSON | Restore from backup |
corrupted-tool-use | tool_use.name >200 chars | Parse and repair |
orphaned-tool-results | tool_result missing matching tool_use — causes 400 errors | Strip orphans |
zombie-teams | Stale team directories with dead agents | Remove stale dirs |
oversized-sessions | Session files >50MB | — |
stale-backups | Old .jsonl.bak files wasting disk | Delete old backups |
disk-usage | Session storage exceeding healthy thresholds | — |
cozempic init Wire hooks + slash command into project
cozempic list List sessions with sizes and token estimates
cozempic current [-d] Show/diagnose current session
cozempic diagnose <session> Analyze bloat sources
cozempic treat <session> [-rx PRESET] Run prescription (dry-run default)
cozempic treat <session> --execute Apply changes with backup
cozempic strategy <name> <session> Run single strategy
cozempic reload [-rx PRESET] Treat + auto-resume in new terminal
cozempic checkpoint [--show] Save team state to disk
cozempic guard [--daemon] Start guard (auto-starts via hook)
cozempic doctor [--fix] Check for known issues
cozempic digest [show|update|clear|flush|recover|inject]
cozempic dashboard Build a static HTML report of your prune savings
cozempic self-update Upgrade to latest version from PyPI
cozempic formulary Show all strategies & prescriptions
cozempic uninstall [--project|--all|--purge] Reverse init: unwire hooks + slash command
After cozempic init, these hooks are wired automatically:
| Hook | When | What |
|---|---|---|
SessionStart | Session opens | Guard daemon + digest inject |
PostToolUse[Task] | Agent spawn | Team checkpoint |
PostToolUse[TaskCreate|TaskUpdate] | Todo changes | Team checkpoint |
PreCompact | Before compaction | Checkpoint + digest flush |
Stop | Session end | Checkpoint + digest flush |
--execute required to modify fileswrite → fsync → os.replace() — no partial writes.jsonl.bak before any modification Prescription: aggressive
Before: 158.2K tokens (29.56MB, 6602 messages)
After: 121.5K tokens (23.09MB, 5073 messages)
Freed: 36.7K tokens (23.2%) — 6.47MB, 1529 removed, 4038 modified
Context: [============--------] 61%
Strategy Results:
compact-summary-collapse 8.17MB saved (85.2%) (4201 removed)
progress-collapse 1.63MB saved (5.5%) (1525 removed)
metadata-strip 693.9KB saved (2.3%) (2735 modified)
tool-use-result-strip 1.44MB saved (4.9%) (891 modified)
thinking-blocks 1.11MB saved (3.8%) (1127 modified)
tool-output-trim 1.72MB saved (5.8%) (167 modified)
...
NaN, infinity, and non-representable huge integers are now rejected with a clear error at every CLI flag, COZEMPIC_* env var, and config field (a NaN threshold would otherwise silently disable the gate it controls). Thanks to @ynaamane (#116), and folded in the matching fix for the interactive-guard reload-grace knobdocs/qa-fleet.md + a corpus-driven regression test so this whole class can't regresscozempic reload. Brings cozempic's higher-fidelity prune+resume to interactive sessions without surprise reloads. Tunable via COZEMPIC_NUDGE_PCTS; silence with COZEMPIC_NUDGE_OFF=1COZEMPIC_FORCE_RELOAD_PCT, default 88%) it reloads even mid-turn. Headless/CI behaviour unchangedCOZEMPIC_INTERACTIVE=auto|on|offCOZEMPIC_IDLE_BACKOFF_CYCLES) and skips redundant no-op SOFT checkpointscozempic reload --session <id|path> escape hatch when auto-detect fails in multi-agent sessions. Previously reload had no way to recover from ambiguous session detection, leaving users stuck. Matches guard --session.--version still prints the old number (the running Python process can't hot-swap its own code)COZEMPIC_NO_TELEMETRY=1 disables anonymous usage countersCOZEMPIC_NO_AUTO_UPDATE, COZEMPIC_NO_TELEMETRY, COZEMPIC_CONTEXT_WINDOW env vars/exit + claude --resume in the same pane[1m] suffix)pip install --upgrade cozempic on every session. MCP/plugin use uv run --upgrade. npm install.js always upgrades.cozempic self-update: force-upgrade from PyPI regardless of install method (pip, uv, editable, clone)tool-result-age strategy — age-based tool result compaction. Recent results stay verbatim, mid-age get JSON minified and diff context collapsed, old replaced with compact stubs. Claude can re-read any file. 10-40% additional savings targeting the 45% of session size that tool results occupy.is_protected() guard on all strategies, isSidechain preserved in envelope-strip, output_tokens in token formula, parentUuid re-linking, sibling tool_use protectioncompact-summary-collapse (85-95%), attribution-snapshot-strip, microcompact-aware tool-output-trimcozempic diagnose shows cache hit rate| Variable | Default | Effect |
|---|---|---|
COZEMPIC_CONTEXT_WINDOW | auto-detect | Override context window size (e.g. 200000 for Pro plan) |
COZEMPIC_NO_AUTO_UPDATE | off | Disable all automatic upgrades (honored by the Python updater, SessionStart hook, and npm installer). Not generally recommended — Claude Code ships frequent changes and cozempic updates keep strategies compatible with the latest session format. See Auto-update & how to control it. |
COZEMPIC_PIN | unset | Hold a reviewed version (e.g. 1.8.30): disables auto-update on both paths and warns on drift instead of auto-installing. For users who want the protection on a version they've vetted. |
COZEMPIC_NO_TELEMETRY | off | Skip anonymous usage counters. Cozempic pings a simple counter on each prune — no personal data, session content, or identifiable information is sent. Helps us prioritize development. |
Contributions welcome. To add a strategy:
src/cozempic/strategies/@strategy(name, description, tier, expected_savings)StrategyResult with a list of PruneActionssrc/cozempic/registry.pyMIT — see LICENSE.
Built by Ruya AI.
.claude/
.claude-plugin/
marketplace.json
commands/
cozempic.md
hooks/
persist-session-id.sh
settings.json
.gitignore
.mcp.json
claude-opus-1m.sh
CONTRIBUTORS.md
docs/
behavioral-digest-design.md
qa-fleet.md
LICENSE
npm/
bin/
cozempic.js
install.js
package.json
packaging/
aur/
.SRCINFO
PKGBUILD
ci/
publish.yml
homebrew/
cozempic.rb
macports/
Portfile
nix/
default.nix
flake.nix
README.md
plugin/
.claude-plugin/
plugin.json
.mcp.json
hooks/
hooks.json
README.md
servers/
cozempic_mcp.py
skills/
cozempic-doctor/
SKILL.md
diagnose/
SKILL.md
guard/
SKILL.md
reload/
SKILL.md
treat/
SKILL.md
pyproject.toml
README.md
scripts/
backup-analytics.sh
outreach-digest.sh
stats-summary.sh
src/
cozempic/
__init__.py
__main__.py
_constants.py
_validation.py
cli.py
completion.py
config.py
dashboard/
__init__.py
aggregate.py
lifetime.py
render.py
data/
cozempic_slash_command.md
hooks.json
diagnosis.py
digest.py
doctor.py
executor.py
guard.py
helpers.py
init.py
metrics.py
overflow.py
recap.py
receipts.py
registry.py
reload_lock.py
safety.py
session.py
spawn_lock.py
strategies/
__init__.py
_config.py
aggressive.py
gentle.py
standard.py
team.py
tokens.py
types.py
updater.py
watchdog.py
watcher.py
tests/
__init__.py
conftest.py
fixtures/
guard_logs/
f641174c_reload_loop.log
harness/
finished_team.jsonl
idle_team.jsonl
live_team.jsonl
README.md
sessions/
corrupted_tool_use.jsonl
orphaned_tool_results.jsonl
post_compact_recovery.jsonl
solo_bloated.jsonl
team_two_subagents.jsonl
test_active_session_detection.py
test_atomic_writes_wave1.py
test_auto_init_global_skip.py
test_c3_fallback.py
test_cli_receipts.py
test_cli_validation.py
test_codex_inherit.py
test_completions.py
test_dashboard_aggregate.py
test_dashboard_coercion_corpus.py
test_dashboard_lifetime.py
test_dashboard_render.py
test_digest.py
test_doctor_extended.py
test_doctor.py
test_executor.py
test_find_current_session.py
test_global_init.py
test_golden_corpus.py
test_guard_cleanup.py
test_guard_futile_reload.py
test_guard_hard_loop_backoff.py
test_guard_hardening.py
test_guard_leak.py
test_guard_live_readonly.py
test_guard_longitudinal_loop.py
test_guard_pid_recycling.py
test_guard_polish_pr93.py
test_guard_pruneconflict_loop.py
test_guard_race_2026_05_18.py
test_guard_receipt.py
test_guard_reload_loop_fix.py
test_guard_reload_watcher_poll.py
test_guard_robustness.py
test_guard_safe_point.py
test_guard_session_lazy_create_121.py
test_guard_team_agent_spawn.py
test_guard_transient_race.py
test_guard_unprunable_live_loop.py
test_guard_watchdog.py
test_hook_idempotency_shell.py
test_hook_path_baking.py
test_hook_posix_dash.py
test_hooks_sync.py
test_host_file_lock.py
test_input_coercion_corpus.py
test_interactive_guard.py
test_interactive_loop.py
test_metrics.py
test_mission_critical_r4.py
test_mission_critical_r5.py
test_mission_critical_r6.py
test_mission_critical_r7.py
test_model_detection.py
test_nudge.py
test_overflow.py
test_permission_mode_protected.py
test_phantom_clear_terminate.py
test_post_compact.py
test_pr138_review_fixes.py
test_protect_pattern.py
test_prune_safety_r2.py
test_prune_safety.py
test_recap.py
test_receipts.py
test_reload_gate_contract.py
test_reload_gate_regex_cap.py
test_reload_ledger_env_bounds.py
test_reload_lock_wave2.py
test_resume_torn_line.py
test_session_atomic.py
test_session_id_parity.py
test_session.py
test_settings_lock.py
test_spawn_lock.py
test_strategies_config.py
test_strategies.py
test_task_list_keying.py
test_team_recovery_receipt.py
test_team_schema.py
test_tmp_orphan.py
test_token_delta_report.py
test_tokens.py
test_tool_result_age.py
test_track1.py
test_track2.py
test_track4.py
test_transient_daemon_reproducer.py
test_uninstall.py
test_updater.py
test_validation.py
test_watcher.py
test_win_guard_compat.py
test_ynaamane_review.py
uv.lock© 2026 Flowy · Free and open source
Built for Claude Code · Not affiliated with Anthropic
| 0-5% |
| 15 | background-poll-collapse | aggressive | Collapse repeated polling messages | 0-1% |
| 16 | document-dedup | aggressive | Deduplicate large document blocks (CLAUDE.md injection) | 0-44% |
| 17 | mega-block-trim | aggressive | Trim any content block over 32KB | safety net |
| 18 | envelope-strip | aggressive | Strip constant envelope fields (cwd, version, slug) | 2-4% |