rune-kit/rune/context-engine
Claude Code and agent skill by rune-kit/rune
- community
Checking that the SKILL.md file is still in the repository.
Context window management. Auto-triggered when context is filling up. Triggers smart compaction and preserves critical information across compaction boundaries. Called by L1 orchestrators at context thresholds.
Install
npx vskill@latest install rune-kit/rune/context-engineSKILL.md
The same SKILL.md was published earlier as rune-kit/rune/context-engine.
context-engine
Purpose
Context window management for long sessions. Detects when context is approaching limits, triggers smart compaction preserving critical decisions and progress, and coordinates with session-bridge to save state before compaction. Prevents the common failure mode of losing important context mid-workflow.
Behavioral Contexts
Context-engine also manages behavioral mode injection via contexts/ directory. Three modes are available:
| Mode | File | When to Use | |
|---|---|---|---|
dev | contexts/dev.md | Active coding — bias toward action, code-first | |
research | contexts/research.md | Investigation — read widely, evidence-based | |
review | contexts/review.md | Code review — systematic, severity-labeled |
Mode activation: Orchestrators (cook, team, rescue) can set the active mode by writing to .rune/active-context.md. The session-start hook injects the active context file into the session. Mode switches mid-session are supported — the orchestrator updates the file and references the new behavioral rules.
Default: If no .rune/active-context.md exists, no behavioral mode is injected (standard Claude behavior).
Triggers
- Called by
cookandteamautomatically at context boundaries - Auto-trigger: when tool call count exceeds threshold or context utilization is high
- Auto-trigger: before compaction events
Calls (outbound)
Exception: L3→L3 coordination
session-bridge(L3): coordinate state save when context critical
Called By (inbound)
cook(L1): Phase boundaries and when tool count exceeds thresholdsteam(L1): before parallel workstream dispatch, after mergerescue(L1): between refactoring sessions for state persistencecontext-pack(L3): when packaging context for sub-agent handoffsession-bridge(L3): coordinates with context-engine for compaction timingadversary(L2): (oracle-mode) emitcontext.previewbefore bundle build to gate token cost
Execution
Step 1 — Count tool calls
Count total tool calls made so far in this session. This is the ONLY reliable metric — token usage is not exposed by Claude Code and any estimate will be dangerously inaccurate.
Do NOT attempt to estimate token percentages. Tool count is a directional proxy, not a precise measurement.
Step 2 — Classify health
Map tool call count to health level:
These thresholds are directional heuristics, not precise limits. Sessions with many large file reads may hit context limits earlier; sessions with mostly Grep/Glob may go longer.
Large-File Adjustment
Projects with large source files (Python modules often 500-1500 LOC, Java files similarly) consume significantly more context per Read call. If the session has read files averaging >500 lines, apply a 0.8x multiplier to all thresholds:
Detection: count Read tool calls that returned >500 lines. If ≥3 such calls → activate large-file thresholds for the remainder of the session.
Step 3 — If YELLOW
Emit advisory to the calling orchestrator:
"[X] tool calls. Load only essential files. Avoid reading full files when Grep will do."
Do NOT trigger compaction yet. Continue execution.
Step 4 — If ORANGE
Emit recommendation to the calling orchestrator:
"[X] tool calls. Recommend /compact at next phase boundary (after current module completes)."
Identify the next safe boundary (end of current loop iteration, end of current file being processed) and flag it.
Auto-activate Caveman Output Mode (see references/caveman-mode.md) — emit output.density.set with mode=caveman, scope=session, source=context-orange. Reduces output token cost ~75% with no information loss; persists until /compact returns context to GREEN. Manual override (/caveman or "stop caveman") always wins.
Step 5 — If RED
Immediately trigger state save via rune:session-bridge (Save Mode) before any compaction occurs. If caveman mode was not already active from ORANGE, emit output.density.set with mode=caveman, scope=session, source=context-red now.
Pass to session-bridge:
- Current task and phase description
- List of files touched this session
- Decisions made (architectural choices, conventions established)
- Remaining tasks not yet started
After session-bridge confirms save, emit:
"Context CRITICAL ([X] tool calls, likely near limit). State saved to .rune/. Run /compact now."
Block further tool calls until compaction is acknowledged.
Step 6 — Report
Emit the context health report to the calling skill.
Step 6b — Context Percentage Advisory
In addition to tool-call counting, monitor context window percentage when available:
| Remaining | Level | Action | |
|---|---|---|---|
| >35% | SAFE | Continue normally | |
| 25-35% | WARNING | Advise: "Context at ~[X]%. Consider /compact at next phase boundary" | |
| <25% | CRITICAL | Save state via session-bridge → recommend immediate /compact |
Debounce: emit advisory max once per 5 tool calls to avoid noise. Tool-call thresholds (Steps 1-2) remain the primary signal. Percentage advisory is supplementary — use when CLI status bar data is available.
Iterative Retrieval (Context-Loading Strategy)
When loading context for a task (Phase 1 of cook, or onboard), use a 4-phase retrieval loop instead of loading everything at once:
Why: The first search cycle reveals codebase-specific terms (custom class names, project conventions, internal APIs) that produce much better results in cycle 2. Loading 3 deeply relevant files beats loading 10 surface-level matches.
Key rule: Stop at 3 high-relevance files, not 10 mediocre ones. Quality > quantity for context loading.
Compaction Technique: Structured Summary with Continuation Point
When compaction is triggered (RED or approved ORANGE), generate a structured summary that replaces the full conversation history while preserving therapeutic continuity — the ability to resume exactly where work left off.
Summary Structure
The compaction summary MUST include these sections in order:
Why This Structure
Most compaction loses the continuation point — the agent knows WHAT was discussed but not WHERE to resume. The "Active Threads" and "Continuation Point" sections solve this by preserving:
- The exact file and function being edited
- What's done vs remaining in the current micro-task
- The specific next action (not a summary of the plan, but the next concrete step)
Rules
- Summary MUST be <500 tokens — if longer, you're summarizing too much detail
- "Active Threads" section is the most critical — get this wrong and the agent restarts from scratch
- Never include full file contents in the summary — only paths and line references
- Include user tone/urgency signals — these are lost in pure technical summaries
Incremental Stream Processing
Full detail moved to `references/stream-processing.md` (progressive disclosure). Read that file before executing this section.
Artifact Folding (Large Output Management)
Full detail moved to `references/artifact-folding.md` (progressive disclosure). Read that file before executing this section.
Context Health Levels
Note: These are tool call counts, NOT token percentages. Claude Code does not expose context utilization to skills. Tool count is a directional signal only.
Output Format
Strategic Compact Decision Table
When ORANGE or RED is reached, use this table to determine whether compaction is safe at the current boundary:
| Transition | Compact? | Reason | |
|---|---|---|---|
| Research → Planning | YES | Research findings summarize well; key decisions survive | |
| Planning → Implementation | YES | Plan is in files (.rune/plan-*.md); context can reload from artifacts | |
| Debug → Next feature | YES | Debug findings are in Debug Report; fix has the diagnosis | |
| Mid-implementation (Phase 4) | CONDITIONAL | Safe ONLY at task boundaries within Phase 4 (after a file is fully written + tested). Never mid-file-edit. See Mid-Loop Compaction below | |
| After failed approach → Pivot | YES | Failed approach should be discarded; fresh context helps | |
| Quality (Phase 5) → Verify | NO | Quality findings reference specific file:line in current context | |
| After commit (Phase 7) | YES | Work is persisted in git; safe boundary |
What survives compaction: Task description, file paths mentioned, key decisions, plan reference, current phase. What is lost: Full file contents read, intermediate reasoning, exact error messages, tool output details.
Mid-Loop Compaction (Phase 4 Emergency)
Compact during the run, not just at the session boundary.
When context hits RED during Phase 4 (implementation), compaction IS possible at clean split points:
- Find a clean boundary: completed task within the phase (file fully written + tests pass for that file)
- Flush state first: call
session-bridgeto save progress, then callneural-memoryto capture decisions - Split 70/30: preserve 70% of remaining context for continuation, summarize 30% of completed work
- Never break tool pairs: compaction MUST NOT split a
tool_usefrom itstool_result— always keep pairs together - Inject continuation marker: after compaction, include: "Resuming Phase 4. Tasks [1-3] complete. Currently on task 4. Plan file:
.rune/plan-X-phaseN.md"
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/context-engine/SKILL.md
Popularity
- Repository stars
- 77
- Repository forks
- 21
- Repository npm downloads, 30 days
- 548
- 7-day trend score
- 34
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 4 Jul 2026, 4 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rune-kit/rune/context-engine)