What is context engineering? Claude Code, Codex, Cursor, Grok

By

Context engineering is choosing what an agent sees before it edits. How Claude Code, Codex, Cursor and Grok Build load rules, files and skills.

Context engineering is choosing what goes into the context window so the model has what it needs and nothing else. None of these tools ship a mode by that name. The work is how you fill the context window on purpose.

How context engineering works

Before you type, the tool has already loaded instruction files, tool names and short descriptions of skills. That text is in the window on every later turn. A long file here costs tokens even when the task does not need it.

While you work, file reads, rules that match a path, and hook output join the same window. A subagent can keep a large read in its own window and send back a summary. Compaction then throws part of the history away and keeps a smaller stand-in.

The useful habit is to decide the three layers before a long task. What is always loaded. What you attach for this task. What you keep out.

Three layers of contextInstruction files and skill descriptions load before you type. You then attach the files for this task. Compaction keeps a summary and reloads the root instructions. Path-scoped rules can be summarized away.Always loaded: rulesand skill namesThis task: files youattach or the agentreadsKept out: secrets,lockfiles, old logsCompaction keeps asummary

Agent memory is one of the things that can load before you type. A committed rule is the piece you can review. A generated memory is not.

Context engineering in each tool

The controls are instruction files, ignore files, mentions and compaction. The names differ. No vendor documents a switch called context engineering.

Claude Code Codex Cursor Grok Build
Always loaded CLAUDE.md or AGENTS.md, auto memory, MCP tool names, skill descriptions AGENTS.md for required guidance. Memories only if you enable them Rules, plus what you @ mention AGENTS.md, CLAUDE.md, and every *.md in .grok/rules/
See what loaded /context Not documented on the memories page Not documented grok inspect, /context, /session-info
Shrink the chat /compact, /clear, auto-compact Not restated here. See the context window entry Not documented as a default compaction point /compact, and auto-compact
Keep a file out Do not put it in CLAUDE.md. Path-scoped rules load only when a matching file is touched Put required rules in AGENTS.md, not only in memories .cursorignore, on top of .gitignore .gitignore skips rules files. A skill paths list hides that skill until a match

Claude Code

Before you type, Claude Code loads CLAUDE.md, or AGENTS.md in its place, plus auto memory, MCP tool names and skill descriptions. An output style, or text from --append-system-prompt, can add more.

/context shows a live breakdown, including which CLAUDE.md and auto memory files loaded. /memory opens those files. /clear drops the conversation when the next task is unrelated. /compact replaces the conversation with a structured summary. /compact focus on the auth bug fix tells that summary what to keep. Auto-compact runs as you approach the window limit, in the same way as /compact.

After /compact, the project-root CLAUDE.md and unscoped rules are read from disk again. Path-scoped rules and nested CLAUDE.md files are summarized away with the rest of the history, because they were loaded when Claude touched a matching file. If a rule has to survive compaction, drop its paths: frontmatter or move it to the root CLAUDE.md. Nested files load again later, on demand, when a matching file is touched.

Skill descriptions are part of what loads up front. The full skill body loads when the skill is used. A plugin that adds many skills adds their descriptions to every turn. See the context window guide.

OpenAI Codex

Codex does not document a feature named context engineering. It reads AGENTS.md before it does work. Instructions from the repo root down to the current directory are concatenated, and Codex stops adding files once the combined size reaches project_doc_max_bytes, 32 KiB by default. A long file can drop the paragraphs at the end.

The memories page says to keep required team guidance in AGENTS.md, and to treat memories as optional recall. Memories are off until you enable them. This entry does not restate Codex compaction. The context window entry covers the commands documented there. See AGENTS.md and Memories.

Cursor

Type @ to attach context. @auth.ts or @src/components/ includes a file or a folder. @Terminals includes terminal output. @Chats includes an earlier conversation. @Commit (Diff of Working State) is the uncommitted diff. @Branch (Diff with Main) is the branch diff. @Browser attaches the built-in browser. You can mention several items. If you do not know which files matter, skip @ and let Agent search.

.cursorignore in the project root adds exclusions. Cursor already ignores .env files, .git/ and lockfiles, and it respects .gitignore. Ignored files are blocked from Agent. Terminal commands and MCP tools run outside those file controls, so they can still read an ignored file.

Rules are the committed layer. The field names are in the rules entry. See @ mentions and ignore files.

Grok Build

Grok loads AGENTS.md, Agents.md, AGENT.md, CLAUDE.md, Claude.md and CLAUDE.local.md, plus every *.md file in .grok/rules/. .claude/rules/ and .cursor/rules/ are read for compatibility. Files ignored by .gitignore are skipped, which keeps CLAUDE.local.md out when that file is gitignored. Deeper files win on a conflict. Files load in full, with no size cap. Short specific instructions are followed more reliably than long ones.

grok inspect lists each rules file with its path and an approximate token count. grok --rules appends text for one run. --system-prompt-override replaces the system prompt.

/compact takes optional instructions about what to preserve. Grok also auto-compacts as the window fills. /context or /session-info shows usage.

A skill with a paths list stays hidden until a matching file is touched. That is a way to keep a skill description out of context until the task reaches those files. See Project rules and Sessions.

Details checked against each vendor’s documentation in November 2026.

A real example

This is a root instruction file for one task on this site. It names the files to read, the test to run, and a directory to leave alone. In Claude Code it belongs in CLAUDE.md. In Codex or Grok Build the same paragraphs belong in AGENTS.md. Grok also reads CLAUDE.md.

Read src/pages/ai-glossary/[slug].astro before editing a glossary page.

Tests for glossary entries are in src/data/ai-glossary.test.ts.
Run: node --test src/data/ai-glossary.test.ts

Do not edit src/course-content.

Check what that file costs before you add to it. In Claude Code, run /context and look under Memory files. In Grok Build, run grok inspect and read the token count next to the rules file.

In Cursor, for one task, mention the file instead of pasting the repo into the chat:

@src/pages/ai-glossary/[slug].astro
@src/data/ai-glossary.test.ts

When to use context engineering

Use it when a session is about to edit, and you can name the files and the rule that matter. A short root file plus one or two @ mentions beats a CLAUDE.md that restates the whole repository.

Use /clear or a new session when the next task does not need the old logs. Use /compact with a focus sentence when the investigation is long and the next edit still depends on it.

Use path-scoped rules, or a Grok skill paths list, when an instruction only matters for one directory. A root file is for the rules every task needs.

Skip the extra file when the default instructions are already short and the task is one command. Adding a page of reminders to every turn is how the window fills before the work starts.

Pitfalls

Claude Code path-scoped rules feel permanent and then vanish at /compact, because they were part of the message history. The root CLAUDE.md comes back. The nested file comes back only when a matching path is touched again. A rule you need after compaction has to live at the root, or without paths:.

Skill descriptions load even when you never invoke the skill. A marketplace plugin can add a tax to every message. The Claude Code install panel shows that cost for official marketplace plugins, as an every-turn estimate, before you install.

.cursorignore does not bind the terminal or MCP tools. A secret in .env is blocked from Agent file reads and can still appear in a command the agent runs. Do not treat the ignore file as a vault.

Grok loads rules files in full and documents no size cap. A long AGENTS.md is not truncated for you. grok inspect is how you see the token count before a session spends it.

Codex will not apply a team rule that exists only as a memory. Memories are off by default, they stay on one machine, and the docs tell you to put required guidance in AGENTS.md.

  • Prompt caching for coding agents is what happens to cost when the prefix changes, including after compaction.
  • AGENTS.md is the file most of these tools already load. Keep it short enough that the rest of the window is free for the task.
  • How to document project decisions is the note you want in that file when the reason for a choice would otherwise die with the chat.
  • Skill Cabinet lists the skill descriptions sitting on your machine. Those descriptions are what Claude Code loads on every turn, before you invoke the skill.
  • Context window: The context window is everything a coding agent can see at once. How to check it, free it and keep it small in Claude Code, Codex, Cursor and Grok Build.
  • Rules: Project rules are durable instructions a coding agent loads for a repo. How they work in Cursor, Claude Code, Codex and Grok Build, and when to skip them.
  • Agent memory: Agent memory is notes a coding agent keeps between sessions. How Claude Code, Codex and Grok Build store them, and what Cursor documents instead.

All AI glossary entries →

Want me to talk about your product? You can sponsor this site.