context-engine · borghei — Claude Code skill: agent context management
context-engine — a skill for Claude Code, Codex, Cursor, GitHub Copilot, and Gemini CLI that decides what goes into the context window, what gets written to persistent memory, and what is retrieved on demand.
LicenseRef-MIT-Commons-Clause 112 installs ★ 1,183 updated 2026-11-08
npx skills add borghei/Claude-Skills --skill context-engine -a claude-codeWhat context-engine does
The skill works across Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode, attaching in each as a SKILL.md file. It ships four Python scripts: context_analyzer.py estimates token counts for files or a prompt, context_budget_planner.py allocates a window across components and returns an eviction order on overflow, context_pruner.py strips comments, docstrings, and duplicates from code, and memory_indexer.py builds a TF-IDF index over a directory of notes or docs.
Four placement zones govern every piece of content. Anchors — instructions and the task spec — stay in the window. Decisions and conventions go to a memory file and reload at session start. A large codebase gets indexed and retrieved per step. Recomputable facts such as test output are never stored. Compaction fires at 70–80% of the window: stale tool outputs leave first, then old history is summarised and replaced, but only after conclusions are written to memory.
All scripts accept --json for machine-readable output. context_budget_planner.py exits with 1 on overflow and 2 on bad arguments. Token counting uses roughly 4 characters per token as an approximation; for exact figures, call the provider's token-counting endpoint directly.
What it helps with
- allocate a token budget across system prompt, history, tools, and RAG
- build a RAG pipeline over a codebase using a TF-IDF index
- trigger context compaction before the window ceiling is reached
- persist decisions and open questions across agent sessions
- strip comments and duplicates from source files before loading them into context
Example prompts for the agent
- Analyse token usage in
references/against a budget of 128000 and show what to evict first - Run
context_pruner.pyonsrc/with--aggressiveand report how many tokens are freed
How to install context-engine
1Skills CLI (Vercel)
npx skills add borghei/Claude-Skills --skill context-engine -a claude-code2Manually: put the files in place
~/.claude/skills/context-engine/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/context-engine/
1Skills CLI (Vercel)
npx skills add borghei/Claude-Skills --skill context-engine -a codex2Manually: put the files in place
.agents/skills/context-engine/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add borghei/Claude-Skills --skill context-engine -a cursor2Manually: put the files in place
.cursor/skills/context-engine/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install borghei/Claude-Skills engineering/context-engine/SKILL.md2Manually: put the files in place
.github/skills/context-engine/SKILL.md1Skills CLI (Vercel)
npx skills add borghei/Claude-Skills --skill context-engine -a gemini-cli2Platform CLI
gemini skills install https://github.com/borghei/Claude-Skills --path engineering/context-engineManually: put the files in place
.devin/skills/context-engine/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add borghei/Claude-Skills --skill context-engine -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about context-engine
How do I install context-engine in Claude Code?
Run npx skills add borghei/Claude-Skills --skill context-engine -a claude-code. The skill is then available at ~/.claude/skills/context-engine/SKILL.md.
What does the context-engine skill do?
It guides the agent on what to keep in the active window, what to write to long-term memory, and what to retrieve through an index. The four included scripts handle token analysis, budget planning, code pruning, and memory indexing.
How accurate is the token count from context_analyzer.py?
The script estimates roughly 4 characters per token. For exact numbers, use the token-counting endpoint provided by your model's API.
Similar skills
All skills for Agent setup: memory, context, orchestration →context-engine by other authors comes first.