Skip to content
Skillpedia
Tasks & projects280k Β· #415

strategic-compact

What it does

This tool suggests when to 'clean' the AI's conversation memory so it doesn't get overloaded. It helps the AI remember what's important in long or complex tasks.

When to use it

  • βœ“When the conversation with the AI is getting very long and slow.
  • βœ“When switching from one major task phase to another (e.g., research to planning).
  • βœ“After finishing an important part of the work and starting something new.

Skill link

https://github.com/affaan-m/ECC/blob/main/skills/strategic-compact/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/affaan-m/ECC/blob/main/skills/strategic-compact/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œAI, the conversation is getting confusing, can we clean the memory?”

5 new skills a week. 1 minute to read.

strategic-compact: full guide

Long agent sessions hit a limit. The agent can only hold so much text at once, and when it fills up, Claude Code compacts the conversation on its own schedule. That can happen in the middle of an edit, after which the agent may no longer remember which files it was changing or why.

This skill moves that decision to a better moment. A small script watches how large the session has grown and reminds you to run /compact when a phase has ended, for example when research is done and a plan exists. You stay in control: the hook says when, you decide if. It fits people who run long Claude Code sessions with several stages. Short chats do not need it, and it works only in Claude Code, because it relies on hooks.

Use cases

Research finished, starting to build

You spent an hour reading files and comparing options for a new login flow. The plan is now written down. Compacting at this point drops the bulky reading notes and keeps the plan, so the build phase starts with room to spare.

A bug is fixed, a new feature is next

You chased a stubborn error through logs and stack traces. Once it is fixed, that debugging noise has no value for the next feature. Compacting clears it so the agent does not mix old error details into unrelated work.

A failed approach needs a fresh start

Your first attempt at a data import did not work, and the conversation is full of reasoning about why. Compacting before the second try removes that dead end, so the agent is less likely to repeat or build on the failed idea.

Step by step

  1. 1Check how you installed it. If you used the ECC plugin, the hook is already registered and needs no setup. If you installed manually, add the PreToolUse entries for Edit and Write from the skill to ~/.claude/settings.json.
  2. 2Work as usual. The hook runs before each Edit or Write and checks the session size. By default it suggests compacting near 160k tokens on a 200k window, or after 50 tool calls.
  3. 3When a reminder appears, look at where you are. Only compact if a phase just ended, such as research done or a feature finished.
  4. 4Write the plan and key decisions to a file first, because compaction loses most of the conversation.
  5. 5Run /compact with a short note, for example: /compact Focus on implementing auth middleware next. Then continue in the new phase.

Example

What to ask

β€œThe research on the payment provider is done and I have written the plan to PLAN.md. The hook just suggested compacting. Should I compact now, and what should I say?”

What you get

Yes, this is a good point: research is bulky and the plan is saved in a file. Run: /compact Next phase is implementing the payment webhook, follow PLAN.md. The plan file, CLAUDE.md and your git state stay intact. The raw research notes will be gone.

Tips

  • βœ“Never compact in the middle of an implementation. Variable names, file paths and half-finished state are lost, and rebuilding them costs more than the space you gain.
  • βœ“Do not count on the task list surviving. Newer Claude Code versions removed the todo tools by default, so save the plan in a file instead.
  • βœ“Tune the reminders with environment variables. COMPACT_CONTEXT_THRESHOLD sets the token level (0 turns the size signal off), and ECC_CONTEXT_WINDOW_TOKENS sets the real window size if your model is large but not detected.

Alternatives

  • context-engineering

    Pick this if your problem is the starting setup and rules the agent sees, not when to compact a session that is already long.

  • knowledge-capture

    Pick this if you want decisions and key facts saved as notes in a vault, so they last well beyond any single session.

  • do

    Pick this if you already have a written step-by-step plan and want the agent to carry it out, one phase at a time.

Questions and answers

Does this skill compact my conversation for me?

No. It only reminds you. The hook suggests running /compact at a useful moment, and you decide whether to do it. Nothing is cleared until you run the command yourself.

Will it work outside Claude Code?

The skill depends on a Claude Code hook that runs before Edit and Write. The material does not describe support for other tools, so assume it is meant for Claude Code only.

Why does it measure tokens and not only tool calls?

A few large file reads can fill the window in very few calls, while many tiny calls can leave it almost empty. Context size shows real pressure, so it is the main signal.

How it works

The tool checks how much the AI has 'remembered' of the conversation. If it's near the limit, it suggests you use a command to clean the memory, ensuring the most important information is kept.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Strategic Compact Skill

Suggests manual /compact at strategic points in your workflow rather than relying on arbitrary auto-compaction.

When to Activate

  • Running long sessions that approach context limits (200K+ tokens)
  • Working on multi-phase tasks (research β†’ plan β†’ implement β†’ test)
  • Switching between unrelated tasks within the same session
  • After completing a major milestone and starting new work
  • When responses slow down or become less coherent (context pressure)

Why Strategic Compaction?

Auto-compaction triggers at arbitrary points:

  • Often mid-task, losing important context
  • No awareness of logical task boundaries
  • Can interrupt complex multi-step operations

Strategic compaction at logical boundaries:

  • After exploration, before execution β€” Compact research context, keep implementation plan
  • After completing a milestone β€” Fresh start for next phase
  • Before major context shifts β€” Clear exploration context before different task

How It Works

The suggest-compact.js script runs on PreToolUse (Edit/Write) and combines two signals:

  1. Context size (primary) β€” Reads the latest usage record from the session transcript (transcript_path in the hook payload) and sums input_tokens + cache_read_input_tokens + cache_creation_input_tokens (the true context size of the turn). Suggests /compact at a window-scaled threshold β€” 160k tokens on a 200k window, 250k on a 1M window (detected from a [1m] model marker, or inferred when observed tokens already exceed 200k) β€” and re-reminds after every additional 60k tokens of context growth
  2. Tool-call count (secondary) β€” Counts tool invocations in session; suggests at a configurable threshold (default: 50 calls), then every 25 calls after

Tool count alone is a weak proxy for window pressure: a few large file reads or MCP responses can fill the window in very few calls, while many tiny calls can cross 50 with a near-empty window. The context-size signal fires when it actually matters.

Hook Setup

Installed as a plugin? No setup is needed. The plugin's hooks/hooks.json already registers suggest-compact.js (hook id pre:edit-write:suggest-compact, active in the standard and strict hook profiles). Do not copy the block below into ~/.claude/settings.json β€” ~/.claude/scripts/ does not exist on plugin installs, and duplicating a plugin hook causes double execution.

If installed manually (./install.sh), add to your ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit",
        "hooks": [{ "type": "command", "command": "node ~/.claude/scripts/hooks/suggest-compact.js" }]
      },
      {
        "matcher": "Write",
        "hooks": [{ "type": "command", "command": "node ~/.claude/scripts/hooks/suggest-compact.js" }]
      }
    ]
  }
}

Configuration

Environment variables:

  • COMPACT_THRESHOLD β€” Tool calls before first suggestion (default: 50)
  • COMPACT_CONTEXT_THRESHOLD β€” Context tokens before the context-size suggestion (default: 160000 on a 200k window, 250000 on a 1M window; 0 disables the context signal)
  • COMPACT_CONTEXT_INTERVAL β€” Additional context tokens before the suggestion repeats (default: 60000)
  • COMPACT_STATE_TTL_DAYS β€” Days before stale per-session state files in the temp dir are swept (default: 14)
  • ECC_CONTEXT_WINDOW_TOKENS β€” Explicit context-window size, in tokens, overriding auto-detection. Set this for large-window models whose reported id lacks a [1m] marker (e.g. 400k Opus 4.x, or a new 1M-window model family) so the threshold scales to the real window instead of defaulting to 200k and overstating context usage.
  • CLAUDE_CODE_AUTO_COMPACT_WINDOW β€” Claude Code's native window-size override, in tokens; honored as a fallback when ECC_CONTEXT_WINDOW_TOKENS is unset.

The context window is otherwise auto-detected from a [1m] model marker or inferred when observed tokens already exceed 200k. On a large-window model that carries neither signal, set one of the overrides above so the /compact suggestion fires at the right point.

Compaction Decision Guide

Use this table to decide when to compact:

Phase Transition Compact? Why
Research β†’ Planning Yes Research context is bulky; plan is the distilled output
Planning β†’ Implementation Yes Plan is written down (a file, or the task list if you have one); free up context for code

…

FAQ

What does 'cleaning memory' mean?

It's like giving the AI a summary, keeping only essential information and discarding the rest so it can continue to function well.

Why not let the AI clean its memory automatically?

The AI might clean its memory at bad times, losing important information mid-task. This tool suggests cleaning at logical points, like the end of a phase.

What happens to information when memory is cleaned?

Key instructions and important files are kept. Intermediate information or old conversations might be lost to make space for new content.

Details

Original description by the author

Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction. Use when a session is approaching a context limit and a task phase is a natural place to compact.

repo: affaan-m/ECC

Popularity

GitHub stars
280k
Ranking position
#415
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills