Skip to main content
skill CX Codex

context-engineering · rohitg00 — Claude Code skill: what it does, how to install

context-engineering guides Claude Code through the four context operations — Write, Select, Compress, and Isolate — to prevent context degradation.

MIT ★ 2,966 updated 2026-09-29

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add rohitg00/pro-workflow
/plugin install pro-workflow@pro-workflow
Open on GitHub

What context-engineering does

This skill establishes clear rules for token management across long AI sessions. It structures session control around four distinct actions. Write moves state into NOTES.md or CLAUDE.md so decisions persist through session compaction. Select prioritizes surgical retrieval with grep and targeted line offsets over loading full modules. Compress defines compaction boundaries, prompts selective summarizing, and restores essential project rules via a PostCompact hook. Isolate splits intensive work into subagents, clean sessions, or git worktrees using claude -w.

The skill details budget planning, reserving 20–30K tokens for static MCP tool schemas while leaving the remainder for active execution. Running more than 15 MCP servers directly threatens this dynamic window because tool definitions consume budget before any code runs.

What it helps with

  • prevent context degradation during long coding sessions
  • preserve critical task state across session compaction
  • isolate heavy exploration and test execution into subagents
  • stop models from reading large files when single functions suffice

Example prompts for the agent

  • Organize our context budget and set up a scratchpad workflow in NOTES.md
  • Help me configure a PostCompact hook to retain critical context
  • Delegate auth module exploration to an isolated subagent

How to install context-engineering

1Plugin marketplace

/plugin marketplace add rohitg00/pro-workflow
/plugin install pro-workflow@pro-workflow

This installs the whole pro-workflow plugin with all its skills

2Skills CLI (Vercel)

npx skills add rohitg00/pro-workflow --skill context-engineering -a claude-code

3Manually: put the files in place

~/.claude/skills/context-engineering/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/context-engineering/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about context-engineering

How do I install context-engineering in Claude Code?

Run /plugin marketplace add rohitg00/pro-workflow followed by /plugin install pro-workflow@pro-workflow inside Claude Code.

What does context-engineering do?

It equips the agent with guidelines for token budgets, scratchpad persistence, targeted line reading, compaction hooks, and subagent delegation.

When does the skill trigger compaction?

It recommends compacting after planning phases, upon feature completion, or once context usage reaches 50% via CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50.

Source text

SKILL.md · MIT
---
name: context-engineering
description: Master the four operations of context engineering — Write, Select, Compress, Isolate. Manage token budgets, compaction strategies, and context partitioning to keep AI sessions sharp and efficient.
user-invocable: true
---

# Context Engineering

Four operations control everything about how context flows through an AI coding session. Master them and you control the quality of every response.

## The Four Operations

### 1. Write — Persist Info Outside Context

Move information out of the context window into durable storage so it survives compaction and session boundaries.

**Where to write:**

| Target | When | Example |
|--------|------|---------|
| CLAUDE.md | Permanent project rules | "Always use pnpm, never npm" |
| NOTES.md / scratchpad | Working state for current task | Architecture decisions, open questions |
| `.claude/memory/` | Learnings and patterns | `[LEARN]` rules from corrections |
| External files | Data too large for context | Test plans, migration checklists |

**Pattern — Scratchpad workflow:**
```text
1. Start complex task → create NOTES.md with goals and constraints
2. After research → write findings to NOTES.md
3. After compaction → NOTES.md survives, context does not
4. Resume → read NOTES.md to recover full state
```

### 2. Select — Retrieve Relevant Info

Pull the right information into context at the right time. Precision matters more than volume.

**Methods ranked by precision:**

1. `@file` references — exact file injection
2. `grep` / `Glob` — targeted pattern search
3. Subagent exploration — delegated deep search
4. RAG / embeddings — semantic retrieval for large codebases

**Key principle: Focused 300 tokens > unfocused 113K tokens.**

A surgical grep result that returns the exact function signature beats dumping an entire module into context. Every irrelevant token dilutes attention.

**Pattern — Progressive retrieval:**
```text
1. Start with file names (Glob)
2. Narrow to specific functions (Grep)
3. Read only the relevant lines (Read with offset+limit)
4. Never read entire large files when you need one function
```

### 3. Compress — Reduce Tokens, Preserve Signal

Shrink context without losing the information that matters.

**Compaction strategies:**

| Strategy | How | When |
|----------|-----|------|
| `/compact` with focus | `/compact focus: auth module changes` | Task boundaries |
| Microcompact | Ask Claude to summarize tool output inline | After large reads/searches |
| Head+tail | Read first 20 + last 20 lines of large output | Log analysis, test results |
| Tool result clearing | Subagent results auto-clear after reporting | Heavy exploration |
| Semantic selection | Summarize findings, discard raw data | Research phases |

**Compaction triggers:**

- After planning, before implementation
- After completing a feature or milestone
- When context exceeds 50% (set `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50`)
- Before switching task domains
- After heavy search/read operations

**PostCompact hook — Re-inject critical context:**
```json
{
  "type": "PostCompact",
  "command": "cat .claude/critical-context.md"
}
```

Use this to ensure project rules, current task state, or architecture constraints survive every compaction.

### 4. Isolate — Partition Across Execution Spaces

Don't load everything into one context. Split work across independent execution spaces.

| Method | Isolation Level | Use When |
|--------|----------------|----------|
| Subagents | Forked context | Heavy exploration, test runs, doc generation |
| Worktrees (`claude -w`) | Full repo copy | Parallel features, competing approaches |
| `/btw` (built-in Claude Code) | Temporary overlay | Quick questions without entering conversation history |
| Agent teams | Independent sessions | Cross-layer changes, parallel reviews |
| Fresh session (`/resume`) | Clean slate | Unrelated work, degraded context |

**Pattern — Subagent delegation:**
```text
Main session: planning, coordination, commits
Subagent 1: explore auth module, report findings
Subagent 2: run test suite, report failures
Subagent 3: generate migration script
```

Main context stays clean. Subagents handle the volume.

## Context Budget Planning

Example baseline (calibrate with `/context`): a 200K window (Haiku 4.5; Fable 5.1, Opus 5.5, and Sonnet 5 carry 1M) with ~20K overhead (CLAUDE.md, tool definitions, MCP schemas) leaves **~180K usable**. Quality still drops as context fills, so keep the same discipline on 1M tiers. Actual budgets vary by model and configuration.

| Allocation | Budget | What Goes Here |
|------------|--------|----------------|
| Static context | 20-30K | CLAUDE.md, tool schemas, MCP definitions |
| Dynamic context | 150-180K | Code, conversation, tool results |

**Put static context first.** CLAUDE.md and tool definitions load before conversation. Keeping them stable maximizes prompt cache hits — saves cost and latency.

| Phase | Target Usage | Action If Over |
|-------|-------------|----------------|
| Planning | < 20% | Keep plans concise, write to scratchpad |
| Implementation | < 50% | Compact between files, delegate reads |
| Testing | < 70% | Delegate test runs to subagents |
| Review | < 85% | Start fresh session if degraded |

## When to /clear vs /compact vs Subagent

| Situation | Action |
|-----------|--------|
| Task boundary, want to keep learnings | `/compact` with focus |
| Context degraded, Claude repeating itself | `/compact`, then `/resume` if still bad |
| Starting unrelated work | `/clear` or new session |
| Heavy read/search operation | Delegate to subagent |
| Quick side question | `/btw` (doesn't pollute main context) |
| Exploring multiple approaches | Worktrees or agent teams |

## Anti-Patterns

- Loading entire files when you need one function
- Keeping MCP tool results in context after extracting what you need
- Running 15+ MCPs (each adds tool schema overhead to every request)
- Vague prompts that force Claude to search broadly ("fix the code")
- Never compacting until auto-compact triggers at 95%

## Add to CLAUDE.md

```markdown
## Context Engineering

Write to NOTES.md for working state that must survive compaction.
Select with precision — grep first, read specific lines, never dump whole files.
Compact at 50% or task boundaries. Set CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50.
Isolate heavy work to subagents. Main session stays for coordination and commits.
```

© Rohit Ghumare · MIT · rohitg00/pro-workflow

Similar skills

All skills for Agent setup: memory, context, orchestration →

context-engineering by other authors comes first.

context-engineering addyosmani context-engineering helps you set up agent context: which rules, specs and files to feed the agent, and when. Use it at the start of a session, when output quality drops, or when switching tasks. CX Codex +1 78,100installs context-engineering mrgoonie context-engineering guides LLM agent context design, token compaction, and memory isolation to prevent attention degradation during long runs. CX Codex +1 508installs context-engineering mvschwarz context-engineering — a skill about how an agent's context window gets filled, pruned and shared. Useful when an agent drifts or forgets constraints mid-task. CX Codex +1 ★ 8,928repo stars janitor-value Krzysztof Hendzel janitor-value audits installed skills against actual session history to spot context waste. Ideal when checking which prompts overload your context window. CX Codex +1 ★ 140repo stars context-surfing pskoett context-surfing monitors context coherence during extended coding sessions, saving state and performing clean handoffs before hallucinations ruin output. CX Codex +1 272installs context-engine borghei 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. CX Codex +1 112installs context-mode Mert Koseoğlu context-mode routes heavy tool outputs and web pages into an MCP sandbox so raw data does not clutter the agent context window. CX Codex +1 ★ 34,370repo stars context-budget affaan-m context-budget — a skill for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode that displays live context usage and remaining capacity through the provider's native commands. CX Codex +1 7,000installs context-compression muratcankoylan context-compression gives an agent a written procedure for folding a long session into a structured summary: intent, files touched, decisions, next steps. CX Codex +1 669installs

From the same set83

The whole set →
skill-router The skill-router skill maps pro-workflow skills and commands to jobs, with guidance on when to use each and whether a person or the agent starts it. Use it when you’re unsure what fits. CX Codex +1 ★ 2,966repo stars permission-analyst permission-analyst analyzes permission prompts and auto mode denials, recommends permissions rules and autoMode entries. Use it when prompts slow you down or auto mode keeps falling back to confirmations. CX Codex ★ 2,966repo stars safe-mode safe-mode intercepts destructive terminal commands and confines agent edits to a specific directory using Claude Code hooks. CX Codex +1 ★ 2,966repo stars wiki-research-loop wiki-research-loop is a Claude Code skill that researches a topic and adds pages to a wiki. It runs on requests such as research <topic> or instructions to grow a wiki automatically. CX Codex +1 ★ 2,966repo stars survey-generator survey-generator generates structured literature surveys on AI/ML topics. Output is a wiki page in markdown with bibliography, not a one-off HTML file. CX Codex +1 ★ 2,966repo stars learn learn is a Claude Code command that shows topic-based guidance and saves confirmed takeaways from a session. CX Codex +1 ★ 2,966repo stars pro-workflow pro-workflow — a skill that packages coding habits for AI agents: correction loops, pre-flight rules, worktree sessions and a wrap-up ritual. CX Codex +1 ★ 2,966repo stars pro-workflow The pro-workflow plugin for Claude Code adds persistent SQLite memory, FTS5-indexed project wikis, and 23 slash commands to carry instructions across sessions. ★ 2,966repo stars

Project sponsors

Companies that keep this analytics open