Best-Practice Workflows for Coding with Claude Code
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.docs.anthropic.com
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.www.anthropic.com
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.www.anthropic.com
For automation, use headless/non-interactive mode via `claude --print` or piping to enable scripted and CI use.docs.anthropic.com
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.www.anthropic.com
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.www.anthropic.com
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.www.anthropic.com
Claude Code is susceptible to prompt injection from adversarial file content; review changes that modify system prompts or tool configurations.docs.anthropic.com
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.docs.anthropic.com
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.www.anthropic.com
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.docs.anthropic.com
Include runnable commands in CLAUDE.md so Claude can self-verify its work.www.anthropic.com
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.www.anthropic.com
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.www.anthropic.com
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.docs.anthropic.com
Have Claude run the project's linters and tests as verification steps after each change.www.anthropic.com
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.docs.anthropic.com
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.docs.anthropic.com
MCP is an open protocol that Anthropic announced in November 2024.www.anthropic.com
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.docs.anthropic.com
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.www.anthropic.com
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.www.anthropic.com
Background on orchestrator and subagent pipelines.www.anthropic.com
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.www.anthropic.com
A thin CLAUDE.md forces the model to re-infer project facts — invest in a comprehensive one.docs.anthropic.com
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.docs.anthropic.com
Claude Code vs. OpenAI Codex CLI
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.github.com
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.platform.openai.com
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.docs.anthropic.com
GPT-4o's context window is 128K tokens.platform.openai.com