Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

strategic-compact战略契约

Agent Skill

strategic-compact 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

188

周安装

8

GitHub Stars

13

下载量

66
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:strategic-compact(战略契约)
来源仓库:https://github.com/mhylle/claude-skills-collection
仓库路径:skills/strategic-compact
安装命令:
npx skills add https://github.com/mhylle/claude-skills-collection --skill strategic-compact
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/mhylle/claude-skills-collection --skill strategic-compact

简介

strategic-compact 智能压缩会话上下文,优化长时间工作流程。

  • 在自然暂停点建议压缩时机,避免打断连续性思考。
  • 与上下文保护程序集成,保留关键逻辑边界。strategic-compact 属于研究检索类 Skill,可作为该场景下的辅助能力补充。
  • 可配置以适应不同项目偏好,非强制干预用户操作。
  • 需用户授权方可激活建议机制,尊重自主控制权。

SKILL.md

Strategic Compact Skill

A framework for intelligently suggesting context compaction at optimal moments during long coding sessions, preserving work continuity while managing context window limitations.

Design Philosophy

Why Strategic Compaction > Auto-Compaction

Auto-compaction operates on simple thresholds (token count, time elapsed) without understanding the semantic state of your work. This leads to several problems:

  1. Mid-Task Disruption: Auto-compact might trigger while you're debugging a complex issue, losing the mental model you've built up over many interactions.
  2. Context Fragmentation: Arbitrary cutoffs create artificial boundaries in your work history, making it harder to understand the full picture when resuming.
  3. Lost Continuity: Important context about "why" decisions were made gets compacted away at random points rather than preserved at meaningful boundaries.
  4. Incomplete State: Compacting mid-implementation can lose track of partially completed work, leading to duplicated effort or missed steps.

Strategic compaction instead:

  • Monitors for logical boundaries in your work (task completion, phase transitions)
  • Considers the semantic state of the session (actively debugging vs. between tasks)
  • Provides suggestions rather than forcing compaction
  • Integrates with context-saver to preserve critical state before compaction
  • Respects your workflow rhythm rather than imposing arbitrary limits

The goal is compaction that feels like a natural pause point, not an interruption.


When to Use

This skill operates primarily through the PreToolUse hook, passively monitoring session state and providing suggestions at appropriate moments.

Automatic Monitoring (PreToolUse Hook)

The skill attaches to every tool call, maintaining counters and evaluating whether the current moment represents a good compaction opportunity.

Manual Invocation

You can also invoke the skill directly:

  • /strategic-compact - Check current session state and get recommendation
  • /strategic-compact status - View tool counts and threshold proximity
  • /strategic-compact now - Force a compaction suggestion (with context-saver integration)

Tool Call Tracking Mechanism

How to Count Tool Calls

The skill maintains session state by tracking tool invocations. This is implemented through the PreToolUse hook which fires before each tool execution.

# Session State Structure
session_state:
  tool_counts:
    total: 0              # All tool calls
    significant: 0        # Tools that modify state or are complex
    read_operations: 0    # Read, Glob, Grep operations
    write_operations: 0   # Write, Edit, Bash operations
    navigation: 0         # Directory changes, file searches

  boundaries:
    tasks_completed: 0    # TaskUpdate with status=completed
    phases_completed: 0   # Major implementation phases
    commits_made: 0       # Successful git commits

  flags:
    active_debugging: false    # Currently in debug cycle
    active_implementation: false  # Mid-feature implementation
    last_error_count: 0       # Errors in recent tool calls

  timestamps:
    session_start: null
    last_boundary: null       # Last logical boundary crossed
    last_suggestion: null     # Avoid repeated suggestions

Which Tools to Count

Significant Tools (count toward threshold):

  • Edit - File modifications
  • Write - File creation/overwrite
  • Bash - Command execution (especially git, npm, build commands)
  • NotebookEdit - Jupyter modifications
  • TaskUpdate - Task state changes

Tracked but Weighted Lower:

  • Read - File reading (0.5 weight)
  • Glob - File pattern matching (0.3 weight)
  • Grep - Content searching (0.3 weight)
  • WebFetch / WebSearch - External lookups (0.5 weight)

Boundary Markers (reset considerations):

  • TaskUpdate with status: completed - Task boundary
  • Bash with git commit - Commit boundary
  • Skill invocations for phase completion

Session State Tracking

State is maintained in-memory during the session. The PreToolUse hook updates counters before each tool execution:

# Pseudocode for state tracking
def on_pre_tool_use(tool_name, parameters):
    state = get_session_state()

    # Update counters
    state.tool_counts.total += 1
    state.tool_counts[categorize(tool_name)] += get_weight(tool_name)

    # Check for boundary markers
    if is_boundary_marker(tool_name, parameters):
        state.boundaries[get_boundary_type(tool_name, parameters)] += 1
        state.timestamps.last_boundary = now()

    # Update activity flags
    update_activity_flags(state, tool_name, parameters)

    # Evaluate suggestion opportunity
    if should_suggest_compact(state):
        return generate_suggestion(state)

    return None  # Allow tool to proceed

Threshold Configuration

Default Threshold

The default threshold is 50 significant tool calls between logical boundaries.

This number is based on:

  • Typical context window capacity for detailed work
  • Average session complexity before context becomes "stale"
  • Balance between interruption frequency and context quality

How to Configure Custom Thresholds

Thresholds can be configured in your project's .claude/settings.json:

{
  "skills": {
    "strategic-compact": {
      "thresholds": {
        "default": 50,
        "aggressive": 30,
        "relaxed": 75,
        "never": -1
      },
      "active_threshold": "default",
      "boundary_weight": {
        "task_completion": 0.5,
        "commit": 0.3,
        "phase_completion": 0.7
      }
    }
  }
}

Different Thresholds for Different Scenarios

ScenarioThresholdRationale
Standard Development50Balanced for typical feature work
Complex Debugging75Need more context for issue tracking
Quick Fixes30Less context needed, faster cycles
Large Refactoring40Many files, context can get stale
Documentation60Mostly reading, less state to track
Plan ExecutionPer-phaseAlign with plan phase boundaries

Dynamic Threshold Adjustment:

The skill can adjust thresholds based on detected activity:

dynamic_rules:
  - condition: "active_debugging == true"
    adjustment: "+25"
    reason: "Preserve debugging context"

  - condition: "error_rate > 0.3"
    adjustment: "+15"
    reason: "Troubleshooting in progress"

  - condition: "time_since_boundary > 30min"
    adjustment: "-10"
    reason: "Context likely getting stale"

Logical Boundaries

The skill identifies optimal compaction moments by recognizing logical boundaries in your work.

When to Suggest Compact

After Completing a Phase/Task

Strong Signal - Task completion is the clearest boundary.

trigger:
  event: TaskUpdate
  parameters:
    status: completed
  conditions:
    - tool_count.significant >= threshold * 0.6
    - time_since_last_suggestion > 10min

Suggestion appears after the task is marked complete, offering a natural pause point.

After Major Implementation Milestone

Strong Signal - Commits and successful builds indicate stable points.

trigger:
  event: Bash
  command_pattern: "git commit"
  result: success
  conditions:
    - tool_count.significant >= threshold * 0.7
    - not pending_tasks_in_current_feature

Before Starting New Feature

Medium Signal - Beginning new work is a good reset point.

trigger:
  event: TaskUpdate
  parameters:
    status: in_progress
  conditions:
    - previous_task_completed
    - feature_boundary_detected
    - tool_count.significant >= threshold * 0.5

When Context is About to Overflow

Warning Signal - Proactive suggestion before forced compaction.

trigger:
  event: any
  conditions:
    - estimated_context_usage > 0.8
    - tool_count.significant >= threshold * 0.9
  priority: high

When NOT to Suggest Compact

During Active Debugging

suppress_when:
  - recent_error_count > 0
  - last_tool_was: [Read, Grep, Glob]  # Investigating
  - pattern_detected: "debug_cycle"
  - task_subject_contains: ["debug", "fix", "investigate"]

Rationale: Debugging requires building up mental models and context. Compacting mid-debug loses the trail of investigation.

During Active Implementation

suppress_when:
  - uncommitted_changes: true
  - last_tools_sequence: [Edit, Edit, Edit]  # Active coding
  - time_since_last_edit < 5min
  - test_failures_unresolved: true

Rationale: Mid-implementation compaction risks losing track of partial work and the reasoning behind changes.

Other Suppression Conditions

suppress_when:
  - last_suggestion < 10min_ago  # Avoid nagging
  - user_deferred_recently: true  # Respect user choice
  - critical_operation_in_progress: true
  - rollback_or_revert_active: true

Best Practices

When to Accept Compact Suggestion

Accept when:

  • You've just completed a logical unit of work
  • The suggestion aligns with a natural pause in your workflow
  • You're about to context-switch to a different feature/area
  • You've made a commit and tests are passing
  • You notice responses are getting slower or less accurate

When to Defer

Defer when:

  • You're in the middle of tracking down a bug
  • You have uncommitted changes you're still working on
  • You're about to run a critical command that needs context
  • You're iterating on a specific piece of code
  • The current task is almost complete (< 5 minutes remaining)

How to Preserve Context Before Compact

Before accepting a compaction suggestion, ensure critical context is preserved:

  1. Check for uncommitted work: git status git diff --stat
  2. Review active tasks: TaskList to see pending work
  3. Document decision points:

- Any architectural decisions made - Reasoning behind non-obvious choices - Known issues or TODOs discovered

  1. Capture current position:

- What file/function you're working in - What the next step should be - Any blockers or dependencies

Using context-saver Skill Before Compacting

The strategic-compact skill integrates with the context-saver skill to preserve session state:

compact_workflow:
  1. Detect compaction opportunity
  2. Check if context-saver is available
  3. If available:
     - Invoke context-saver with current session state
     - Wait for context file creation
     - Include context file path in compact summary
  4. Present compaction suggestion with preserved context reference
  5. If accepted:
     - Perform compaction
     - New session starts with context file reference

Integration Example:

[Strategic Compact Suggestion]

Session Status:
- Tool calls: 67 (threshold: 50)
- Last boundary: Task "Implement auth flow" completed 5 min ago
- Current state: Between tasks, no active debugging

Recommendation: Good time to compact

Before compacting, I'll save your context:
> Invoking context-saver skill...
> Context saved to: .claude/contexts/session-2024-01-15-auth-impl.md

You can reference this context in your next session with:
> "Continue from .claude/contexts/session-2024-01-15-auth-impl.md"

Accept compaction? [Y/n]

PreToolUse Hook Configuration

Example hooks.json Configuration

Create or update .claude/hooks.json in your project:

{
  "hooks": {
    "PreToolUse": [
      {
        "name": "strategic-compact-monitor",
        "skill": "strategic-compact",
        "enabled": true,
        "priority": 10,
        "config": {
          "threshold": 50,
          "mode": "suggest",
          "integrate_context_saver": true,
          "suppress_during": [
            "debugging",
            "active_implementation",
            "rollback"
          ],
          "boundary_events": [
            "task_completion",
            "git_commit",
            "phase_transition",
            "feature_boundary"
          ]
        }
      }
    ]
  }
}

Configuration Options

OptionTypeDefaultDescription
thresholdnumber50Tool calls before suggesting
modestring"suggest""suggest", "warn", or "silent"
integrate_context_saverbooleantrueAuto-invoke context-saver
suppress_duringarray[...]Activity types to suppress during
boundary_eventsarray[...]Events that count as boundaries
min_intervalnumber600Min seconds between suggestions
dynamic_thresholdbooleantrueAdjust threshold based on activity

How to Enable/Disable

Enable for a project:

# Add to project settings
echo '{"skills": {"strategic-compact": {"enabled": true}}}' > .claude/settings.json

Disable temporarily:

/strategic-compact disable

Disable for session:

{
  "hooks": {
    "PreToolUse": [
      {
        "name": "strategic-compact-monitor",
        "enabled": false
      }
    ]
  }
}

Integration with Claude Code

The skill integrates with Claude Code's hook system:

Claude Code Session
      │
      ▼
  PreToolUse Hook
      │
      ▼
  strategic-compact-monitor
      │
      ├── Update counters
      ├── Check boundaries
      ├── Evaluate conditions
      │
      ▼
  [Suggestion or Pass-through]
      │
      ▼
  Tool Execution
      │
      ▼
  PostToolUse (optional logging)

Suggestion Message Format

Clear, Non-Intrusive Suggestions

Suggestions should be informative but not disruptive:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 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)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Include Current Tool Count

Always show the current state so users understand why the suggestion appeared:

Tool Activity Summary:
  - Edits:    23 files modified
  - Reads:    45 files examined
  - Commands: 18 bash operations
  - Searches: 12 grep/glob operations

  Weighted Total: 72 (threshold: 50)

Include Reason for Suggestion

Be explicit about why this moment was chosen:

Why now?
  ✓ Task "Implement auth flow" completed
  ✓ Successful commit made
  ✓ All tests passing
  ✓ No uncommitted changes
  ✓ No active debugging session

This is a natural pause point in your workflow.

Minimal Mode (for experienced users)

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

Advanced Configuration

Per-Project Thresholds

Different projects may need different thresholds:

{
  "projects": {
    "large-monorepo": {
      "threshold": 40,
      "reason": "Many files, context gets stale quickly"
    },
    "focused-library": {
      "threshold": 75,
      "reason": "Smaller scope, more context helpful"
    },
    "debugging-session": {
      "threshold": 100,
      "reason": "Need extensive context for investigation"
    }
  }
}

Custom Boundary Definitions

Define project-specific boundaries:

{
  "custom_boundaries": {
    "migration_complete": {
      "trigger": "Bash",
      "pattern": "npm run migrate",
      "success_required": true,
      "weight": 0.8
    },
    "deploy_staging": {
      "trigger": "Bash",
      "pattern": "deploy.*staging",
      "weight": 1.0
    }
  }
}

Integration with Other Skills

The strategic-compact skill can coordinate with:

  • context-saver: Automatic context preservation before compact
  • implement-phase: Phase completion as boundary markers
  • create-plan: Plan phase transitions as boundaries
  • code-review: Review completion as boundary markers
skill_integration:
  context-saver:
    invoke_before_compact: true
    pass_session_state: true

  implement-phase:
    listen_for: phase_complete
    boundary_weight: 1.0

  create-plan:
    listen_for: plan_created
    suggest_compact_after: true

Troubleshooting

Suggestions Too Frequent

Increase threshold or add suppression conditions:

{
  "threshold": 75,
  "min_interval": 900
}

Suggestions Never Appear

Check that:

  1. Hook is enabled in .claude/hooks.json
  2. Threshold is set appropriately
  3. Skill is not permanently suppressed

Context Not Being Saved

Ensure context-saver skill is available:

ls -la skills/context-saver/SKILL.md

Boundaries Not Detected

Add custom boundary patterns for your workflow:

{
  "custom_boundaries": {
    "my_workflow_step": {
      "trigger": "Bash",
      "pattern": "your-command-pattern"
    }
  }
}

Summary

The strategic-compact skill transforms context compaction from an arbitrary interruption into a thoughtful workflow optimization. By monitoring session state, recognizing logical boundaries, and integrating with context preservation tools, it ensures that compaction happens at optimal moments without disrupting active work.

Key principles:

  1. Suggest, don't force - Respect user workflow
  2. Boundary-aware - Align with natural pause points
  3. Context-preserving - Integrate with context-saver
  4. Configurable - Adapt to different projects and preferences
  5. Non-intrusive - Clear but minimal suggestions

Use this skill to maintain high-quality context throughout long sessions while avoiding the disruption of poorly-timed compaction.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.79%
按下载量换算22

Claude

27.75%
按下载量换算18

Cursor

18.81%
按下载量换算12

Gemini CLI

10.69%
按下载量换算7

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills