agentsclimarketplace

ContextEngineering

Skill mj-deving/pai-skills/skills/Thinking/ContextEngineering

Curated, sanitized export of 21 agent-skill packages for Claude Code and Codex, gated by an automated publication audit (no secrets, no local paths).

Install
npx -y skills add mj-deving/pai-skills --skill ContextEngineering

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Strategic context management for AI agents — 5-level hierarchy, starvation/flooding diagnosis, brain dump structuring, confusion surfacing. USE WHEN context management, context strategy, too much context, too little context, context window, context budget, brain dump, session context, what context to load, context starvation, context flooding, agent context, prompt engineering context.

SKILL.md

5.5 KB, ~1.2k tokens by cl100k_base, as published. Nobody here has run it

ContextEngineering

Strategic structuring of information fed to AI agents. Too little context and the agent hallucinates. Too much and it loses focus. This skill teaches how to find the balance.

Customization

Before executing, check for user customizations at: ${PAI_USER_DIR}/SKILLCUSTOMIZATIONS/ContextEngineering/

<!-- ## Voice Notification ```bash curl -s -X POST http://localhost:8888/notify \ -H "Content-Type: application/json" \ -d '{"message": "Running WORKFLOWNAME in ContextEngineering to ACTION"}' \ > /dev/null 2>&1 & ``` -->

Workflow Routing

WorkflowTriggerFile
StructureContext"structure context", "brain dump", "session setup", "what context to load"Workflows/StructureContext.md
DiagnoseContext"context problem", "agent confused", "hallucinating", "losing focus", "context starvation", "context flooding"Workflows/DiagnoseContext.md

The 5-Level Context Hierarchy

From most persistent to most transient:

LevelWhatToken BudgetLifespanExample
L1 — RulesCLAUDE.md, steering rules, constitution~200-400PermanentProject conventions, behavioral constraints
L2 — SpecsFeature specs, requirements, design docs~500-1500Per-projectSPEC.md, PRD.md, ADRs
L3 — SourceCode files being modified + relevant examples~1000-3000Per-taskThe files you're actually editing
L4 — ErrorsTest failures, build errors, runtime logs~200-500Per-attemptStack traces, failing assertions
L5 — ConversationChat history, prior turns, accumulated reasoningGrows unboundedPer-sessionPrevious questions and answers

Key insight: L1-L2 are compressed and stable. L3-L4 are focused and relevant. L5 grows without bound and is the primary cause of context degradation.

The 2,000-Line Threshold

Research and practice show agent performance degrades beyond ~2,000 lines of active context per task. When you approach this:

  • Compacted: Summarize L5 (conversation history) to key decisions and open questions
  • Selective: Load only L3 source files directly relevant to current task
  • Defer: Don't load reference docs "just in case" — load when a workflow needs them

Anti-Patterns

Context Starvation (too little)

Symptoms: Agent invents APIs that don't exist, uses wrong function signatures, ignores project conventions, hallucinates file paths.

Diagnosis: Missing L1 (no CLAUDE.md) or L3 (didn't read the relevant code before modifying).

Fix: Ensure CLAUDE.md exists with conventions. Read the file before editing. Load relevant types/interfaces.

Context Flooding (too much)

Symptoms: Agent loses focus, contradicts earlier reasoning, forgets task objectives, produces generic output, ignores specific instructions buried in noise.

Diagnosis: L5 (conversation) has grown past useful length, or too many L3 files loaded at once.

Fix: Summarize conversation at natural breakpoints. Load only files relevant to current sub-task, not entire codebase.

Context Pollution

Symptoms: Agent follows patterns from wrong project, mixes conventions, applies advice from unrelated context.

Diagnosis: L2 specs from different projects loaded simultaneously, or stale L5 history from a previous task.

Fix: Clear context between projects. Use /clear between unrelated tasks. Keep CLAUDE.md per-project, not global.

Core Principles

  • A well-structured 10-minute rules file prevents hours of correction cycles
  • Every piece of context has a cost — token budget, attention dilution, confusion risk
  • Implicit knowledge doesn't exist — if it's not in context, the agent doesn't know it
  • Surface confusion explicitly — "I'm assuming X; correct me now" is better than silent wrong assumptions

Examples

Example 1: Starting a complex task

User: "Refactor the auth module — here's what I know: [brain dump]"
→ Invokes StructureContext workflow
→ Organizes brain dump into task context (objective, stack, constraints, files, gotchas)
→ Identifies L3 source files to load before starting

Example 2: Agent producing bad output

User: "The agent keeps inventing functions that don't exist"
→ Invokes DiagnoseContext workflow
→ Diagnoses: L3 starvation — agent didn't read source files
→ Fix: Read the relevant types/interfaces before continuing

Example 3: Session getting unfocused

User: "We've been going back and forth and losing track"
→ Invokes DiagnoseContext workflow
→ Diagnoses: L5 flooding — conversation history too long
→ Fix: Summarize key decisions, /clear, restart with fresh context

Integration

Works with:

  • CLAUDE.md composition standard — how to write L1 rules files
  • CONTEXT_ROUTING.md — lookup table for finding the right context
  • DocsList — explicit L2 documentation index when a task needs a project docs map
  • context-search — finding relevant prior work
  • Algorithm OBSERVE — assumption surfacing step

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.