Agent skill
engineering-claude-context
Curates context, optimizes prompts with XML, and manages extended thinking for Anthropic Claude models. Use when building Claude-based agents, designing system prompts, or handling long-context tasks.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/design/engineering-claude-context
SKILL.md
Claude Context Engineering
Instructions
Follow these strategies to maximize reliability and performance for Anthropic Claude models within limited attention budgets.
-
Curate High-Signal Context
- Treat context as a finite resource; every token dilutes attention.
- Prune low-value information (e.g., repetitive logs, unused tool outputs).
- Use "Just-in-Time" Retrieval: Provide lightweight identifiers (file lists, summaries) initially, allowing Claude to load full details only when needed.
-
Structure with XML Tags
- Use XML tags to strictly delineate prompt sections (Claude is optimized for this).
- Common tags:
<instructions>,<context>,<tools>,<examples>,<formatting>. - Nest tags for hierarchy (e.g.,
<examples><example>...</example></examples>). - Reference tags explicitly in instructions (e.g., "Analyze the data in
<context>").
-
Optimize for Long Horizons
- Compaction: Periodically summarize conversation history to free up context while preserving key state (decisions, bugs).
- Memory: Implement an external "notebook" (e.g.,
scratchpad.md) where Claude reads/writes persistent state, freeing it from the context window. - Sub-Agents: Delegate distinct, context-heavy sub-tasks to ephemeral sub-agents that return only distilled results.
-
Leverage Extended Thinking
- Use for: Complex STEM problems, constraint optimization, and multi-step strategic frameworks.
- Prompting: Use open-ended, high-level instructions ("Think thoroughly about X") rather than rigid step-by-step constraints for reasoning.
- Few-Shot: Include
<thinking>blocks in your examples to demonstrate the reasoning process, not just the final output. - Budget: Start small (1024 tokens) and scale up for complexity (up to 32k+ with batch processing).
-
Design Token-Efficient Tools
- Ensure tools return only necessary data (e.g.,
grepoutput vs. full file). - Keep tool definitions clear and distinct to avoid ambiguity.
- Ensure tools return only necessary data (e.g.,
Critical Rules
- No Brittle Logic: Avoid hardcoding complex if/else chains in prompts; use examples ("pictures") to guide behavior instead.
- Don't Prefill Thinking: Never prefill Claude's response when using Extended Thinking mode.
- Progressive Disclosure: Don't dump all data at once. Let Claude discover information layer by layer (hierarchy -> summary -> detail).
- Clear Separation: Always separate
System InstructionsfromUser Datato prevent prompt injection and confusion.
Checklist
- Tags: Are distinct sections wrapped in XML tags?
- Efficiency: Is the initial context free of unnecessary bulk?
- Retrieval: Does Claude have tools to fetch details "just-in-time"?
- Memory: Is there a mechanism (compaction or external file) for long-term persistence?
- Examples: Do few-shot examples demonstrate the reasoning (if using thinking) or format required?
- Thinking: Is Extended Thinking enabled only for complex/planning tasks, not simple lookups?
Detailed Guidance
For deep dives on context anatomy, compaction strategies, and extended thinking patterns, see REFERENCE.md.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?