/forgewright:strategic-compactionfrom forgewright
Detects optimal moments for context compaction during conversation milestones, preventing context-window saturation while preserving PLAN_LOCKED handoff invariants. Runs memory hygiene via shell script.
Ships in forgewright. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Detects when to compact context to preserve progress and prevent overflow.
scripts/memory/memory-hygiene.sh for stale memory GC.bash scripts/memory/memory-hygiene.sh (takes no CLI flags; reports before/after observation counts and GC results).bash skills/strategic-compaction/evals/run-tests.sh (kernel/VERIFY.md Schema v2 observed exit code).You are the context strategist — you watch for moments where compaction preserves value and prevents context overflow. You speak up at logical breakpoints, not randomly.
Context compaction is most valuable when done at milestones — after research concludes, after a complex change, after a failed approach is abandoned. Compacting mid-thought wastes progress. Waiting until overflow loses context entirely. This skill finds the sweet spot.
| Trigger | Detection | Rationale |
|---|---|---|
| Milestone words | User says: "ok", "good", "clear", "got it", "let's do it", "go ahead", "done" | User signals understanding or completion |
| Failed approach | 3+ consecutive failed attempts detected | Clear the failed path, preserve learnings |
| Complex change | 5+ files modified since last compaction | Progress checkpoint before complexity grows |
| Architecture decision | User says "let's go with X" or confirms a design | Decision point — preserve context |
| Context saturation | >30 tool calls since last compaction | Proactive overflow prevention |
| Research milestone | User says "now I know" or "that answers it" | Research complete, ready to implement |
| Trigger | Detection | Rationale |
|---|---|---|
| Phase transition | Moving from planning to execution | Good checkpoint boundary |
| Skill chain complete | Finished one skill, about to start another | Natural handoff point |
| Long operation done | A long build/deploy/test completed | Results preserved before next step |
Do NOT trigger on:
const MILESTONE_WORDS = [
'ok', 'okay', 'good', 'great', 'clear', 'got it', 'understood',
'let\'s do it', 'let\'s go', 'go ahead', 'proceed', 'done',
'perfect', 'excellent', 'that works', 'sounds good', 'makes sense'
];
const RESEARCH_COMPLETE = [
'now i know', 'that answers', 'clear now', 'understood',
'i see', 'that makes sense', 'helped'
];
function isMilestone(userMessage) {
const lower = userMessage.toLowerCase().trim();
return MILESTONE_WORDS.some(w => lower === w || lower.endsWith(w))
|| RESEARCH_COMPLETE.some(w => lower.includes(w));
}
const COMPACTION_THRESHOLDS = {
toolCallsSinceCompaction: 30,
filesModifiedSinceCompaction: 5,
failedAttemptsSinceCompaction: 3,
turnsSinceCompaction: 15
};
function shouldSuggestCompaction(context) {
return (
context.toolCallsSinceCompaction > COMPACTION_THRESHOLDS.toolCallsSinceCompaction
|| context.filesModifiedSinceCompaction > COMPACTION_THRESHOLDS.filesModifiedSinceCompaction
|| context.failedAttemptsSinceCompaction > COMPACTION_THRESHOLDS.failedAttemptsSinceCompaction
|| context.turnsSinceCompaction > COMPACTION_THRESHOLDS.turnsSinceCompaction
);
}
function detectFailedApproach(messages) {
let consecutiveFailures = 0;
const FAILURE_INDICATORS = ['error', 'failed', 'didn\'t work', 'not working', 'invalid'];
for (const msg of messages.slice(-10)) {
const hasFailure = FAILURE_INDICATORS.some(f => msg.includes(f));
if (hasFailure) {
consecutiveFailures++;
} else {
break;
}
}
return consecutiveFailures >= 3;
}
When a trigger is detected, include this in the response:
---
⧖ Context checkpoint reached.
Progress preserved:
- [Brief summary of what was accomplished]
Suggestion: Type `/compact` to archive this checkpoint
and start fresh with the context summary preserved.
---
[Continue with current task]
[Session turn ends]
↓
Is this a milestone moment?
├── YES → Proceed to checkpoint check
└── NO → Is context saturated?
├── YES → Suggest compaction
└── NO → No suggestion needed
| Type | When to Use | What Gets Archived |
|---|---|---|
| Full | Architecture decisions, major milestones | Everything + summary |
| Partial | Skill handoffs, phase transitions | Recent context only |
| Minimal | Proactive prevention | Last N turns only |
| Pattern | Why It's Bad | Correct Approach |
|---|---|---|
| Compacting mid-thought | Loses current work state | Wait for natural pause |
| Compacting on every "ok" | Alert fatigue | Require threshold crossing |
| Compacting after overflow | Already too late | Proactive monitoring |
| Ignoring small milestones | Lose learning opportunities | Accumulate small wins |
This skill operates as a hook evaluator at message boundaries:
// hooks/strategic-compaction.ts
interface ContextState {
toolCallsSinceCompaction: number;
filesModifiedSinceCompaction: number;
failedAttemptsSinceCompaction: number;
turnsSinceCompaction: number;
lastCompactionTimestamp: number;
recentMessages: string[];
}
export function evaluateCompactionNeed(
context: ContextState,
userMessage: string
): CompactionSuggestion | null {
// Check milestone words
if (isMilestone(userMessage) && shouldSuggestCompaction(context)) {
return {
type: 'checkpoint',
reason: 'Milestone reached with accumulated context',
summary: summarizeRecentProgress(context)
};
}
// Check proactive thresholds
if (context.toolCallsSinceCompaction > 40) {
return {
type: 'preventive',
reason: 'High tool call count — prevent overflow',
summary: summarizeRecentProgress(context)
};
}
return null;
}
Customize thresholds via environment:
# Optional overrides (defaults shown)
FORGEWRIGHT_COMPACTION_TOOL_THRESHOLD=30
FORGEWRIGHT_COMPACTION_FILE_THRESHOLD=5
FORGEWRIGHT_COMPACTION_FAIL_THRESHOLD=3
FORGEWRIGHT_COMPACTION_TURN_THRESHOLD=15
| Metric | Target | Measurement |
|---|---|---|
| False positive rate | < 10% | Suggestions not followed / total suggestions |
| Detection accuracy | > 90% | Actual milestones detected / total milestones |
| Overflow prevention | > 80% | Preemptive compactions / total overflows |
When triggering:
/compact command with preserved summaryWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub buiphucminhtam/forgewright --plugin forgewright93 skills in this plugin
/3d-spatial-engineerUse for 3D spatial layouts, scene-graph coordinate transforms, greybox blockouts, culling volumes, static batching, and LOD optimization across 3D game engines./accessibility-engineerUse for web WCAG 2.1/2.2 AA accessibility audits, ARIA semantics, keyboard navigation, focus management, contrast verification, and automated axe-core remediation./ai-behavior-engineerUse for game AI and NPC decision systems: finite state machines, behavior trees, utility AI, GOAP, perception, navigation, tactical steering, and encounter tuning.Other plugins' skills for the same job