context-engineering

Optimizes agent context setup for maximum output quality. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when configuring rules files and context for AI-assisted development. Covers the context hierarchy, packing strategies, and confusion management.

26 stars

Best use case

context-engineering is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Optimizes agent context setup for maximum output quality. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when configuring rules files and context for AI-assisted development. Covers the context hierarchy, packing strategies, and confusion management.

Teams using context-engineering should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/context-engineering/SKILL.md --create-dirs "https://raw.githubusercontent.com/TerminalSkills/skills/main/skills/context-engineering/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/context-engineering/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How context-engineering Compares

Feature / Agentcontext-engineeringStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Optimizes agent context setup for maximum output quality. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when configuring rules files and context for AI-assisted development. Covers the context hierarchy, packing strategies, and confusion management.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Context Engineering

## Overview

Feed agents the right information at the right time. Context is the single biggest lever for agent output quality — too little and the agent hallucinates, too much and it loses focus. Context engineering is the practice of deliberately curating what the agent sees, when it sees it, and how it's structured.

## Instructions

### The Context Hierarchy

Structure context from most persistent to most transient:

```
1. Rules Files (CLAUDE.md, etc.)   ← Always loaded, project-wide
2. Spec / Architecture Docs        ← Loaded per feature/session
3. Relevant Source Files            ← Loaded per task
4. Error Output / Test Results      ← Loaded per iteration
5. Conversation History             ← Accumulates, compacts
```

### Level 1: Rules Files

Create a rules file that persists across sessions — highest-leverage context:

```markdown
# Project: [Name]
## Tech Stack
- React 18, TypeScript 5, Vite, Tailwind CSS 4
## Commands
- Build: `npm run build` | Test: `npm test` | Dev: `npm run dev`
## Code Conventions
- Functional components with hooks (no class components)
- Named exports (no default exports)
- Colocate tests: `Button.tsx` → `Button.test.tsx`
## Boundaries
- Never commit .env files or secrets
- Ask before modifying database schema
- Always run tests before committing
```

Equivalent files: `.cursorrules`, `.windsurfrules`, `.github/copilot-instructions.md`, `AGENTS.md`

### Level 2: Specs and Architecture

Load relevant spec sections when starting a feature. Don't load the entire spec if only one section applies.

**Effective:** "Here's the authentication section of our spec"
**Wasteful:** "Here's our entire 5000-word spec" (when only working on auth)

### Level 3: Relevant Source Files

Before editing, read the files. Before implementing a pattern, find an existing example.

**Pre-task context loading:**
1. Read the file(s) you'll modify
2. Read related test files
3. Find one example of a similar pattern in the codebase
4. Read type definitions or interfaces involved

### Level 4: Error Output

Feed specific errors, not entire logs:

**Effective:** "Test failed: `TypeError: Cannot read property 'id' of undefined at UserService.ts:42`"
**Wasteful:** Pasting 500-line test output when one test failed

### Level 5: Conversation Management

- Start fresh sessions when switching major features
- Summarize progress when context gets long
- Compact deliberately before critical work

### Context Packing Strategies

**The Selective Include** — only what's relevant:

```
TASK: Add email validation to the registration endpoint
RELEVANT FILES:
- src/routes/auth.ts (endpoint to modify)
- src/lib/validation.ts (existing validation utilities)
- tests/routes/auth.test.ts (tests to extend)
PATTERN TO FOLLOW:
- See phone validation in src/lib/validation.ts:45-60
CONSTRAINT:
- Must use existing ValidationError class
```

**The Hierarchical Summary** — for large projects, maintain a project map:

```markdown
## Authentication (src/auth/)
Key files: auth.routes.ts, auth.service.ts, auth.middleware.ts
Pattern: All routes use authMiddleware, errors use AuthError class

## Tasks (src/tasks/)
Key files: task.routes.ts, task.service.ts, task.socket.ts
Pattern: Optimistic updates via WebSocket
```

### Confusion Management

**When context conflicts:**
```
CONFUSION:
Spec says "Use REST for all endpoints" but existing code uses GraphQL
for user queries (src/graphql/user.ts).
Options:
A) Follow the spec — add REST endpoint
B) Follow existing patterns — use GraphQL, update spec
C) Ask — this seems intentional
→ Which approach?
```

**When requirements are incomplete:** Check existing code for precedent. If none, stop and ask. Don't invent requirements.

## Examples

### The Inline Planning Pattern

For multi-step tasks, emit a lightweight plan before executing:

```
PLAN:
1. Add Zod schema for task creation
2. Wire schema into POST /api/tasks route handler
3. Add test for validation error response
→ Executing unless you redirect.
```

This catches wrong directions before you've built on them.

## Guidelines

### Anti-Patterns

| Anti-Pattern | Fix |
|---|---|
| Context starvation | Load rules file + relevant source before each task |
| Context flooding (>5000 lines) | Include only what's relevant, aim for <2000 lines |
| Stale context | Start fresh sessions when context drifts |
| Missing examples | Include one example of the pattern to follow |
| Implicit knowledge | Write it in rules files — unwritten rules don't exist |
| Silent confusion | Surface ambiguity explicitly |

### Red Flags

- Agent output doesn't match project conventions
- Agent invents APIs or imports that don't exist
- Agent re-implements existing utilities
- Agent quality degrades as conversation gets longer
- No rules file exists in the project

### Verification

- [ ] Rules file covers tech stack, commands, conventions, boundaries
- [ ] Agent output follows the patterns in the rules file
- [ ] Agent references actual project files (not hallucinated ones)
- [ ] Context is refreshed when switching between major tasks

Related Skills

prompt-engineering

26
from TerminalSkills/skills

Prompt engineering techniques for LLMs — zero-shot, few-shot, chain-of-thought, ReAct, and structured prompting. Use when designing prompts for AI features, improving LLM output quality, building reliable AI pipelines, or getting consistent structured responses from language models.

product-marketing-context

26
from TerminalSkills/skills

When the user wants to create or update their product marketing context document. Also use when the user mentions 'product context,' 'marketing context,' 'set up context,' 'positioning,' or wants to avoid repeating foundational information across marketing tasks. Creates `.claude/product-marketing-context.md` that other marketing skills reference.

zustand

26
from TerminalSkills/skills

You are an expert in Zustand, the small, fast, and scalable state management library for React. You help developers manage global state without boilerplate using Zustand's hook-based stores, selectors for performance, middleware (persist, devtools, immer), computed values, and async actions — replacing Redux complexity with a simple, un-opinionated API in under 1KB.

zoho

26
from TerminalSkills/skills

Integrate and automate Zoho products. Use when a user asks to work with Zoho CRM, Zoho Books, Zoho Desk, Zoho Projects, Zoho Mail, or Zoho Creator, build custom integrations via Zoho APIs, automate workflows with Deluge scripting, sync data between Zoho apps and external systems, manage leads and deals, automate invoicing, build custom Zoho Creator apps, set up webhooks, or manage Zoho organization settings. Covers Zoho CRM, Books, Desk, Projects, Creator, and cross-product integrations.

zod

26
from TerminalSkills/skills

You are an expert in Zod, the TypeScript-first schema declaration and validation library. You help developers define schemas that validate data at runtime AND infer TypeScript types at compile time — eliminating the need to write types and validators separately. Used for API input validation, form validation, environment variables, config files, and any data boundary.

zipkin

26
from TerminalSkills/skills

Deploy and configure Zipkin for distributed tracing and request flow visualization. Use when a user needs to set up trace collection, instrument Java/Spring or other services with Zipkin, analyze service dependencies, or configure storage backends for trace data.

zig

26
from TerminalSkills/skills

Expert guidance for Zig, the systems programming language focused on performance, safety, and readability. Helps developers write high-performance code with compile-time evaluation, seamless C interop, no hidden control flow, and no garbage collector. Zig is used for game engines, operating systems, networking, and as a C/C++ replacement.

zed

26
from TerminalSkills/skills

Expert guidance for Zed, the high-performance code editor built in Rust with native collaboration, AI integration, and GPU-accelerated rendering. Helps developers configure Zed, create custom extensions, set up collaborative editing sessions, and integrate AI assistants for productive coding.

zeabur

26
from TerminalSkills/skills

Expert guidance for Zeabur, the cloud deployment platform that auto-detects frameworks, builds and deploys applications with zero configuration, and provides managed services like databases and message queues. Helps developers deploy full-stack applications with automatic scaling and one-click marketplace services.

zapier

26
from TerminalSkills/skills

Automate workflows between apps with Zapier. Use when a user asks to connect apps without code, automate repetitive tasks, sync data between services, or build no-code integrations between SaaS tools.

zabbix

26
from TerminalSkills/skills

Configure Zabbix for enterprise infrastructure monitoring with templates, triggers, discovery rules, and dashboards. Use when a user needs to set up Zabbix server, configure host monitoring, create custom templates, define trigger expressions, or automate host discovery and registration.

yup

26
from TerminalSkills/skills

Validate data with Yup schemas. Use when adding form validation, defining API request schemas, validating configuration, or building type-safe validation pipelines in JavaScript/TypeScript.