agentleFS
chiruu12chiruu12/claude-skills-template/.claude/skills/context-engineering/SKILL.md

context-engineering

Skill0 starsChanged 7 months agoMITView on GitHub

Optimize AI agent context for maximum effectiveness using a 5-level hierarchy. Use when setting up a new project for AI-assisted development, when Claude keeps losing context, when responses are inconsistent across sessions, or when you want to reduce token waste. Also use when asked about "context", "rules files", or "how to set up Claude for this project".

146 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use accessibility-engineering, using-agent-skills and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • steven123397Skill

    accessibility-engineering

    Audits existing interfaces for WCAG 2.2 AA conformance and remediates the violations found. Use when auditing a page or component for accessibility, running axe-core or pa11y, triaging a11y violations, or checking screen reader and contrast issues before shipping.

    Also in 4 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 42 projects that use this

  • LLl0k0laDSkill

    idea-refine

    Refine ideas through structured divergent and convergent thinking. Use "idea-refine" or "ideate" to trigger.

    Also in 48 projects that use this

  • HK-hubSkill

    source-driven-development

    Grounds every implementation decision in official documentation. Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters.

    Also in 49 projects that use this

  • jaydubya818Skill

    deprecation-and-migration

    Retire APIs or migrate consumers and persistent data across releases.

    Also in 45 projects that use this

  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 18 projects that use this

  • +5 more from LLl0k0laD

The file

We split this skill into the rules it gives an agent

10 rules. 0 are common, 9 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 132 edited versions we read keep these.

  • 9

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    NOT: when debugging a specific bug — use triage-issue instead

    line 21
  2. Distinctive:

    Check what context already exists in the project:

    line 28
  3. Distinctive:

    Keep these concise — every token here is loaded on every request.

    line 55
  4. Distinctive:

    Keep Level 1 rules under 2000 words total

    line 71
  5. Distinctive:

    Use progressive disclosure — summary in CLAUDE.md, details in linked files

    line 72
  6. Distinctive:

    Remove stale context — outdated rules cause confusion, not just waste

    line 73
  7. Distinctive:

    Test that the context is working by asking Claude to perform a common task without any additional explanation.

    line 77
  8. Distinctive:

    No Level 2 specs for active features — Claude fills gaps with assumptions

    line 93
  9. Distinctive:

    DO NOT: put everything in CLAUDE.md — use progressive disclosure across all 5 levels

    line 106
  10. Distinctive:

    DO NOT: write rules about things that are obvious from the code — only non-obvious constraints

    line 107

“Common” is measured: kept by at least 6 in 10 of the 132 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Context Engineering

Structure project context so AI agents produce consistent, high-quality results without re-explanation every session. The 5-level hierarchy ensures the right information is available at the right time — always-loaded rules at the top, conversation-specific details at the bottom.

When to Use

  • Setting up a new project for AI-assisted development
  • Claude keeps forgetting conventions or making the same mistakes
  • Responses are inconsistent across sessions or workspaces
  • Token usage is high because you're re-explaining context every time
  • NOT when debugging a specific bug — use triage-issue instead
  • NOT for one-off tasks that won't repeat — just explain in the conversation

Process

1. Audit existing context

Check what context already exists in the project:

# Check for existing context files
ls -la CLAUDE.md .claude/settings.json .claude/rules/ 2>/dev/null
find . -name "CONTEXT.md" -o -name "*.rules.md" 2>/dev/null

2. Apply the 5-level hierarchy

LevelWhatWhen LoadedExamples
1. Rules filesNon-negotiable constraintsAlways (every request)CLAUDE.md, .claude/rules/*.md
2. Specs/PlansCurrent feature contextWhen referencedPRDs, design docs, plan files
3. Source codeImplementation realityWhen files are readThe actual codebase
4. Error outputRuntime feedbackDuring debuggingTest failures, stack traces, lint errors
5. ConversationSession-specific contextCurrent session onlyUser messages, clarifications

3. Write Level 1 — Rules files

CLAUDE.md and .claude/rules/ are always in context. They should contain:

  • Architecture decisions — "Routes → Services → CRUD → Models"
  • Conventions — naming, file structure, import patterns
  • Boundaries — "never import from X in Y", "always use Z for database access"
  • Tool commands — how to run tests, lint, build

Keep these concise — every token here is loaded on every request.

4. Write Level 2 — Specs and plans

For active features, create spec files that capture:

  • What the feature does (user perspective)
  • Key decisions already made (so Claude doesn't re-litigate)
  • Acceptance criteria
  • Out of scope

Link from CLAUDE.md: "For feature X, see docs/specs/feature-x.md"

5. Optimize for token efficiency

  • Move detailed reference material to files Claude reads on-demand (Level 3)
  • Keep Level 1 rules under 2000 words total
  • Use progressive disclosure — summary in CLAUDE.md, details in linked files
  • Remove stale context — outdated rules cause confusion, not just waste

6. Verify context effectiveness

Test that the context is working by asking Claude to perform a common task without any additional explanation. If it follows conventions correctly, the context is sufficient.

Common Rationalizations

ShortcutWhy It Fails
"I'll just explain things in the conversation each time"Conversation context is ephemeral. You're paying tokens every session to re-teach what should be in Level 1. It also drifts — you'll explain differently each time.
"I'll put everything in CLAUDE.md so it's always available"CLAUDE.md is loaded on EVERY request. A 5000-word CLAUDE.md burns tokens even for simple questions. Use progressive disclosure — summary at Level 1, details at Level 3.
"The code is self-documenting, no rules needed"Code shows WHAT exists, not WHY it's that way or WHAT to do next time. Without explicit rules, Claude will infer conventions from whatever code it reads first — which may be the exception, not the rule.
"I'll add context as issues come up"Reactive context accumulates as patches. Every 2-3 months, audit and restructure. Proactive context engineering prevents the drift in the first place.

Red Flags

  • CLAUDE.md over 3000 words — too much always-loaded context, burning tokens on every request
  • Rules contradict each other — Claude will follow whichever it sees last, which is non-deterministic
  • Stale rules reference deleted files or patterns — causes confusion and hallucination
  • No Level 2 specs for active features — Claude fills gaps with assumptions

Verification Checklist

  • CLAUDE.md under 2000 words and contains only non-negotiable constraints
  • .claude/rules/ files cover common workflows without being overly prescriptive
  • Active features have Level 2 spec files linked from CLAUDE.md
  • Claude follows project conventions without re-explanation on a fresh session
  • No contradictions between rules files
  • Stale context removed (no references to deleted files/patterns)

Anti-patterns

  • DO NOT put everything in CLAUDE.md — use progressive disclosure across all 5 levels
  • DO NOT write rules about things that are obvious from the code — only non-obvious constraints
  • DO NOT reference specific file paths in rules (they go stale) — describe patterns and conventions instead
  • DO NOT skip the audit step — existing context may contradict what you're about to add

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.