Guide / Codex workflow

How Codex instructions and context files actually work

Better Codex output usually comes from better repo structure, not longer prompting. The uploaded cheat sheet is strongest when you turn it into four practical questions: which Codex surface are you using, where do instructions belong, what gets loaded on demand, and what actually has priority.

V Vanderburgh.it CODEX CONTEXT AT A GLANCE

Four ideas: surface, instructions, context loading, and priority.

Surface

CLI, IDE, cloud, or ChatGPT

UsePick the right runtime for the job StrengthBetter fit, less friction Watch-outContext differs by surface

Codex is not one identical experience everywhere.

Instructions

`AGENTS.md` is the repo contract

UseRules, workflow, standards StrengthClear local behavior Watch-outDo not bury rules in docs

Put behavior in instruction files and knowledge in docs.

Loading

Context is read when it becomes relevant

UseFocused retrieval during the task StrengthLess noise, more signal Watch-outMessy repos slow the model down

Clean file structure beats giant context dumps.

Priority

The current task still leads

UsePrompt, task, repo, then docs StrengthPredictable steering Watch-outConflicting rules create drift

Keep the instruction stack explicit and narrow.

Core file `AGENTS.md`

Use it for behavior, coding rules, testing expectations, branching norms, and project-specific operating guidance.

Reference docs README and friends

Keep architecture, API, roadmap, and deeper docs as reference material, not as hidden instruction layers trying to steer every action.

Operating rule Context priority

The current task wins first, then task instructions, then scoped rules, then repo and documentation context that Codex can load on demand.

Surface model

Codex behaves differently depending on where you run it

The uploaded sheet gets one thing right immediately: local CLI, IDE extension, cloud tasks, and ChatGPT Codex are related surfaces, not one identical product. The runtime changes the available context, the level of control, and the kind of work each surface suits best.

01

Codex CLI

Local terminal

Reads your local repo, local `AGENTS.md`, and terminal state. Best when you want direct development, debugging, scripts, and full local control.

Strongest for hands-on repo work.
02

IDE extension

Workspace-aware daily flow

Still uses repo-local instructions, but adds editor context and workspace state. Best for everyday development inside VS Code, Cursor, or JetBrains.

Strongest for keep-coding-without-leaving-the-IDE work.
03

Cloud tasks

Async and parallel

Works from a GitHub repository plus task instructions, and is built for longer-running, parallel, or delegated jobs rather than one interactive shell session.

Strongest for background execution and multi-task fanout.
04

ChatGPT Codex

High-level orchestration

Combines chat instructions with uploaded or connected project context. Best for planning, review, broad orchestration, and lighter-touch code collaboration.

Strongest for guidance, review, and structured collaboration.

Instruction layers

Where instructions should actually live

The source document effectively describes a ladder. Put durable defaults at the top, repo rules in the repository, narrower overrides near the code, and truly temporary guidance only with the task that needs it.

  1. Layer 1 Global defaults

    Use global settings for personal preferences and recurring habits you want across projects. Do not hide project-specific rules here.

  2. Layer 2 Repository root

    The repo-root `AGENTS.md` is the main project contract for behavior, coding standards, testing, and workflow expectations.

  3. Layer 3 Scoped folders

    Use nested `AGENTS.md` files only when a subtree genuinely needs different constraints or conventions than the rest of the repository.

  4. Layer 4 Task instructions

    Session or cloud-task instructions should hold the temporary goal for this run, not the permanent project rules that belong in version control.

Context loading

Codex does not preload everything in your repository

One of the best takeaways from the uploaded sheet is operational: Codex loads what is relevant when it becomes relevant. That makes focused docs and well-placed instructions more valuable than stuffing every rule into one oversized file.

01

Startup

At the start, Codex picks up the root and scoped instruction layers, repo metadata, branch state, and current working files.

02

During the task

As work narrows, it opens the README, architecture notes, source files, tests, config, and other relevant docs on demand.

03

User prompt

Your current prompt has the highest immediate influence, unless it conflicts with a harder system or project rule.

Priority order

What usually outranks what

The exact internal stack depends on the surface, but the useful rule is simple: direct user intent first, then explicit task framing, then local instruction files, then repo context and documentation, with outside knowledge last.

01

Current prompt

Immediate intent

The active request is the sharpest statement of what should happen right now.

Start with the task in front of you.
02

Task instructions

Mission frame

Session prompts, automation instructions, or cloud-task fields define the current mission more narrowly than repo docs do.

These shape the current run.
03

`AGENTS.md`

Repo rulebook

Scoped rules beat broad rules, and repo-local behavior belongs here rather than buried inside general Markdown prose.

This is the operational contract.
04

Repo files and docs

Supporting context

Source, config, tests, architecture notes, git history, and external references support the answer after the instruction stack is clear.

Useful context, but not the first steering layer.

Reference docs versus instructions

README, architecture, API, roadmap, and docs are context, not steering wheels

This is where many repos get messy. Teams often use `README.md`, `ARCHITECTURE.md`, `API.md`, `ROADMAP.md`, and deep docs as if they were instruction files. That makes them stale faster and creates mixed signals about what is mandatory versus what is merely useful reference.

The stronger pattern is simple: put behavior rules in `AGENTS.md`, then keep the reference Markdown files clean, current, and easy to read on demand.

Practical split

Use `AGENTS.md` for standards, constraints, and workflow rules. Use the rest of the Markdown surface for orientation, system design, contracts, milestones, and deeper supporting detail.

Best practices

What to change in a real repository after reading this

01

Keep `AGENTS.md` tight

Make it short, concrete, and enforceable. Link out to deeper docs instead of turning it into a handbook nobody will maintain.

02

Scope only when needed

Add nested instruction files only when a folder truly has different constraints, not just because the repo is large.

03

Structure for retrieval

Use readable filenames, current docs, useful tests, and repo-local notes that Codex can open quickly when the task moves there.

Common failure mode

Most Codex problems are context problems before they are model problems

The strongest idea in the source image is simple: better context produces better results. In practice, weak output often comes from conflicting repo rules, stale docs, giant instruction dumps, or huge mixed-change tasks that make the real goal harder to isolate.

Watch-outs

Avoid oversized `AGENTS.md` files, conflicting scoped rules, stale documentation, giant unrelated change sets, and the habit of skipping tests while still trusting the output too quickly.

The short version

Design the repo so Codex can find the right truth fast

The extracted lesson from the uploaded sheet is not “write a bigger prompt.” It is “choose the right Codex surface, keep `AGENTS.md` as the behavioral contract, keep docs as clean reference, and structure the repo so the right context can be loaded without collisions.”