Context-Engineering

GitHub

"Context engineering is the delicate art and science of filling the context window with just the right information for the next step." — Andrej Karpathy. A frontier, first-principles handbook inspired by Karpathy and 3Blue1Brown for moving beyond prompt engineering to the wider discipline of context design, orchestration, and optimization.

8,887 stars Python Markdown CodeWiki
AI Prompts & Endpoints
CodeWiki Knowledge Base

Repository: davidkimai/Context-Engineering


Stars: 8736

CLAUDE.md

CLAUDE.md - Cognitive Operating System

This document provides a comprehensive framework of cognitive tools, protocol shells, reasoning templates, and workflows for Claude Code. Load this file in your project root to enhance Claude's capabilities across all contexts.

1. Core Meta-Cognitive Framework

Context Schemas

Code Understanding Schema

json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Code Understanding Schema",
"description": "Standardized format for analyzing and understanding code",
"type": "object",
"properties": {
"codebase": {
"type": "object",
"properties": {
"structure": {
"type": "array",
"description": "Key files and directories with their purposes"
},
"architecture": {
"type": "string",
"description": "Overall architectural pattern"
},
"technologies": {
"type": "array",
"description": "Key technologies, frameworks, and libraries"
}
}
},
"functionality": {
"type": "object",
"properties": {
"entry_points": {
"type": "array",
"description": "Main entry points to the application"
},
"core_workflows": {
"type": "array",
"description": "Primary functional flows"
},
"data_flow": {
"type": "string",
"description": "How data moves through the system"
}
}
},
"quality": {
"type": "object",
"properties": {
"strengths": {
"type": "array",
"description": "Well-designed aspects"
},
"concerns": {
"type": "array",
"description": "Potential issues or areas for improvement"
},
"patterns": {
"type": "array",
"description": "Recurring design patterns"
}
}
}
}
}

Troubleshooting Schema

json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Troubleshooting Schema",
"description": "Framework for systematic problem diagnosis and resolution",
"type": "object",
"properties": {
"problem": {
"type": "object",
"properties": {
"symptoms": {
"type": "array",
"description": "Observable issues"
},
"context": {
"type": "string",
"description": "When and how the problem occurs"
},
"impact": {
"type": "string",
"description": "Severity and scope of the issue"
}
}
},
"diagnosis": {
"type": "object",
"properties": {
"potential_causes": {
"type": "array",
"description": "Possible root causes"
},
"evidence": {
"type": "array",
"description": "Supporting information for each cause"
},
"verification_steps": {
"type": "array",
"description": "How to confirm each potential cause"
}
}
},
"solution": {
"type": "object",
"properties": {
"approach": {
"type": "string",
"description": "Overall strategy"
},
"steps": {
"type": "array",
"description": "Specific actions to take"
},
"verification": {
"type": "string",
"description": "How to confirm the solution worked"
},
"prevention": {
"type": "string",
"description": "How to prevent future occurrences"
}
}
}
}
}


Reasoning Protocols

text
/reasoning.systematic{
intent="Break down complex problems into logical steps with traceable reasoning",
input={
problem="<problem_statement>",
constraints="<constraints>",
context="<context>"
},
process=[
/understand{action="Restate problem and clarify goals"},
/analyze{action="Break down into components"},
/plan{action="Design step-by-step approach"},
/execute{action="Implement solution methodically"},
/verify{action="Validate against requirements"},
/refine{action="Improve based on verification"}
],
output={
solution="Implemented solution",
reasoning="Complete reasoning trace",
verification="Validation evidence"
}
}

text
/thinking.extended{
intent="Engage deep, thorough reasoning for complex problems requiring careful consideration",
input={
problem="<problem_requiring_deep_thought>",
level="<basic|deep|deeper|ultra>" // Corresponds to think, think hard, think harder, ultrathink
},
process=[
/explore{action="Consider multiple perspectives and approaches"},
/evaluate{action="Assess trade-offs of each approach"},
/simulate{action="Test mental models against edge cases"},
/synthesize{action="Integrate insights into coherent solution"},
/articulate{action="Express reasoning clearly and thoroughly"}
],
output={
conclusion="Well-reasoned solution",
rationale="Complete thinking process",
alternatives="Other considered approaches"
}
}

Self-Improvement Protocol

text
/self.reflect{
intent="Continuously improve reasoning and outputs through recursive evaluation",
input={
previous_output="<output_to_evaluate>",
criteria="<evaluation_criteria>"
},
process=[
/assess{
completeness="Identify missing information",
correctness="Verify factual accuracy",
clarity="Evaluate understandability",
effectiveness="Determine if it meets needs"
},
/identify{
strengths="Note what was done well",
weaknesses="Recognize limitations",
assumptions="Surface implicit assumptions"
},
/improve{
strategy="Plan specific improvements",
implementation="Apply improvements methodically"
}
],
output={
evaluation="Assessment of original output",
improved_output="Enhanced version",
learning="Insights for future improvement"
}
}

2. Workflow Protocols

Explore-Plan-Code-Commit Workflow

text
/workflow.explore_plan_code_commit{
intent="Implement a systematic approach to coding tasks with thorough planning",
input={
task="<task_description>",
codebase="<relevant_files_or_directories>"
},
process=[
/explore{
action="Read relevant files and understand the codebase",
instruction="Analyze but don't write code yet"
},
/plan{
action="Create detailed implementation plan",
instruction="Use extended thinking to evaluate alternatives"
},
/implement{
action="Write code following the plan",
instruction="Verify correctness at each step"
},
/finalize{
action="Commit changes and create PR if needed",
instruction="Write clear commit messages"
}
],
output={
implementation="Working code solution",
explanation="Documentation of approach",
commit="Commit message and PR details"
}
}

Test-Driven Development Workflow

text
/workflow.test_driven{
intent="Implement changes using test-first methodology",
input={
feature="<feature_to_implement>",
requirements="<detailed_requirements>"
},
process=[
/write_tests{
action="Create comprehensive tests based on requirements",
instruction="Don't implement functionality yet"
},
/verify_tests_fail{
action="Run tests to confirm they fail appropriately",
instruction="Validate test correctness"
},
/implement{
action="Write code to make tests pass",
instruction="Focus on passing tests, not implementation elegance initially"
},
/refactor{
action="Clean up implementation while maintaining passing tests",
instruction="Improve code quality without changing behavior"
},
/finalize{
action="Commit both tests and implementation",
instruction="Include test rationale in commit message"
}
],
output={
tests="Comprehensive test suite",
implementation="Working code that passes tests",
commit="Commit message and PR details"
}
}

Iterative UI Development Workflow

text
/workflow.ui_iteration{
intent="Implement UI components with visual feedback loop",
input={
design="<design_mockup_or_description>",
components="<existing_component_references>"
},
process=[
/analyze_design{
action="Understand design requirements and constraints",
instruction="Identify reusable patterns and components"
},
/implement_initial{
action="Create first implementation of UI",
instruction="Focus on structure before styling"
},
/screenshot{
action="Take screenshot of current implementation",
instruction="Use browser tools or Puppeteer MCP"
},
/compare{
action="Compare implementation with design",
instruction="Identify differences and needed improvements"
},
/refine{
action="Iteratively improve implementation",
instruction="Take new screenshots after each significant change"
},
/finalize{
action="Polish and commit final implementation",
instruction="Include screenshots in documentation"
}
],
output={
implementation="Working UI component",
screenshots="Before/after visual documentation",
commit="Commit message and PR details"
}
}

3. Code Analysis & Generation Tools

Code Analysis Protocol

text
/code.analyze{
intent="Deeply understand code structure, patterns and quality",
input={
code="<code_to_analyze>",
focus="<specific_aspects_to_examine>"
},
process=[
/parse{
structure="Identify main components and organization",
patterns="Recognize design patterns and conventions",
flow="Trace execution and data flow paths"
},
/evaluate{
quality="Assess code quality and best practices",
performance="Identify potential performance issues",
security="Spot potential security concerns",
maintainability="Evaluate long-term maintainability"
},
/summarize{
purpose="Describe the code's primary functionality",
architecture="Outline architectural approach",
interfaces="Document key interfaces and contracts"
}
],
output={
overview="High-level summary of the code",
details="Component-by-component breakdown",
recommendations="Suggested improvements"
}
}

Code Generation Protocol

text
/code.generate{
intent="Create high-quality, maintainable code meeting requirements",
input={
requirements="<feature_requirements>",
context="<codebase_context>",
constraints="<technical_constraints>"
},
process=[
/design{
architecture="Plan overall structure",
interfaces="Define clean interfaces",
patterns="Select appropriate design patterns"
},
/implement{
skeleton="Create foundational structure",
core="Implement primary functionality",
edge_cases="Handle exceptions and edge cases",
tests="Include appropriate tests"
},
/review{
functionality="Verify requirements are met",
quality="Ensure code meets quality standards",
style="Adhere to project conventions"
},
/document{
usage="Provide usage examples",
rationale="Explain key decisions",
integration="Describe integration points"
}
],
output={
code="Complete implementation",
tests="Accompanying tests",
documentation="Comprehensive documentation"
}
}

Refactoring Protocol

text
/code.refactor{
intent="Improve existing code without changing behavior",
input={
code="<code_to_refactor>",
goals="<refactoring_objectives>"
},
process=[
/analyze{
behavior="Document current behavior precisely",
tests="Identify or create verification tests",
issues="Identify code smells and problems"
},
/plan{
approach="Design refactoring strategy",
steps="Break down into safe, incremental changes",
verification="Plan verification at each step"
},
/execute{
changes="Implement refactoring incrementally",
tests="Run tests after each change",
review="Self-review each modification"
},
/validate{
functionality="Verify preserved behavior",
improvements="Confirm refactoring goals were met",
documentation="Update documentation if needed"
}
],
output={
refactored_code="Improved implementation",
verification="Evidence of preserved behavior",
improvements="Summary of changes and benefits"
}
}

4. Testing & Validation Frameworks

Test Suite Generation Protocol

text
/test.generate{
intent="Create comprehensive test suite for code verification",
input={
code="<code_to_test>",
requirements="<functionality_requirements>"
},
process=[
/analyze{
functionality="Identify core functionality",
edge_cases="Determine boundary conditions",
paths="Map execution paths"
},
/design{
unit_tests="Design focused component tests",
integration_tests="Design cross-component tests",
edge_case_tests="Design boundary condition tests",
performance_tests="Design performance verification"
},
/implement{
framework="Set up testing framework",
fixtures="Create necessary test fixtures",
tests="Implement designed tests",
assertions="Include clear assertions"
},
/validate{
coverage="Verify adequate code coverage",
independence="Ensure test independence",
clarity="Confirm test readability"
}
],
output={
test_suite="Complete test implementation",
coverage_analysis="Test coverage assessment",
run_instructions="How to execute tests"
}
}

Bug Diagnosis Protocol

text
/bug.diagnose{
intent="Systematically identify root causes of issues",
input={
symptoms="<observed_problem>",
context="<environment_and_conditions>"
},
process=[
/reproduce{
steps="Establish reliable reproduction steps",
environment="Identify environmental factors",
consistency="Determine reproducibility consistency"
},
/isolate{
scope="Narrow down affected components",
triggers="Identify specific triggers",
patterns="Recognize symptom patterns"
},
/analyze{
trace="Follow execution path through code",
state="Examine relevant state and data",
interactions="Study component interactions"
},
/hypothesize{
causes="Formulate potential root causes",
tests="Design tests for each hypothesis",
verification="Plan verification approach"
}
],
output={
diagnosis="Identified root cause",
evidence="Supporting evidence",
fix_strategy="Recommended solution approach"
}
}

5. Git & GitHub Integration

Git Workflow Protocol

text
/git.workflow{
intent="Manage code changes with Git best practices",
input={
changes="<code_changes>",
branch_strategy="<branching_approach>"
},
process=[
/prepare{
branch="Create or select appropriate branch",
scope="Define clear scope for changes",
baseline="Ensure clean starting point"
},
/develop{
changes="Implement required changes",
commits="Create logical, atomic commits",
messages="Write clear commit messages"
},
/review{
diff="Review changes thoroughly",
tests="Ensure tests pass",
standards="Verify adherence to standards"
},
/integrate{
sync="Sync with target branch",
conflicts="Resolve any conflicts",
validate="Verify integration success"
}
],
output={
commits="Clean commit history",
branches="Updated branch state",
next_steps="Recommended follow-up actions"
}
}

GitHub PR Protocol

text
/github.pr{
intent="Create and manage effective pull requests",
input={
changes="<implemented_changes>",
context="<purpose_and_background>"
},
process=[
/prepare{
review="Self-review changes",
tests="Verify tests pass",
ci="Check CI pipeline status"
},
/create{
title="Write clear, descriptive title",
description="Create comprehensive description",
labels="Add appropriate labels",
reviewers="Request appropriate reviewers"
},
/respond{
reviews="Address review feedback",
updates="Make requested changes",
discussion="Engage in constructive discussion"
},
/finalize{
checks="Ensure all checks pass",
approval="Confirm necessary approvals",
merge="Complete merge process"
}
],
output={
pr="Complete pull request",
status="PR status and next steps",
documentation="Any follow-up documentation"
}
}

Git History Analysis Protocol

text
/git.analyze_history{
intent="Extract insights from repository history",
input={
repo="<repository_path>",
focus="<analysis_objective>"
},
process=[
/collect{
commits="Gather relevant commit history",
authors="Identify contributors",
patterns="Detect contribution patterns"
},
/analyze{
changes="Examine code evolution",
decisions="Trace architectural decisions",
trends="Identify development trends"
},
/synthesize{
insights="Extract key insights",
timeline="Create evolutionary timeline",
attribution="Map features to contributors"
}
],
output={
history_analysis="Comprehensive historical analysis",
key_insights="Important historical patterns",
visualization="Temporal representation of evolution"
}
}

6. Project Navigation & Exploration

Codebase Exploration Protocol

text
/project.explore{
intent="Build comprehensive understanding of project structure",
input={
repo="<repository_path>",
focus="<exploration_objectives>"
},
process=[
/scan{
structure="Map directory hierarchy",
files="Identify key files",
patterns="Recognize organizational patterns"
},
/analyze{
architecture="Determine architectural approach",
components="Identify main components",
dependencies="Map component relationships"
},
/document{
overview="Create high-level summary",
components="Document key components",
patterns="Describe recurring patterns"
}
],
output={
map="Structural representation of codebase",
key_areas="Identified important components",
entry_points="Recommended starting points"
}
}

Dependency Analysis Protocol

text
/project.analyze_dependencies{
intent="Understand project dependencies and relationships",
input={
project="<project_path>",
depth="<analysis_depth>"
},
process=[
/scan{
direct="Identify direct dependencies",
transitive="Map transitive dependencies",
versions="Catalog version constraints"
},
/analyze{
usage="Determine how dependencies are used",
necessity="Evaluate necessity of each dependency",
alternatives="Identify potential alternatives"
},
/evaluate{
security="Check for security issues",
maintenance="Assess maintenance status",
performance="Evaluate performance impact"
}
],
output={
dependency_map="Visual representation of dependencies",
recommendations="Suggested optimizations",
risks="Identified potential issues"
}
}

7. Self-Reflection & Improvement Mechanisms

Knowledge Gap Identification Protocol

text
/self.identify_gaps{
intent="Recognize and address knowledge limitations",
input={
context="<current_task_context>",
requirements="<knowledge_requirements>"
},
process=[
/assess{
current="Evaluate current understanding",
needed="Identify required knowledge",
gaps="Pinpoint specific knowledge gaps"
},
/plan{
research="Design targeted research approach",
questions="Formulate specific questions",
sources="Identify information sources"
},
/acquire{
research="Conduct necessary research",
integration="Incorporate new knowledge",
verification="Validate understanding"
}
],
output={
gap_analysis="Identified knowledge limitations",
acquired_knowledge="New information gathered",
updated_approach="Revised approach with new knowledge"
}
}

Solution Quality Improvement Protocol

text
/self.improve_solution{
intent="Iteratively enhance solution quality",
input={
current_solution="<existing_solution>",
quality_criteria="<quality_standards>"
},
process=[
/evaluate{
strengths="Identify solution strengths",
weaknesses="Pinpoint improvement areas",
benchmarks="Compare against standards"
},
/plan{
priorities="Determine improvement priorities",
approaches="Design enhancement approaches",
metrics="Define success metrics"
},
/enhance{
implementation="Apply targeted improvements",
verification="Validate enhancements",
iteration="Repeat process as needed"
}
],
output={
improved_solution="Enhanced implementation",
improvement_summary="Description of enhancements",
quality_assessment="Evaluation against criteria"
}
}

8. Documentation Guidelines

Code Documentation Protocol

text
/doc.code{
intent="Create comprehensive, useful code documentation",
input={
code="<code_to_document>",
audience="<target_readers>"
},
process=[
/analyze{
purpose="Identify code purpose and function",
interfaces="Determine public interfaces",
usage="Understand usage patterns"
},
/structure{
overview="Create high-level description",
api="Document public API",
examples="Develop usage examples",
internals="Explain key internal concepts"
},
/implement{
inline="Add appropriate inline comments",
headers="Create comprehensive headers",
guides="Develop usage guides",
references="Include relevant references"
},
/validate{
completeness="Verify documentation coverage",
clarity="Ensure understandability",
accuracy="Confirm technical accuracy"
}
],
output={
documentation="Complete code documentation",
examples="Illustrative usage examples",
quick_reference="Concise reference guide"
}
}

Technical Writing Protocol

text
/doc.technical{
intent="Create clear, informative technical documentation",
input={
subject="<documentation_topic>",
audience="<target_readers>",
purpose="<documentation_goals>"
},
process=[
/plan{
scope="Define documentation scope",
structure="Design logical organization",
level="Determine appropriate detail level"
},
/draft{
overview="Create conceptual overview",
details="Develop detailed explanations",
examples="Include illustrative examples",
references="Add supporting references"
},
/refine{
clarity="Improve explanation clarity",
flow="Enhance logical progression",
accessibility="Adjust for audience understanding"
},
/finalize{
review="Conduct thorough review",
formatting="Apply consistent formatting",
completeness="Ensure comprehensive coverage"
}
],
output={
documentation="Complete technical document",
summary="Executive summary",
navigation="Guide to document structure"
}
}

9. Project-Specific Conventions

Bash Commands


- npm run build: Build the project
- npm run test: Run all tests
- npm run test:file <file>: Run tests for a specific file
- npm run lint: Run linter
- npm run typecheck: Run type checker

Code Style


- Use consistent indentation (2 spaces)
- Follow project-specific naming conventions
- Include JSDoc comments for public functions
- Write unit tests for new functionality
- Follow the principle of single responsibility
- Use descriptive variable and function names

Git Workflow


- Use feature branches for new development
- Write descriptive commit messages
- Reference issue numbers in commits and PRs
- Keep commits focused and atomic
- Rebase feature branches on main before PR
- Squash commits when merging to main

Project Structure


- /src: Source code
- /test: Test files
- /docs: Documentation
- /scripts: Build and utility scripts
- /types: Type definitions

Usage Notes

1. Customization: Modify sections to match your project's specific needs and conventions.

2. Extension: Add new protocols and frameworks as they become relevant to your workflow.

3. Integration: Reference these protocols in your prompts to Claude Code by mentioning them by name or structure.

4. Permissions: Consider adding common tools to your allowlist for more efficient workflows.

5. Workflow Adaptation: Combine and modify protocols to create custom workflows for your specific tasks.

6. Documentation: Keep this file updated with project-specific information and conventions.

7. Sharing: Commit this file to your repository to share these cognitive tools with your team.


README.md

<div align="center">

Context Engineering

</div>


<img width="1600" height="400" alt="image" src="https://github.com/user-attachments/assets/f41f9664-b707-4291-98c8-5bab3054a572" />

"Context engineering is the delicate art and science of filling the context window with just the right information for the next step." — Andrej Karpathy

> Software Is Changing (Again) Talk @YC AI Startup School

<div align="center">

![Ask DeepWiki](https://deepwiki.com/davidkimai/Context-Engineering)

<img width="1917" height="360" alt="image" src="https://github.com/user-attachments/assets/0c20f697-d505-4d49-a829-fc4d319eb1d3" />

</div>

<div align="center">

## DeepGraph

Chat with NotebookLM + Podcast Deep Dive

![Discord](https://discord.gg/JeFENHNNNQ)


</div>

Comprehensive Course Under Construction

### Context Engineering Survey-Review of 1400 Research Papers

> Awesome Context Engineering Repo

Operationalizing the Latest Research on Context With First Principles & Visuals — July 2025 from ICML, IBM, NeurIPS, OHBM, and more


"Providing “cognitive tools” to GPT-4.1 increases its pass@1 performance on AIME2024 from 26.7% to 43.3%, bringing it very close to the performance of o1-preview." — IBM Zurich

<div align="center">

Agent Commands


Support for Claude Code | OpenCode | Amp | Kiro | Codex | Gemini CLI

#### Context Engineering Survey-Review of 1400 Research Papers | Context Rot | IBM Zurich | Quantum Semantics | Emergent Symbolics ICML Princeton | MEM1 Singapore-MIT | LLM Attractors Shanghai AI | MemOS Shanghai | Latent Reasoning | Dynamic Recursive Depths


</div>

A frontier, first-principles handbook for moving beyond prompt engineering to the wider discipline of context design, orchestration, and optimization.


text
Prompt Engineering  │  Context Engineering
↓ │ ↓
"What you say" │ "Everything else the model sees"
(Single instruction) │ (Examples, memory, retrieval,
│ tools, state, control flow)

Definition of Context Engineering

Context is not just the single prompt users send to an LLM. Context is the complete information payload provided to a LLM at inference time, encompassing all structured informational components that the model needs to plausibly accomplish a given task.

> — Definition of Context Engineering from A Systematic Analysis of Over 1400 Research Papers

text
╭─────────────────────────────────────────────────────────────╮
│ CONTEXT ENGINEERING MASTERY COURSE │
│ From Zero to Frontier │
╰─────────────────────────────────────────────────────────────╯


Mathematical Foundations
C = A(c₁, c₂, ..., cₙ)


┌─────────────┬──────────────┬──────────────┬─────────────────┐
│ FOUNDATIONS │ SYSTEM IMPL │ INTEGRATION │ FRONTIER │
│ (Weeks 1-4) │ (Weeks 5-8) │ (Weeks 9-10) │ (Weeks 11-12) │
└─────┬───────┴──────┬───────┴──────┬───────┴─────────┬───────┘
│ │ │ │
▼ ▼ ▼ ▼
┌─────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Math Models │ │ RAG Systems │ │ Multi-Agent │ │ Meta-Recurs │
│ Components │ │ Memory Arch │ │ Orchestrat │ │ Quantum Sem │
│ Processing │ │ Tool Integr │ │ Field Theory │ │ Self-Improv │
│ Management │ │ Agent Systems│ │ Evaluation │ │ Collaboration│
└─────────────┘ └──────────────┘ └──────────────┘ └──────────────┘


Why This Repository Exists

"Meaning is not an intrinsic, static property of a semantic expression, but rather an emergent phenomenon"

Agostino et al. — July 2025, Indiana University

Prompt engineering received all the attention, but we can now get excited for what comes next. Once you've mastered prompts, the real power comes from engineering the entire context window that surrounds those prompts. Guiding thought, if you will.

This repository provides a progressive, first-principles approach to context engineering, built around a biological metaphor:

text
atoms → molecules → cells → organs → neural systems → neural & semantic field theory 
│ │ │ │ │ │
single few- memory + multi- cognitive tools + context = fields +
prompt shot agents agents operating systems persistence & resonance

"Abstraction is the cost of generalization"— Grant Sanderson (3Blue1Brown)


<div align="center">

<img width="931" height="854" alt="image" src="https://github.com/user-attachments/assets/580a9b1a-539f-41dc-abce-a5106b33350e" />

A Survey of Context Engineering - July 2025



On Emergence, Attractors, and Dynamical Systems Theory | Columbia DST


https://github.com/user-attachments/assets/9f046259-e5ec-4160-8ed0-41a608d8adf3

!image

</div>

mermaid
graph TD
classDef basic fill:#e1f5fe,stroke:#01579b,stroke-width:2px,color:#01579b
classDef intermediate fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,color:#2e7d32
classDef advanced fill:#fff3e0,stroke:#e65100,stroke-width:2px,color:#e65100
classDef meta fill:#f3e5f5,stroke:#6a1b9a,stroke-width:2px,color:#6a1b9a

subgraph Basic["Level 1: Basic Context Engineering"]
A[Atoms]
B[Molecules]
C[Cells]
D[Organs]
end

subgraph Field["Level 2: Field Theory"]
E[Neural Systems]
F[Neural Fields]
end

subgraph Protocol["Level 3: Protocol System"]
G[Protocol Shells]
H[Unified System]
end

subgraph Meta["Level 4: Meta-Recursion"]
I[Meta-Recursive Framework]
end

%% Connections
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G --> H
H --> I

%% Descriptions for each level
A1["Single instructions<br>Simple constraints<br>Basic prompts"] --> A
B1["Example pairs<br>Few-shot patterns<br>Demonstration sets"] --> B
C1["Persistent memory<br>State management<br>Context window"] --> C
D1["Multi-step flows<br>Specialists<br>System orchestration"] --> D
E1["Reasoning frameworks<br>Verification tools<br>Cognitive patterns"] --> E
F1["Continuous meaning<br>Attractors & resonance<br>Symbolic residue"] --> F
G1["Structured templates<br>Field operations<br>Emergence protocols"] --> G
H1["Protocol integration<br>System-level emergence<br>Self-maintenance"] --> H
I1["Self-reflection<br>Recursive improvement<br>Interpretable evolution"] --> I

%% Real-world parallels
A2["Like: Basic prompt<br>engineering"] -.-> A
B2["Like: Few-shot<br>learning"] -.-> B
C2["Like: Conversational<br>chatbots"] -.-> C
D2["Like: Multi-agent<br>systems"] -.-> D
E2["Like: ReAct<br>Chain-of-Thought"] -.-> E
F2["Like: Semantic<br>field theory"] -.-> F
G2["Like: Protocol<br>orchestration"] -.-> G
H2["Like: Self-organizing<br>systems"] -.-> H
I2["Like: Self-improving<br>intelligence"] -.-> I

%% Apply classes
class A,B,C,D,A1,A2,B1,B2,C1,C2,D1,D2 basic
class E,F,E1,E2,F1,F2 intermediate
class G,H,G1,G2,H1,H2 advanced
class I,I1,I2 meta

Quick Start

1. Read 00_foundations/01_atoms_prompting.md (5 min)
Understand why prompts alone often underperform

2. Run 10_guides_zero_to_hero/01_min_prompt.py (Jupyter Notebook style)
Experiment with a minimal working example

3. Explore 20_templates/minimal_context.yaml
Copy/paste a template into your own project

4. Study 30_examples/00_toy_chatbot/
See a complete implementation with context management

Learning Path

text
┌─────────────────┐     ┌──────────────────┐     ┌────────────────┐
│ 00_foundations/ │ │ 10_guides_zero_ │ │ 20_templates/ │
│ │────▶│ to_one/ │────▶│ │
│ Theory & core │ │ Hands-on │ │ Copy-paste │
│ concepts │ │ walkthroughs │ │ snippets │
└─────────────────┘ └──────────────────┘ └────────────────┘
│ │
│ │
▼ ▼
┌─────────────────┐ ┌────────────────┐
│ 40_reference/ │◀───────────────────────────▶│ 30_examples/ │
│ │ │ │
│ Deep dives & │ │ Real projects, │
│ eval cookbook │ │ progressively │
└─────────────────┘ │ complex │
▲ └────────────────┘
│ ▲
│ │
└────────────────────┐ ┌───────────┘
▼ ▼
┌─────────────────────┐
│ 50_contrib/ │
│ │
│ Community │
│ contributions │
└─────────────────────┘

What You'll Learn

| Concept | What It Is | Why It Matters |
|---------|------------|----------------|
| Token Budget | Optimizing every token in your context | More tokens = more $$ and slower responses |
| Few-Shot Learning | Teaching by showing examples | Often works better than explanation alone |
| Memory Systems | Persisting information across turns | Enables stateful, coherent interactions |
| Retrieval Augmentation | Finding & injecting relevant documents | Grounds responses in facts, reduces hallucination |
| Control Flow | Breaking complex tasks into steps | Solve harder problems with simpler prompts |
| Context Pruning | Removing irrelevant information | Keep only what's necessary for performance |
| Metrics & Evaluation | Measuring context effectiveness | Iterative optimization of token use vs. quality |
| Cognitive Tools & Prompt Programming | Learm to build custom tools and templates | Prompt programming enables new layers for context engineering |
| Neural Field Theory | Context as a Neural Field | Modeling context as a dynamic neural field allows for iterative context updating |
| Symbolic Mechanisms | Symbolic architectures enable higher order reasoning | Smarter systems = less work |
| Quantum Semantics | Meaning as observer-dependent | Design context systems leveraging superpositional techniques |

Karpathy + 3Blue1Brown Inspired Style

For learners of all experience levels

1. First principles – start with the fundamental context
2. Iterative add-on – add only what the model demonstrably lacks
3. Measure everything – token cost, latency, quality score
4. Delete ruthlessly – pruning beats padding
5. Code > slides – every concept has a runnable cell
6. Visualize everything — every concept is visualized with ASCII and symbolic diagrams

Research Evidence


Memory + Reasoning

MEM1: Learning to Synergize Memory and Reasoning for Efficient Long-Horizon Agents - Singapore-MIT June 2025

“Our results demonstrate the promise of reasoning-driven memory consolidation as a scalable alternative to existing solutions for training long-horizon interactive agents, where both efficiency and performance are optimized." — Singapore-MIT

!image

1. MEM1 trains AI agents to keep only what matters—merging memory and reasoning at every step—so they never get overwhelmed, no matter how long the task.

2. Instead of piling up endless context, MEM1 compresses each interaction into a compact “internal state,” just like a smart note that gets updated, not recopied.

3. By blending memory and thinking into a single flow, MEM1 learns to remember only the essentials—making agents faster, sharper, and able to handle much longer conversations.

4. Everything the agent does is tagged and structured, so each action, question, or fact is clear and easy to audit—no more mystery meat memory.

5. With every cycle, old clutter is pruned and only the latest, most relevant insights are carried forward, mirroring how expert problem-solvers distill their notes.

6. MEM1 proves that recursive, protocol-driven memory—where you always refine and integrate—outperforms traditional “just add more context” approaches in both speed and accuracy.

Cognitive Tools

Eliciting Reasoning in Language Models with Cognitive Tools - IBM Zurich June 2025

Prompts and Prompt Programs as Reasoning Tool Calls


“Cognitive tools” encapsulate reasoning operations within the LLM itself — IBM Zurich

!image

These cognitive tools (structured prompt templates as tool calls) break down the problem by identifying the main concepts at hand, extracting relevant information in the question, and highlighting meaningful properties, theorems, and techniques that

might be helpful in solving the problem.

!image


These templates scaffold reasoning layers similar to cognitive mental shortcuts, commonly studied as "heuristics".

1. This research shows that breaking complex tasks into modular “cognitive tools” lets AI solve problems more thoughtfully—mirroring how expert humans reason step by step.

2. Instead of relying on a single, big prompt, the model calls specialized prompt templates, aka cognitive tools like “understand question,” “recall related,” “examine answer,” and “backtracking”—each handling a distinct mental operation.

3. Cognitive tools work like inner mental shortcuts: the AI picks the right program at each stage and runs it to plan its reasoning and downstream actions before conducting the task for greater accuracy and flexibility.

4. By compartmentalizing reasoning steps into modular blocks, these tools prevent confusion, reduce error, and make the model’s thought process transparent and auditable—even on hard math problems.

5. This modular approach upgrades both open and closed models—boosting real-world math problem-solving and approaching the performance of advanced RL-trained “reasoning” models, without extra training.

6. The results suggest that the seeds of powerful reasoning are already inside large language models—cognitive tools simply unlock and orchestrate these abilities, offering a transparent, efficient, and interpretable alternative to black-box tuning.

Emergent Symbols

Emergent Symbolic Mechanisms Support Abstract Reasoning in Large Language Models - ICML Princeton June 18, 2025


!image

TL;DR: A three-stage architecture is identified that supports abstract reasoning in LLMs via a set of emergent symbol-processing mechanisms.

>


These include symbolic induction heads, symbolic abstraction heads, and retrieval heads.

1. In early layers, symbol abstraction heads convert input tokens to abstract variables based on the relations between those tokens.

2. In intermediate layers, symbolic induction heads perform sequence induction over these abstract variables.

3. Finally, in later layers, retrieval heads predict the next token by retrieving the value associated with the predicted abstract variable.

These results point toward a resolution of the longstanding debate between symbolic and neural network approaches, suggesting that emergent reasoning in neural networks depends on the emergence of symbolic mechanisms. — ICML Princeton


!image


> Why Useful?

>

This supports why Markdown, Json, and similar structured, symbolic formats are more easily LLM parsable

> Concept: Collaborate with agents to apply delimiters, syntax, symbols, symbolic words, metaphors and structure to improve reasoning/context/memory/persistence during inference

1. This paper proves that large language models develop their own inner symbolic “logic circuits”—enabling them to reason with abstract variables, not just surface word patterns.

2. LLMs show a three-stage process: first abstracting symbols from input, then reasoning over these variables, and finally mapping the abstract answer back to real-world tokens.

3. These emergent mechanisms mean LLMs don’t just memorize—they actually create internal, flexible representations that let them generalize to new problems and analogies.

4. Attention heads in early layers act like “symbol extractors,” intermediate heads perform symbolic reasoning, and late heads retrieve the concrete answer—mirroring human-like abstraction and retrieval.

5. By running targeted experiments and interventions, the authors show these symbolic processes are both necessary and sufficient for abstract reasoning, across multiple models and tasks.

6. The results bridge the historic gap between symbolic AI and neural nets—showing that, at scale, neural networks can invent and use symbolic machinery, supporting real generalization and reasoning.

Star History

![Star History Chart](https://www.star-history.com/#davidkimai/Context-Engineering&Date)

Contributing

We welcome contributions! Check out CONTRIBUTING.md for guidelines.

License

MIT License

Citation

bibtex
@misc{context-engineering,
author = {Context Engineering Contributors},
title = {Context Engineering: Beyond Prompt Engineering},
year = {2025},
publisher = {GitHub},
url = {https://github.com/davidkimai/context-engineering}
}

Acknowledgements


I've been looking forward to this being conceptualized and formalized as there wasn't a prior established field. Prompt engineering receives quite the stigma and doesn't quite cover what most researchers and I do.

- Andrej Karpathy for coining "context engineering" and inspiring this repo
- All contributors and the open source community