Claude Code best practices: how to keep your foundations solid
Seven habits we set up with founders who code with Claude Code, so the parts everything else depends on stay clean at feature
The Claude Code best practices that matter most are about structure, not prompts. Write your conventions in CLAUDE.md, decide which parts of the repo must stay solid, plan before you let it touch those parts, ship one task per PR, and have every PR reviewed by someone other than the agent that wrote it. Clever prompting makes one feature better. These habits keep feature #30 as easy as feature #3.
Here is the setup we put in place with founders who code their own product with Claude Code. None of it needs us. All of it works better if you start early.
1. Keep CLAUDE.md short and specific
Claude Code reads CLAUDE.md at the start of every session. It's the cheapest lever you have, and most repos either don't have one or have a long one nobody reads.
Put in it what Claude can't guess from the code: naming rules, folder structure, how errors are handled, which libraries you use for what, and the commands to run the tests. Then add a short list of what it should never do without asking, like changing a migration that has already run or adding a new dependency.
Keep it under a page. If a rule only matters for one folder, put a CLAUDE.md in that folder instead.
2. Decide what has to stay solid
Not all code deserves the same care. A landing page Claude writes in three different styles is fine. Your data model isn't.
So write down the parts everything else depends on: the database schema, auth and permissions, the API contracts between your services, integrations like payments, and deployment. We call that list the Expandable Core. It's usually 8 to 15 entries, in one markdown file in the repo. Everything outside it can move fast. Everything on it gets a slow read.
This one list changes how you use every other practice below.
3. Think before you prompt
Claude made writing code nearly free. It didn't make deciding what to write any faster. Before a real feature, answer four questions:
- What's the actual problem? "Add a status filter" and "users can't find their open files" don't lead to the same solution. Give Claude the second one.
- What's the simple version? Ask for an architecture and you can get microservices for zero users. Ask for the simplest thing that works.
- What does it touch? If the answer is on your core list, slow down.
- How will you know it's done? One observable result, written before you start.
It rarely takes more than twenty minutes. We wrote more about it (in French) in la règle des 55 minutes.
4. Use plan mode for anything on the core list
For changes to the core, don't let Claude go straight to editing. Switch to plan mode (Shift+Tab in the terminal) and ask for a plan first: which files, which tables, what changes in the contracts, what could break. Read it, push back, then let it run.
A bad plan costs you two minutes to reject. A bad migration costs you a weekend.
5. One task, one branch, one PR
Claude Code can do a lot in one session, and that's the trap. Three features in one branch means one review nobody can really do.
Keep each task small enough to review in fifteen minutes. Ask Claude to open a PR at the end with a summary of what it changed and why. If a PR touches twenty files for a simple feature, that's a sign the structure is forcing it everywhere, and it's worth a look (more in Technical debt in AI-generated code).
6. Make tests the definition of done
Tell Claude to write the test first, watch it fail, then write the code until it passes. It's good at this, and it means "done" is something you can check rather than something Claude says.
You don't need tests everywhere. You need them on the core: anything that touches money, permissions or data other code relies on.
7. Protect the core with a hook, not a reminder
Rules in CLAUDE.md are instructions. Claude follows them most of the time. For the files that really matter, "most of the time" isn't enough, so make it mechanical.
Claude Code runs hooks, scripts that fire before or after its actions. This one stops it from editing your migrations or your auth folder without you. In .claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/protect-core.sh" }]
}
]
}
}
And in .claude/hooks/protect-core.sh (make it executable, it needs jq):
#!/bin/bash
file=$(jq -r '.tool_input.file_path // empty')
case "$file" in
*db/migrations/*|*src/auth/*)
echo "This file is in the Expandable Core. Explain the change and wait for approval." >&2
exit 2 ;;
esac
exit 0
Exit code 2 blocks the edit and sends the message back to Claude, which then explains what it wanted to do. You make the change yourself or adjust the hook. Swap the paths for the ones on your core list.
And then: review in two passes
All of the above reduces the damage. It doesn't replace review. The agent that wrote the code is the worst reviewer of it, because it's confident in its own choices.
Run an agent pass first for the mechanical things (conventions, missing tests, secrets), then a human pass for what needs judgment: does this create a second way of doing something, will this column be a problem in four months. If you're solo, at least come back the next morning. The distance does half the job. The full setup is in our review workflow, and what that first pass looks for on access rules and data exposure is on our Claude Code security page.
The Bunker Test, free. Want to know which of these your repo already does and which ones it's missing? Give us read-only access. Within 5 business days we come back with a Solidity and Structure score out of 100, your top 3 risks and one fix you can ship the same day. A 15-minute walkthrough is included, no commitment.
Want to see this approach running on your repo? Send us access and we'll come back with at least 5 concrete risks within 5 business days.