🎯

strategic-compact

🎯Skill
mhylle/claude-skills-collection8 Installs17Last Updated Jun 27, 2026

Installation

$npx skills add mhylle/claude-skills-collection --skill strategic-compact

Run it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).

Uses skills.sh Β· Node.js 22.20+

After installing

Ask for related work and the agent uses it on its own, or call it yourself.

Run it (Claude Code)/strategic-compact
Install by hand

Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.

Open the skill folder β†’
  • This project .claude/skills/strategic-compact/
  • All projects ~/.claude/skills/strategic-compact/

These paths are for Claude Code. For other tools, the command above puts it in the right place.

Suggest context compaction at optimal logical boundaries β€” between phases, after a research burst, after a debugging session ends β€” rather than waiting for the automatic compaction threshold to hit mid-task. Use when the user asks whether to compact, mentions context is getting long, wants to checkpoint before a big task, or when you notice the session is approaching a natural transition where compacting would preserve the next phase's context. Complements (doesn't replace) Claude Code's built-in auto-compaction. Triggers on "/strategic-compact", "should I compact", "when should I clear context", "getting long", or proactively at phase boundaries and session transitions.

Strategic Compact

Contents

Reference files (open one when a step points to it):

  • references/boundary-rules.md: Boundary rules β€” when to suggest, when not to
  • references/hook-setup.md: Hook setup and configuration

Suggest context compaction at logical boundaries β€” not arbitrary token thresholds. Auto-compaction is a safety net; strategic compaction is a workflow optimization that makes compaction feel like a natural pause instead of an interruption.


Why strategic > automatic

Auto-compaction fires on simple thresholds (token count, time). That creates real problems:

  • Mid-task disruption β€” auto-compact might fire while you're debugging, losing the mental model built up over many interactions.
  • Context fragmentation β€” arbitrary cutoffs create artificial boundaries in session history.
  • Lost continuity β€” "why" decisions get compacted away at random points rather than preserved at meaningful boundaries.
  • Incomplete state β€” mid-implementation compaction can lose partially completed work.

Strategic compaction instead:

  • Monitors for logical boundaries (task completion, phase transitions, successful commits).
  • Considers semantic state (actively debugging vs. between tasks).
  • Provides suggestions β€” never forces compaction.
  • Integrates with context-saver to preserve critical state first.
  • Respects workflow rhythm rather than imposing arbitrary limits.

Goal: compaction that feels like a natural pause, not an interruption.


When to use

Passive monitoring β€” via PreToolUse hook that attaches to every tool call, tracks counters, and evaluates boundaries. Hook setup β†’ references/hook-setup.md.

Direct invocation:

  • /strategic-compact β€” check current session state and get a recommendation.
  • /strategic-compact status β€” view tool counts and threshold proximity.
  • /strategic-compact now β€” force a suggestion (auto-invokes context-saver first).

Trigger phrases: "should I compact", "when should I clear context", "getting long", "checkpoint", "context is getting big".


The core heuristic

Two questions:

  1. Has enough work happened that compaction is worthwhile? (weighted tool-call count vs. threshold)
  2. Is this moment a good place to compact? (logical boundary vs. mid-task)

Both must be yes before suggesting. The full rule set is in references/boundary-rules.md. Summary:

Suggest when…

Signal strengthTrigger
StrongTask completion (TaskUpdate β†’ completed), + β‰₯60% threshold, + >10min since last suggestion
StrongSuccessful git commit, + β‰₯70% threshold, + no pending tasks in this feature
MediumNew feature starting (TaskUpdate β†’ in_progress after completing previous), + β‰₯50% threshold
Warning (high priority)Estimated context usage >80% + β‰₯90% threshold β€” prevent forced auto-compaction mid-task

Don't suggest when…

  • Active debugging β€” recent errors, investigation-pattern tool sequence, or task name contains "debug/fix/investigate".
  • Active implementation β€” uncommitted changes, recent edits, unresolved test failures.
  • User recently deferred β€” respect the last "not now".
  • Critical operation in progress β€” rollback, migration, destructive commands.
  • Last suggestion was <10 min ago β€” avoid nagging.

Threshold

Default: 50 weighted tool calls between logical boundaries.

"Significant" means the weighted count β€” raw tool calls multiplied by the weight table below. A tool call with weight 1.0 contributes 1 significant call; a Read with weight 0.5 contributes 0.5. Weights:

  • Edit / Write / Bash / NotebookEdit / TaskUpdate β€” weight 1.0 (state-modifying or complex)
  • Read β€” 0.5 (inspection, lower cognitive load)
  • Glob / Grep β€” 0.3 (searches, low cost)
  • WebFetch / WebSearch β€” 0.5 (external lookups)

Scenario-tuned thresholds (standard dev 50, debugging 75, quick fixes 30, large refactor 40, docs 60). Full config + dynamic adjustment rules β†’ references/hook-setup.md.


Preserve before compact

When a suggestion is accepted, auto-invoke context-saver before compaction (via integrate_context_saver: true in hook config β€” default). This produces a handoff doc capturing:

  • What was being worked on
  • Files mid-edit with line numbers
  • Decisions made
  • Next steps

The compacted session can be resumed from that file. See context-saver/SKILL.md for the doc format.


Suggestion format

Keep suggestions informative but non-intrusive:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Context Compaction Suggested
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

 Session Metrics:
   Tool calls:     72 significant (threshold: 50)
   Session time:   45 minutes
   Last boundary:  Task completed 3 min ago

 Boundary Detected:
   Task "Add user authentication" marked complete
   Git commit: "feat: implement JWT auth flow"
   No pending changes or active debugging

 Recommendation: GOOD TIME TO COMPACT

 Options:
   [1] Compact now (will invoke context-saver first)
   [2] Defer for 15 minutes
   [3] Defer until next boundary
   [4] Dismiss (don't suggest again this session)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Always show why now β€” the specific boundary and conditions that triggered the suggestion. Users trust the heuristic faster when they can see its reasoning.

Minimal mode (for experienced users):

[Compact? 72/50 calls | Task done | Clean state] Y/n/defer

Integration with other skills

  • context-saver β€” auto-invoked before compact. Captures in-flight state as a handoff doc.
  • implement-phase β€” emits phase_complete boundary events.
  • create-plan β€” plan creation emits a boundary.
  • code-review β€” review completion emits a boundary.

Full integration specs β†’ references/hook-setup.md.


Core principles (keep these in mind)

  1. Suggest, don't force β€” respect the user's workflow.
  2. Boundary-aware β€” align with natural pause points, not token counts.
  3. Context-preserving β€” always integrate with context-saver before compact.
  4. Configurable β€” adapt thresholds per project and scenario.
  5. Non-intrusive β€” clear but minimal suggestions; include the "why."

References (loaded on demand)

  • references/hook-setup.md β€” PreToolUse hook config, state tracking, tool weights, dynamic thresholds, per-project configuration, integration specs, troubleshooting
  • references/boundary-rules.md β€” Full suggest-when / suppress-when rule specifications with YAML patterns, plus accept/defer heuristics for users

More from this repository10