Claude Code Best Practices
Claude Code is deliberately low-level and unopinionated, which makes it a flexible, scriptable, and safe tool but also gives it a learning curve. This Anthropic post collects patterns that work for internal teams and external engineers across many codebases. It covers how to configure the environment, extend Claude's tools, structure common workflows, and run multiple Claude instances in parallel. The author presents these as starting points to experiment with, not fixed rules. ## Customizing Your Setup - **CLAUDE.md files** are loaded automatically at the start of a conversation. They are a good place to record common bash commands, core files and utilities, code style, testing instructions, repository etiquette, environment quirks, and project-specific warnings. The format is free, but the files should be concise and readable. - **Placement** can vary. A root-level CLAUDE.md should be checked into git for team sharing, while CLAUDE.local.md is git-ignored for personal notes. Parent directories suit monorepos, child directories load on demand, and `~/.claude/CLAUDE.md` applies to every session. `/init` generates a starter file. - **Tuning** matters because these files become part of the prompt. Pressing `#` adds an instruction to CLAUDE.md, and emphasis such as "IMPORTANT" or "YOU MUST" can improve adherence. - **Tool permissions** are conservative by default. You can allow tools through the "Always allow" prompt option, the `/permissions` command, `.claude/settings.json` or `~/.claude.json`, or the `--allowedTools` flag. Examples include `Edit` and `Bash(git commit:*)`. - **GitHub integration** works best with the `gh` CLI installed, though the GitHub API or an MCP server also works. ## Giving Claude More Tools - **Bash tools:** Claude inherits your shell environment. Tell it about custom tools with usage examples, ask it to run `--help`, or document them in CLAUDE.md. - **MCP servers:** Claude Code can act as both MCP server and client. Servers can be configured per project, globally, or in a checked-in `.mcp.json` so a whole team gets them. The `--mcp-debug` flag helps diagnose configuration problems. - **Custom slash commands:** Markdown prompt templates in `.claude/commands` (shared via git) or `~/.claude/commands` (personal) become slash commands. The `$ARGUMENTS` keyword passes input through, so a `fix-github-issue.md` template can be invoked as `/project:fix-github-issue 1234`. ## Common Workflows - **Explore, plan, code, commit:** Have Claude read relevant files without writing code, then ask for a plan. Phrases like "think," "think hard," "think harder," and "ultrathink" map to increasing thinking budgets. Save the plan as a document or issue, implement it while checking the solution, then commit and open a PR. The research and planning steps are the most important, since they keep Claude from jumping straight to code. Subagents help verify details without consuming main-context space. - **Test-driven development:** Have Claude write tests from expected input/output pairs, confirm they fail, and commit them. Then have it write code that passes the tests without modifying them, iterating until they pass. Independent subagents can check for overfitting. Clear targets like tests or mockups make iteration effective. - **Visual iteration:** Give Claude a way to take screenshots (for example, through the Puppeteer MCP server) and a visual mock to match. Output typically improves noticeably after two or three iterations. - **Safe YOLO mode:** `--dangerously-skip-permissions` removes approval prompts, which suits tasks like fixing lint errors. The author recommends running it only in a container without internet access because of risks such as data loss and prompt-injection-driven exfiltration. - **Codebase Q&A:** Claude can answer onboarding questions about logging, endpoints, edge cases, or why a particular call was made, without special prompting. - **Git and GitHub:** Many Anthropic engineers use Claude for over 90% of their git work, including history searches, commit messages, rebase conflicts, PR creation, addressing simple review comments, fixing failing builds, and triaging issues. - **Jupyter notebooks:** Keep Claude Code and the `.ipynb` file open side by side in VS Code. Claude can read outputs, including images, and polish notebooks by asking for "aesthetically pleasing" visualizations. ## Optimizing Your Workflow - **Specific instructions** get better results. For example, "write a new test case for foo.py covering the logged-out edge case, avoid mocks" beats "add tests for foo.py." - **Context inputs** include pasted or dragged screenshots (on macOS, `cmd+ctrl+shift+4` copies a screenshot to the clipboard for `ctrl+v`), file paths, tab-completed file references, and URLs. Domains can be allowlisted through `/permissions`. - **Course correction** works through several controls: asking for a plan before code, pressing Escape to interrupt, double-tapping Escape to edit an earlier prompt, and asking Claude to undo changes. - **Context hygiene** comes from running `/clear` between tasks so irrelevant history doesn't crowd out the current work. - **Checklists and scratchpads** help with large tasks. For example, have Claude write lint errors into a Markdown checklist, then work through them one by one. - **Data input** can be pasted, piped (`cat foo.txt | claude`), pulled through bash or MCP tools, or read from files and URLs. ## Headless Mode and Automation - The `-p` flag runs Claude non-interactively for CI, pre-commit hooks, and build scripts. `--output-format stream-json` streams JSON output. Headless sessions do not persist. - Examples include GitHub-triggered issue triage that applies labels, and using Claude as a subjective linter to catch typos, stale comments, and misleading names. ## Multi-Claude Workflows - **Separate writer and reviewer:** One Claude writes code, then a fresh instance (after `/clear` or in another terminal) reviews it. A similar split works for tests and implementation. Scratchpads let instances pass information to each other. - **Multiple checkouts:** Some engineers run 3–4 checkouts in separate terminal tabs, each with its own task. - **Git worktrees:** `git worktree add ../project-feature-a feature-a` creates an isolated working directory for each independent task, avoiding merge conflicts. Tips include consistent naming, one terminal tab per worktree, iTerm2 notifications, and cleanup with `git worktree remove`. - **Headless fan-out and pipelines:** A script can generate a task list (such as 2,000 files to migrate) and call `claude -p` for each item with restricted `--allowedTools`. Alternatively, `claude -p ... --json` can feed into the next step of a data pipeline. The `--verbose` flag helps debugging. ## Getting Started The most practical starting point is a short, shared CLAUDE.md, followed by the explore-plan-code-commit loop with specific prompts and frequent `/clear`. The author encourages adapting these patterns to your own workflow. The post is by Boris Cherny and notes that it is no longer maintained in favor of the official Claude Code documentation.