# Best\-Practice Workflows for Coding with Claude Code

> Key takeaways
>
> - Run a disciplined explore → plan → code → commit loop rather than one\-shot generation; the loop matters more than raw model power\.
> - Give the agent a way to verify its own work — running tests or a linter after every change is among the most effective techniques\.
> - Invest in persistent context: CLAUDE\.md is the primary mechanism and is auto\-read from the project root, your home directory, and parent directories\.
> - Scope each task to a single, well\-defined unit instead of a large batch\.
> - Treat Git as the audit trail; Claude Code reads history, manages branches, and creates PRs\.
> - Extend the agent through the Model Context Protocol \(MCP\) to reach databases, APIs, and custom tooling\.
> - Parallelize safely using git worktrees to isolate multiple Claude Code instances on one repository\.

# Best\-Practice Workflows for Coding with Claude Code

> [!NOTE]
> Claude Code evolves rapidly; exact command names, flags, and documentation URLs can change between releases\. Treat the specifics below as a snapshot and confirm individual commands, flags, and settings against the current official Claude Code documentation before relying on them\.

## The Core Workflow

Claude Code is Anthropic's agentic CLI coding tool that lives in the terminal, reads and edits files, runs shell commands, and interacts with version control\. Its effectiveness comes less from raw model capability than from the loop you run it in\.

[Claude Code is Anthropic's agentic CLI coding tool that lives in the terminal, reads and edits files, runs shell commands, and interacts with version control\.](https://docs.anthropic.com/en/docs/claude-code/overview) - Claude Code Overview

The canonical loop has four phases — explore, plan, code, commit: provide context and let the agent explore the codebase, ask for a written plan before edits, execute with checkpoints, and commit only reviewed changes\. Anthropic's guide recommends a deliberate planning step before editing, where Claude outlines its approach and gets approval before making changes — effectively a two\-phase plan\-then\-act workflow\.

[The canonical loop has four phases — explore, plan, code, commit; Anthropic recommends a deliberate planning step before editing, where Claude outlines its approach and gets approval before making changes\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

Two structural rules keep the loop reliable: scope each task to a single, well\-defined unit rather than a large batch; and for automation, use headless/non\-interactive mode via \`claude \-\-print\` or piping to enable scripted and CI use\.

[Scope each task to a single, well\-defined unit rather than a large batch\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

[For automation, use headless/non\-interactive mode via \`claude \-\-print\` or piping to enable scripted and CI use\.](https://docs.anthropic.com/en/docs/claude-code/cli-reference) - Claude Code CLI Reference

## Prompting \& Instruction Patterns

Prompt quality maps directly to output quality\. Be specific about inputs, outputs, and constraints — vague prompts produce worse results — and provide example inputs and outputs inline to improve correctness\.

[Be specific about inputs, outputs, and constraints — vague prompts produce worse results — and provide example inputs and outputs inline to improve correctness\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

For hard problems, Claude Code recognizes escalating extended\-thinking prompts: the keywords "think", "think hard", "think harder", and "ultrathink" map to progressively larger reasoning budgets, which helps with complex refactors and debugging\.

[Claude Code maps escalating thinking keywords — "think", "think hard", "think harder", and "ultrathink" — to progressively larger extended\-thinking budgets\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

Stage large goals by breaking them into sequential sub\-prompts, each with a verifiable acceptance criterion; specify coding style and language version in the prompt or CLAUDE\.md so the model does not default to training priors; and ask Claude to explain what it changed and why to speed review\.

[Break large goals into sequential sub\-prompts with verifiable acceptance criteria; specify coding style and language version so the model does not default to training priors; and ask Claude to explain what it changed and why\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

> [!WARNING]
> Because the agent reads files as well as prompts, Claude Code is susceptible to prompt injection from adversarial file content — review changes that modify system prompts or tool configurations\.

[Claude Code is susceptible to prompt injection from adversarial file content; review changes that modify system prompts or tool configurations\.](https://docs.anthropic.com/en/docs/claude-code/security) - Claude Code Security

## Context Management

CLAUDE\.md is the primary persistent\-context mechanism — auto\-read at the project root, at \~/\.claude/CLAUDE\.md, and in parent directories — and should hold the architecture overview, coding standards, build/test/lint commands, a glossary, and the project layout\. Memory is tiered across a global file for personal preferences, a project\-root file for project facts, and subdirectory files for component\-specific detail, with Claude merging all applicable files\.

[CLAUDE\.md is the primary persistent\-context mechanism, auto\-read at the project root, at \~/\.claude/CLAUDE\.md, and in parent directories, with memory tiered across global, project, and subdirectory files that Claude merges\.](https://docs.anthropic.com/en/docs/claude-code/memory) - Claude Code Memory

Manage the live conversation as well as the static files: reset context at task boundaries with the /clear command, and rely on Claude Code's proactive context summarization to compress older exchanges in long sessions\.

[Reset context at task boundaries with /clear, and use proactive context summarization to compress older exchanges in long sessions\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

For rules that must persist across sessions, encode them directly in CLAUDE\.md so they are loaded every time\. And make that context actionable by including runnable commands in CLAUDE\.md so Claude can self\-verify its work\.

[Encode persistent project rules directly in CLAUDE\.md so they are loaded into context every session\.](https://docs.anthropic.com/en/docs/claude-code/memory) - Claude Code Memory

[Include runnable commands in CLAUDE\.md so Claude can self\-verify its work\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

## Iteration \& Review Loops

Test\-driven development is the most reliable iteration pattern: write failing tests, make them pass, review the diff, and commit — which constrains the solution space and provides automatic verification\. According to Anthropic's best\-practices guide, giving Claude a way to verify its own work, such as running tests or a linter after every change, is among the most effective techniques\.

[Test\-driven development — write failing tests, make them pass, review the diff, commit — constrains the solution space; giving Claude a way to verify its own work, such as running tests or a linter after every change, is among the most effective techniques\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

Operationally, ask Claude to self\-verify via tool calls before declaring a task done, and instruct it to run a linter or formatter \(for example eslint \-\-fix, black, or ruff\) after each step\. Work in incremental diffs and atomic commits so a bad change can be reverted with git reset; require a planning review before destructive operations such as deletes, migrations, or infrastructure changes; and keep human checkpoints after exploration, after planning, after the first implementation, and before commit\.

[Ask Claude to self\-verify via tool calls before declaring done, run a linter or formatter after each step, work in incremental atomic commits, gate destructive operations behind a planning review, and keep human checkpoints across the loop\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

## Integration with Git, GitHub, CI/CD, Editors, and MCP

Claude Code's Git integration is native — reading log and blame, managing branches, staging, writing commit messages, and creating PRs — with Git serving as the audit trail\. Reinforce this by having Claude run the project's linters and tests as verification steps after each change\.

[Claude Code's Git integration is native — reading log and blame, managing branches, staging, writing commit messages, and creating PRs — with Git serving as the audit trail\.](https://docs.anthropic.com/en/docs/claude-code/overview) - Claude Code Overview

[Have Claude run the project's linters and tests as verification steps after each change\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

GitHub Actions integration runs via \`claude \-\-print\` for automated review, PR generation, and issue triage, and \`/install\-github\-app\` configures the Claude GitHub App\.

[GitHub Actions integration runs via \`claude \-\-print\` for automated review, PR generation, and issue triage, and \`/install\-github\-app\` configures the Claude GitHub App\.](https://docs.anthropic.com/en/docs/claude-code/github-actions) - Claude Code GitHub Actions

The Model Context Protocol \(MCP\) extends Claude Code with external tools — database queries, APIs, and custom tooling — configured via JSON, with first\-party MCP client support shipped in Claude Code\. MCP is an open protocol that Anthropic announced in November 2024\.

[MCP extends Claude Code with external tools — database queries, APIs, and custom tooling — configured via JSON, with first\-party MCP client support\.](https://docs.anthropic.com/en/docs/claude-code/mcp) - Claude Code MCP

[MCP is an open protocol that Anthropic announced in November 2024\.](https://www.anthropic.com/news/model-context-protocol) - Introducing the Model Context Protocol

VS Code and JetBrains IDE extensions exist, though the terminal\-first experience remains canonical\.

[VS Code and JetBrains IDE extensions exist, though the terminal\-first experience remains canonical\.](https://docs.anthropic.com/en/docs/claude-code/overview) - Claude Code Overview

> [!NOTE]
> Official CI/CD templates beyond GitHub Actions are sparse; treat broader pipeline recipes from the community as practitioner reports rather than authoritative guidance\.

## Multi\-Agent \& Subagent Patterns

For large work, a single session can act as an orchestrator that delegates sub\-tasks to subagents\. Anthropic's best\-practices guide recommends using git worktrees to isolate multiple Claude Code instances running in parallel on the same repository, preventing write conflicts\.

[Use subagents to delegate sub\-tasks, and use git worktrees to isolate multiple Claude Code instances running in parallel on the same repository\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

The pattern is to break a goal into independent tasks that subagents handle in parallel, then aggregate the results — a structure well\-suited to large refactors\. For deeper background on orchestrator and subagent pipelines, see Anthropic's "Building Effective Agents\."

[Break a goal into independent tasks that subagents handle in parallel, then aggregate the results — suited to large refactors\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

[Background on orchestrator and subagent pipelines\.](https://www.anthropic.com/research/building-effective-agents) - Building Effective Agents

## Common Pitfalls \& Mitigations

- Over\-trusting single\-shot generation compounds errors — mitigate with checkpoints and test runs\.
- Context bleeds across tasks — mitigate with /clear or a new session\.
- A thin CLAUDE\.md forces the model to re\-infer project facts — invest in a comprehensive one\.
- Unbounded shell permissions risk destructive operations — review tool\-call permissions and require human approval for risky commands\.
- Malicious files can inject prompts — review unexpected tool calls, especially after reading external files\.
- Skipping planning on complex tasks yields inconsistent results — use a planning step for any task touching more than about three files\.

[Single\-shot generation compounds errors \(use checkpoints and test runs\); context bleeds across tasks \(use /clear or a new session\); skipping planning on complex tasks yields inconsistent results\.](https://www.anthropic.com/engineering/claude-code-best-practices) - Claude Code: Best Practices for Agentic Coding

[A thin CLAUDE\.md forces the model to re\-infer project facts — invest in a comprehensive one\.](https://docs.anthropic.com/en/docs/claude-code/memory) - Claude Code Memory

[Review tool\-call permissions and require human approval for risky commands; review unexpected tool calls, especially after reading external files, to guard against prompt injection\.](https://docs.anthropic.com/en/docs/claude-code/security) - Claude Code Security

## Claude Code vs\. OpenAI Codex CLI

> [!INFO]
> This comparison is secondary in scope and should be read with care: there are no public head\-to\-head benchmarks and no adoption statistics, so the matrix below is a feature comparison, not a performance ranking\.

OpenAI Codex CLI is OpenAI's open\-source terminal coding agent, open\-sourced in April 2025\. Its permission model has three levels — suggest \(read\-only\), auto\-edit \(write files, approve shell\), and full\-auto \(full access\) — it uses an AGENTS\.md project\-context file analogous to Claude Code's CLAUDE\.md, relies on sandboxed execution \(Apple Seatbelt on macOS, Docker on Linux for full\-auto\), and is Apache 2\.0 licensed\.

[OpenAI Codex CLI is OpenAI's open\-source terminal coding agent \(April 2025\) with a three\-level permission model \(suggest / auto\-edit / full\-auto\), an AGENTS\.md project\-context file, sandboxed execution \(Apple Seatbelt on macOS, Docker on Linux\), under an Apache 2\.0 license\.](https://github.com/openai/codex) - OpenAI Codex CLI \(GitHub\)

Note a naming distinction: the legacy OpenAI Codex model \(code\-davinci\-002\) was deprecated in March 2023 and is distinct from the Codex CLI\.

[The legacy OpenAI Codex model \(code\-davinci\-002\) was deprecated in March 2023 and is distinct from the Codex CLI\.](https://platform.openai.com/docs/deprecations) - OpenAI Platform Docs — Deprecations

| Feature | Claude Code | OpenAI Codex CLI |
| --- | --- | --- |
| Project context file | CLAUDE\.md \(multi\-tier\) | AGENTS\.md |
| Planning step | Plan\-then\-act workflow | Suggest / auto\-edit / full\-auto |
| Multi\-agent / subagents | Yes \(documented\) | Not natively documented |
| MCP support | Yes \(first\-party\) | Not native |
| GitHub Actions | Yes \(official\) | Community / unofficial |
| Sandboxed execution | Permission prompts | macOS Seatbelt / Docker |
| Open source | No | Yes \(Apache 2\.0\) |
| Model | Claude \(Sonnet family\) | GPT\-4o / o\-series |

[Codex CLI feature details \(permission modes, AGENTS\.md, sandboxing, open\-source licensing, models\)\.](https://github.com/openai/codex) - OpenAI Codex CLI \(GitHub\)

[Claude Code feature details \(CLAUDE\.md context, native Git integration, terminal\-first design\)\.](https://docs.anthropic.com/en/docs/claude-code/overview) - Claude Code Overview

On context window, the one available spec comparison is Claude 3\.5 Sonnet's 200K\-token window versus GPT\-4o's 128K\-token window\. No further quantitative comparison is available and no numbers beyond these specs should be inferred\.

[Claude 3\.5 Sonnet's context window is 200K tokens\.](https://docs.anthropic.com/en/docs/about-claude/models) - About Claude Models

[GPT\-4o's context window is 128K tokens\.](https://platform.openai.com/docs/models/gpt-4o) - OpenAI Platform Docs — GPT\-4o

Chart (bar).
| model | contextTokens |
| --- | --- |
| Claude 3\.5 Sonnet | 200000 |
| GPT\-4o | 128000 |
Source: Anthropic \& OpenAI model documentation (https://docs\.anthropic\.com/en/docs/about\-claude/models)
