What is prompt engineering for a coding agent?
By Flavio
Prompt engineering is writing the request on purpose, so an agent edits the right files. What Claude Code, Codex, Cursor and Grok Build tell you to include.
A prompt is what you send the model: the request, plus any file, error or image you attach to it. Prompt engineering means writing that request on purpose, so the answer is the change you asked for instead of a plausible guess.
What teaching can tell us about prompting is the post that owns the habit: state the behavior, and when the result is wrong, point at the case that failed. This entry is how Claude Code, Codex, Cursor and Grok Build tell you to shape the message.
How prompt engineering works
You say what should be true when the agent stops, what it must not change, and how you will know it worked. The agent already has tools to search the repo. A prompt that lists every file is usually worse than a prompt that names the outcome and the check.
Standing rules do not belong in the prompt every time. Put those in CLAUDE.md or AGENTS.md. A procedure you will reuse becomes an agent skill. The prompt is the task in front of you.
Claude Code’s prompt library and Codex’s prompting page use the same four ideas, with different labels. Claude’s page says to describe the outcome, give the agent a way to check itself, point at a reference in the repo, and paste the error or the log. Codex’s page says goal, context, output and boundaries, and for code it adds the verification step.
Prompt engineering in each tool
| Claude Code | Codex | Cursor | Grok Build | |
|---|---|---|---|---|
| What the docs tell you to include | Outcome, a check, a reference file, the error or log | Behavior, the code or the repro, constraints, how to verify | The request, plus @ files when you know them | A prompt, and @ before a path in the sample |
| Attach a file | @build.log in the prompt library | @ path autocomplete, or /mention in the CLI | @ for files, folders, terminals, chats, diffs, browser | @ before a path, in the overview samples |
| While it is working | A command sent mid-response is queued. A few, such as /status, run immediately | Enter steers the turn, Tab queues the next one | Enter queues, Cmd+Enter sends now | Enter queues by default |
| A prompting guide | Prompt library | Prompting | Prompting agents | Not documented. The overview has two sample prompts |
Claude Code
The prompt library’s patterns are the practical list. Describe the outcome and let Claude find the files. Ask it to run, test, compare or verify in the same prompt, so it does not stop after one attempt. Name an existing file or test to copy. Paste the error, or type @ and the path, so Claude reads the source instead of your summary of it.
/verify is the bundled skill for checking the change against the running app. For a larger or riskier change, plan mode shows the file list before edits. A prompt that worked becomes a skill, and a convention the project should always follow goes in CLAUDE.md. See the prompt library.
OpenAI Codex
For a larger task, Codex’s prompting page says to include the goal, the context, the output you want, and the boundaries. You do not have to fill in every part. For code, name the behavior, point at the code or the reproduction steps, keep the constraints, and say how to verify.
The IDE extension includes your open files. In the CLI, mention paths, or attach them with /mention and @. You can drag an image into the terminal or paste one in the IDE chat. While Codex is working, Enter steers the current turn and Tab queues the next message.
/plan asks Codex to investigate and propose an approach before editing. See Prompting.
Cursor
Type the request in the chat. @ attaches something you already know you need: a file or folder, terminal output, a past chat, the working diff, the branch diff, or the built-in browser. If you do not know which files matter, the page says to skip @ and let Agent search.
Images can be dropped in or pasted. The microphone dictates the prompt, and you review the transcription before you send it. / invokes a skill for one message. Option+Enter on a Mac, or Alt+Enter on Windows, keeps that skill in context for the session.
The context ring next to the input shows how full the window is, split into the system prompt, tools, rules, skills, MCP, subagents, the summarized conversation and the current one. A long rules file is in every prompt. See Prompting agents.
Grok Build
Grok Build’s docs index does not have a prompting guide. The overview’s sample prompts are short:
Explain this repo.
@src/main.rs Walk me through this file.
@ before a path is the documented way to point at a file. grok -p takes one prompt and runs it headlessly. While a turn is running, Enter queues the next prompt. That is the default. Set follow_up_behavior to steer under [ui] in config.toml, or Follow-up behavior in /settings, if Enter should steer instead. See the keyboard shortcuts. Modes such as /plan are covered in the plan mode entry. The product overview is Grok Build.
Details checked against each vendor’s documentation in November 2026.
A real example
A prompt you can send about the RSS feed. It has the outcome, the place to look, a boundary, and a check, which is what both the Claude library and the Codex page ask for:
Posts with an updated: field are missing from /rss.xml when nothing else changed.
Look in src/pages/rss.xml.ts. A post belongs in the feed when its date is in the past, whether or not updated: is set. Do not change how many items the feed keeps.
Run npm run build and paste the last lines of the output.
If the build fails, the next message should name the failure, the way the teaching post describes. “That’s wrong, try again” gives the agent nothing new. “The build stopped on a missing image in src/posts/rss-example.md” does.
When the same check should happen for every post, stop pasting it. Put the boundary in AGENTS.md or CLAUDE.md, or make it a skill you invoke with /.
When to use prompt engineering
Use the longer prompt when the task is easy to do wrong: a migration, a feed, a payment check, anything where a confident wrong edit is expensive. Codex’s page says a short prompt is enough for a small request. Claude’s library agrees that the outcome plus a check is the useful part, not a script of every step.
Skip the ceremony when you are exploring. “Explain how the RSS feed decides which posts to include” is a complete prompt. Add the boundary and the build command when you want files to change.
Plan mode replaces a long prompt when you do not yet know which files should change. You review the plan, then the agent edits.
Pitfalls
“Be concise” and “make it clean” are not checks. Claude Code’s memory docs say to write instructions concrete enough to verify. Less verbose coding agents shows that failure on a one-line style rule, and the same problem shows up in a one-off prompt.
A prompt that forgets the boundary gets a wider diff than you wanted. Codex’s page treats boundaries as the few instructions that prevent a result you cannot use. One or two is the recommendation there, not a page of policy. Policy that applies every time belongs in a rules file, where it is loaded even when you forget to type it.
@ is for files you know. Cursor’s page says that if you are unsure, skipping it lets Agent search. Attaching the whole repository duplicates work the agent was going to do, and it fills the context window.
Grok’s overview samples are not a full method. Copying @src/main.rs into a JavaScript repo does nothing useful. Point @ at a file that exists.
Related on flaviocopes.com
- What teaching can tell us about prompting is the longer version: a concrete case, then feedback that points at the mismatch.
- Prompts, rules and context shows a real prompt I gave a coding agent, and why each part is there.
- Less verbose coding agents shows why a vague style instruction is ignored, in the prompt and in
CLAUDE.md. - SEO Bot can open Cursor or Codex on a site’s source folder with the pages and the tasks from a report. The prompt is the report’s findings, aimed at files that exist, which is the shape this entry describes.
Related glossary entries
- Plan mode: Plan mode makes a coding agent research and propose a plan before it edits code. How it works in Claude Code, Codex, Cursor and Grok Build, and when to use it.
- 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 skills: An agent skill is a SKILL.md folder that teaches a coding agent one task. Where Claude Code, Codex, Cursor and Grok Build load it, and when to skip one.
- Context engineering: Context engineering is choosing what an agent sees before it edits. How Claude Code, Codex, Cursor and Grok Build load rules, files and skills.
Want me to talk about your product? You can sponsor this site.