跳到正文
FunCoding

搜索

搜索文档、Skill 和 MCP

context-engineering

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.

AI 与智能体2.9kskills/context-engineering/SKILL.md

安装

把这段话发给 Claude Code、Codex 或 Cursor。智能体会先检查安全性,你确认后才安装。

读取 https://funcoding.ai/skills/rohitg00/pro-workflow/context-engineering/install.md ,按里面的步骤帮我安装这个 Skill。

SKILL.md

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:

TargetWhenExample
CLAUDE.mdPermanent project rules"Always use pnpm, never npm"
NOTES.md / scratchpadWorking state for current taskArchitecture decisions, open questions
.claude/memory/Learnings and patterns[LEARN] rules from corrections
External filesData too large for contextTest plans, migration checklists

Pattern — Scratchpad workflow:

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:

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:

StrategyHowWhen
/compact with focus/compact focus: auth module changesTask boundaries
MicrocompactAsk Claude to summarize tool output inlineAfter large reads/searches
Head+tailRead first 20 + last 20 lines of large outputLog analysis, test results
Tool result clearingSubagent results auto-clear after reportingHeavy exploration
Semantic selectionSummarize findings, discard raw dataResearch 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:

{
  "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.

MethodIsolation LevelUse When
SubagentsForked contextHeavy exploration, test runs, doc generation
Worktrees (claude -w)Full repo copyParallel features, competing approaches
/btw (built-in Claude Code)Temporary overlayQuick questions without entering conversation history
Agent teamsIndependent sessionsCross-layer changes, parallel reviews
Fresh session (/resume)Clean slateUnrelated work, degraded context

Pattern — Subagent delegation:

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.

AllocationBudgetWhat Goes Here
Static context20-30KCLAUDE.md, tool schemas, MCP definitions
Dynamic context150-180KCode, 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.

PhaseTarget UsageAction 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

SituationAction
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 operationDelegate to subagent
Quick side question/btw (doesn't pollute main context)
Exploring multiple approachesWorktrees 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

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

相似的 Skill

brand-guidelines
anthropics/skills180k

brand-guidelines

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

AI 与智能体

internal-comms
anthropics/skills180k

internal-comms

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

AI 与智能体

template-skill
anthropics/skills180k

template-skill

Replace with description of the skill and when Claude should use it.

AI 与智能体

mcp-builder
anthropics/skills180k

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

AI 与智能体

algorithmic-art
anthropics/skills180k

algorithmic-art

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.

AI 与智能体

academy-guide
anthropics/skills180k

academy-guide

Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.

AI 与智能体