# context-engine

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.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 112 installs · ★ 1183 repo stars
- Author: borghei
- License: LicenseRef-MIT-Commons-Clause · policy=link-only · description only; the file stays with the author
- Source: https://github.com/borghei/Claude-Skills/tree/HEAD/engineering/context-engine/SKILL.md
- Updated: 2026-11-08
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/borghei-context-engine

## What it 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.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add borghei/Claude-Skills --skill context-engine -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/context-engine/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/context-engine/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add borghei/Claude-Skills --skill context-engine -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/context-engine/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add borghei/Claude-Skills --skill context-engine -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/context-engine/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install borghei/Claude-Skills engineering/context-engine/SKILL.md
```

2. **Manually: put the files in place**
- File: `.github/skills/context-engine/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add borghei/Claude-Skills --skill context-engine -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/borghei/Claude-Skills --path engineering/context-engine
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/context-engine/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add borghei/Claude-Skills --skill context-engine -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/borghei/Claude-Skills/tree/HEAD/engineering/context-engine/SKILL.md

## When to use it
- 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
- Analyse token usage in `references/` against a budget of 128000 and show what to evict first
- Run `context_pruner.py` on `src/` with `--aggressive` and report how many tokens are freed

## Similar
- [context-engineering-advisor](https://affpapa.org/en/nevibecode/skills/context-engineering-advisor.md) — skill · 2800 installs
- [Context Engine](https://affpapa.org/en/nevibecode/mcp/context-engine.md) — MCP server · ★ 324 repo stars
- [agent-platform-rag-engine-management](https://affpapa.org/en/nevibecode/skills/agent-platform-rag-engine-management.md) — skill · 8626 installs
- [agent-orchestration-context-manager](https://affpapa.org/en/nevibecode/agents/agent-orchestration-context-manager.md) — subagent · ★ 42780 repo stars
- [context-compressor](https://affpapa.org/en/nevibecode/skills/context-compressor.md) — skill · 274 installs
- [hindsight-docs](https://affpapa.org/en/nevibecode/skills/hindsight-docs.md) — skill · 9700 installs

## Other versions with the same name
- [context-engine · alirezarezvani](https://affpapa.org/en/nevibecode/skills/context-engine.md) — 585 installs

From the same set: [borghei/claude-skills](https://affpapa.org/en/nevibecode/by/borghei/claude-skills.md) — 120 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
