Skip to main content

Your buyers are asking AI. Are you the answer?

Find out with OptimizeCamp →
Back to Blog
Claude CodeAI coding agentpromptingCLAUDE.mdMCPdeveloper toolsagentic AI

Claude Code Prompting Guide (2026)

How to prompt Claude Code on Claude Opus 5.5 and Sonnet 5.5 — CLAUDE.md hierarchy, .claude/rules/*.md, Skills, Lifecycle Hooks, Subagents, and MCP.

April 20, 2026
Updated December 1, 2026
11 min read

TL;DR

Claude Code rewards work-order prompts backed by its full late-2026 customization stack: the CLAUDE.md hierarchy, path-scoped .claude/rules/*.md, on-demand Skills (SKILL.md), deterministic Lifecycle Hooks, custom Subagents (.claude/agents/*.md), and MCP servers on Claude Opus 5.5, Sonnet 5.5, and Haiku 5.5.

Prompting Claude Code well looks less like chatting and more like issuing a crisp engineering work order. As documented in the Claude Code overview, Anthropic's coding agent operates directly inside your repository across terminal, desktop, IDE, and web surfaces — running shell commands, editing files, executing deterministic hooks, calling MCP servers, and delegating to custom subagents. Backed by Claude Opus 5.5 as the default flagship for agentic coding alongside Sonnet 5.5, Haiku 5.5, and Fable 5.2, the payoff for structured prompting is immediate: fewer wasted turns, fewer wrong-file edits, and verified diffs instead of wishful "should work now" summaries.

What Claude Code Is (December 2026)

Claude Code runs inside your working directory with native tools (Bash, Read, Edit, Write, Grep, Glob) governed by an explicit permission model — allowlisting safe verification commands, requiring confirmation on risky mutations, and blocking destructive operations outright.

On the model side, Claude Code runs across Anthropic's Claude 5.x family, all with a 1M-token context window:

  • Claude Opus 5.5 ($4/$20 per 1M API tokens) — default flagship for complex multi-file coding, architecture, and autonomous loops.
  • Claude Sonnet 5.5 ($2/$10) — fast everyday balance for routine edits, test writing, and mid-size subagent runs.
  • Claude Haiku 5.5 ($0.10/$0.50 up to 100K) — ultra-fast, low-cost tier ideal for read-only codebase exploration subagents and quick checks.
  • Claude Fable 5.2 ($8/$40) — heavy reasoning tier for gnarly debugging, formal specifications, or difficult architectural tradeoffs.

Because stable session prefixes (CLAUDE.md, active rules, tool schemas, and earlier conversation turns) benefit heavily from Anthropic's prompt caching, keeping static instructions stable in config files and putting variable instructions at the end of your prompt improves both latency and token efficiency across multi-step runs.

For broader context, see the pillar: The Complete Guide to Prompting AI Coding Agents. For the category definition, see agentic AI.

How Prompting Claude Code Differs From ChatGPT or Claude.ai Chat

A chat model returns a helpful next message. Claude Code executes a closed loop of reads, edits, shell verifications, and hook checks until verifiable acceptance criteria pass.

DimensionClaude.ai / ChatGPT chatClaude Code
InteractionSingle-turn conversationMulti-step autonomous run
FilesYou paste snippetsReads, searches, edits, and writes directly
Tools & guardrailsMinimal or manualBash, Read, Edit, Write, Grep, Glob + Lifecycle Hooks + MCP
VerificationYou check answers manuallyRuns typecheck, lint, and tests directly
Success criteria"A clear explanation""Tests pass, scope respected, clean diff"
Typical failureVague or generic answerTouches wrong files, loops, invents helpers
What fixes itRephrase the questionTighten scope, add rules/hooks, add a stop condition

A conversational nudge like "Refactor this to be cleaner" gives Claude Code no edge — it wanders across adjacent modules and may skip verification. Writing the request as a work order — goal, scope, context files, acceptance criteria, stop condition — converges cleanly. See spec-driven AI coding for the underlying discipline.

The CLAUDE.md Hierarchy and .claude/rules/*.md

Persistent project memory is where most prompting quality is won. As detailed in the Claude Code memory documentation, Claude Code loads instructions across a layered hierarchy alongside path-scoped rule files:

  • Managed Policy — enterprise-managed system-level instructions enforced organization-wide (security policy, approved registries, compliance rules).
  • Project root (./CLAUDE.md) — team-shared repository instructions checked into git (tech stack, test/lint commands, architecture boundaries, default no-touch paths).
  • User global (~/.claude/CLAUDE.md) — your personal preferences across every repo (communication brevity, commit style, local tooling).
  • Project local (./CLAUDE.local.md) — gitignored personal overrides for a single repository (local ports, personal sandbox URLs, scratch conventions).
  • Path-scoped rules (.claude/rules/*.md) — modular Markdown rules scoped to matching file globs or paths (plus subdirectory CLAUDE.md files loaded on demand when working inside that folder).

Keep ./CLAUDE.md lean and scannable; move path-specific rules into .claude/rules/*.md so database migration constraints only load when touching prisma/, and React component norms only load when touching src/components/.

A practical project ./CLAUDE.md:

markdown
# Project: Acme Billing Service

## Stack
- TypeScript (strict), Node 22, Next.js 16 (App Router)
- PostgreSQL via Prisma
- Commands: `pnpm test` (Vitest), `pnpm typecheck`, `pnpm lint`

## Conventions
- Functional components only; avoid in-place mutation.
- Keep files under ~400 lines and functions under ~50 lines.
- Validate all external payloads with Zod at system boundaries.

## Directory boundaries
- `src/app/` — App Router routes; default to Server Components.
- `src/lib/` — pure utilities; zero network calls.
- `src/server/` — server-only logic; never import into client components.
- `prisma/migrations/` — never hand-edit; generate via `pnpm prisma migrate dev`.

## Verification
Before claiming completion, run `pnpm typecheck && pnpm test && pnpm lint`
and include exact command outputs in your final summary.

## Out of scope by default
- Do not edit `prisma/schema.prisma` unless explicitly requested.
- Do not install new dependencies without confirmation.
- Never commit or push directly to `main`.

This is a template, not a rigid standard — trim every line that does not actually prevent mistakes in your repo. For more on persistent context vs. per-task prompts, see the tool use glossary entry.

For rules every coding agent in the repo should share — not just Claude Code — maintain a cross-tool AGENTS.md file alongside or referenced from CLAUDE.md.

On-Demand Skills (SKILL.md) and Slash Commands

Whenever a section of CLAUDE.md grows from a short fact into a multi-step playbook — such as scaffolding an API endpoint, cutting a release changelog, running a security review, or writing a database migration — move it into an on-demand Claude Code Skill (SKILL.md).

Skills pair naturally with slash commands and solve context bloat: Claude Code sees only each Skill's compact name and description up front, then loads the full SKILL.md instructions (and optional helper scripts or reference docs) only when the task matches or when you invoke it explicitly via /skill-name. That keeps everyday sessions sharp and prompt caches steady while packaging repeatable team workflows into version-controlled directories. See our Claude Skills guide for authoring patterns; if you prefer ready-made templates, our sister site AgentsCamp maintains a format-validated library of drop-in slash commands, sub-agents, and skills for Claude Code.

Deterministic Lifecycle Hooks

Prompt instructions in CLAUDE.md are strong guidance, but they remain probabilistic. Claude Code Lifecycle Hooks give you deterministic enforcement by running your own shell scripts or validators automatically at exact lifecycle events:

  • SessionStart — inject fresh environment state, active git branch context, or project diagnostics when a session boots.
  • UserPromptSubmit — validate or enrich incoming prompts before the model processes them (for example, warning on missing ticket IDs or scrubbing accidental secrets).
  • PreToolUse — inspect and allow, modify, or block tool calls before execution (blocking writes to .env, prisma/migrations/, or forbidden Bash patterns).
  • PostToolUse — run automatic actions immediately after an edit or tool finishes (running Prettier/Biome, ESLint on the modified file, or quick targeted typechecks).
  • Stop — execute final verification gates before Claude finishes a turn or exits.

Use CLAUDE.md for engineering judgment and conventions; use Hooks whenever a rule must hold 100% of the time without relying on model compliance.

MCP Servers — Extending Tool Access

Claude Code integrates natively with MCP (Model Context Protocol) servers, giving the agent structured access to external systems — Postgres schemas, GitHub PRs, Linear or Jira tickets, Sentry traces, internal APIs, and documentation indices — right alongside its built-in file and shell tools. Configure servers at project or user scope, apply least-privilege read-only credentials where possible, and name the exact MCP tools you expect Claude Code to call inside your work-order prompt.

Custom Subagents (.claude/agents/*.md)

Beyond ad-hoc delegation, Claude Code Subagents let you define specialized, reusable agents in .claude/agents/*.md (or ~/.claude/agents/*.md) with custom system prompts, restricted tool lists, and per-agent model overrides.

Custom subagents pay for themselves in three clear scenarios:

  • Parallel workstreams. Auditing five independent modules or updating disjoint packages simultaneously without serial waits.
  • Context isolation. Dispatching a read-only codebase researcher so twenty file reads never crowd the parent session's working context.
  • Role and model specialization. Routing read-only exploration or log triage subagents to Claude Haiku 5.5 ($0.10/$0.50 up to 100K) or Sonnet 5.5 ($2/$10) while keeping Claude Opus 5.5 ($4/$20) on the coordinating architect/implementer — matching the patterns in the multi-agent prompting guide.

Skip subagents for small single-file tasks where coordination overhead outweighs context savings.

A Work-Order Prompt You Can Copy

text
GOAL
  Add a retry loop to `request()` in `lib/api/client.ts` so transient
  upstream failures do not bubble straight to callers.

SCOPE
  - Edit only `lib/api/client.ts` and `lib/api/client.test.ts`.
  - Do not change the exported signature of `request()`.
  - Do not touch any other files.

CONTEXT
  Read these first:
  - lib/api/client.ts       (target function)
  - lib/api/client.test.ts  (existing test style)
  - lib/api/errors.ts       (error classes to preserve)

BEHAVIOR
  - Retry on network errors and 5xx responses only.
  - Max 3 attempts with exponential backoff: 100ms, 200ms, 400ms.
  - Surface 4xx responses immediately without retrying.

ACCEPTANCE
  1. `pnpm test lib/api/client.test.ts` — all tests pass.
  2. New tests cover: retry-on-5xx, no-retry-on-4xx, and max-attempt exhaustion.
  3. `pnpm typecheck` — zero errors.
  4. `git diff --name-only` — only the two files listed in SCOPE appear.
  5. Stop once all four conditions pass.

CLOSING STEP
  Print the diff summary, paste exact command outputs, list any assumptions,
  and stop without committing.

Every section closes an ambiguity Claude Code would otherwise guess at. For sibling tools, see the Cursor AI prompting guide and Aider prompting guide. For team workflows beyond the CLI — shared workspaces and persistent reference docs — see the SurePrompts + Claude Projects guide.

Common Anti-Patterns

  • No CLAUDE.md, forcing every prompt to re-explain the repo. Context drifts and tokens burn. Fix: maintain a concise ./CLAUDE.md plus path-scoped .claude/rules/*.md.
  • Bloating CLAUDE.md with long procedures. Huge always-loaded instructions dilute attention on unrelated tasks. Fix: extract multi-step playbooks into on-demand Skills (SKILL.md).
  • Relying on polite prose for hard security boundaries. Telling an agent "please never edit .env" is softer than a hook. Fix: enforce hard blocks with PreToolUse Lifecycle Hooks and permission deny rules.
  • Vague scopes and missing stop conditions. "Clean up the auth module" invites runaway refactors. Fix: name exact files, explicit exclusions, and verifiable exit commands.
  • Running every subagent on the heaviest model. Using Opus 5.5 or Fable 5.2 for simple read-only grep passes wastes budget. Fix: assign Claude Haiku 5.5 or Sonnet 5.5 in .claude/agents/*.md for narrow research and triage subagents.
  • Trusting self-reported green tests without inspecting output. Fix: require pasted verification output, inspect git diff, and run critical checks yourself before merging.

FAQ

How is prompting Claude Code different from prompting Claude.ai chat?

Claude.ai chat is conversational and single-turn. Claude Code runs an autonomous engineering loop inside your repo — reading, editing, executing commands, firing hooks, and invoking subagents. Frame inputs as structured work orders (goal, scope, context, acceptance commands, stop condition) rather than open-ended chat prompts.

What goes in CLAUDE.md vs. .claude/rules/*.md vs. Skills vs. each prompt?

Keep universal, concise repository facts in ./CLAUDE.md (with org rules in Managed Policy, personal global defaults in ~/.claude/CLAUDE.md, and repo-local overrides in ./CLAUDE.local.md). Put directory- or file-type-specific constraints in .claude/rules/*.md. Package multi-step repeatable runbooks as on-demand Skills (SKILL.md). Keep only today's task goal, file scope, and acceptance criteria in the prompt itself.

When should I use a custom Subagent?

Create a .claude/agents/*.md subagent when work splits cleanly into parallel streams, when heavy research would bloat your main session context, or when routing read-only lookups to Haiku 5.5 or Sonnet 5.5 saves time and cost while Opus 5.5 drives the main implementation.

Should I let Claude Code run any command?

No. Allow read-only inspection, tests, typecheck, lint, and local git diffs; require confirmation for package installs, out-of-scope writes, and pushes; and block destructive operations (rm -rf, force-push to main, production deploys) using permissions and PreToolUse hooks.

How do I keep Claude Code from editing the wrong files?

Combine three layers: declare default off-limits directories in ./CLAUDE.md / .claude/rules/*.md (and hard-block sensitive files with PreToolUse hooks), name exact in-scope files in your work-order prompt, and require git diff --name-only as an acceptance gate before finishing.

Try it yourself

Build expert-level prompts from plain English with SurePrompts — 330+ templates with real-time preview.

Open Prompt Builder

Get ready-made Claude prompts

Browse our curated Claude prompt library — ready-to-use templates, no prompt engineering required.

Browse Claude Prompts