Skip to the page
Tecyfy

Claude Code best practices: 8 habits that work

Most Claude Code habits come down to telling it what it cannot see in the code and giving it a way to check its own work. So give it a test it can run, plan big changes before coding, name the files and the finish line, clear the conversation between tasks, and send research to subagents.

Daily use

Take this page into your AI

Open in ChatGPT (new tab)Open in Claude (new tab)

Claude Code's context window is large (1M tokens on most current models), and it compacts the conversation before the window fills, so you will rarely run out. You still pay for context you don't need, because every request sends the whole conversation. Every file read and every command output stays in it. Most of the habits below give it what it cannot see in the code, or a way to check its own work, and a few keep you from paying for context you do not need.

1. Give it a check it can run

The agent stops when the work looks finished. If nothing can tell it otherwise, "looks finished" is all it has, and you become the test suite.

So hand it something that passes or fails: a test, a build, a linter, a script that compares output with a known-good file, or a screenshot to match. Then it can do the work, run the check, read the failure and go again.

Instead of:

make the price parser handle currencies

write:

parsePrice should accept "€12,50" and "$12.50" and return { amount: 12.5, currency }.
add those 2 cases and "12.50" with no symbol to parse.test.ts, run the tests, and fix the code until they pass

Ask it to show the evidence, not to tell you it worked: the command it ran and what came back.

2. Explore, plan, then code

Letting it write code straight away is how you get a tidy solution to the wrong problem. For anything larger than a small fix, split the work:

  1. Explore. Press Shift+Tab until the status line shows plan mode, or start with claude --permission-mode plan. In plan mode it reads files, runs shell commands to explore and writes a plan, but does not edit your source until you approve the plan.
  2. Plan. Ask for a plan: which files change, in what order, and how you will know it works. Press Ctrl+G to edit the plan in your own editor.
  3. Build. Approve the plan and let it work against it, running the tests as it goes.
  4. Commit. Ask it to commit with a message that explains why.

Planning costs time too. If you could describe the change in one sentence, skip it.

3. Name the files, the limits and the finish line

It can guess what you mean. It cannot read your mind. The fastest way to a right answer is a prompt that says:

  • Where: the file or folder, or @src/billing/invoice.ts to put the file straight into your message.
  • What good looks like: the behaviour, the edge case, the test that should pass.
  • What to copy: "follow the pattern in ReportCard.tsx" beats a description of your code style.
  • What not to do: "no new libraries", "don't change the public API".

Vague prompts have their place. "What would you improve in this file?" is a good way to find what you did not think to ask.

4. Keep CLAUDE.md short

CLAUDE.md is read at the start of every session, so every line costs room in every conversation. Keep only what it cannot work out by reading the code: the exact test, typecheck and lint commands, places where the code is misleading, decisions that are not in the repo, and anything you have had to correct twice already.

For each line, ask whether it could find this by reading the code, and whether it would actually go and look. If both are yes, cut it. A rule it keeps breaking is either lost in a file that has grown too long, or is a rule that cannot have exceptions. Things that must happen every time belong in hooks, which run whatever the model decides.

5. Clear between tasks, and start again after 2 corrections

The most common bad session is the kitchen sink: one task, then an unrelated question, then back to the first task, with all of it still in the window. Type /clear when you move to something unrelated.

The second is correcting the same mistake over and over. Each failed attempt stays in the conversation and pulls the next one off course. After 2 corrections on the same problem, clear and write one better first message that says what you have learned. A clean start with a good prompt usually beats a long session full of wrong turns.

6. Send research to a subagent

Asking it to "look into" something unscoped is how it ends up reading hundreds of files into your window. Either scope the question tightly or hand it off:

use a subagent to find every place we read the session token, and report the files and line numbers

A subagent keeps long output, like a wide search, out of your main conversation. Ask it for a short summary back, so your main conversation keeps its room for the actual change.

7. Let it interview you for big features

For a feature with many open questions, do not write the spec yourself first. Ask it to interview you: about the edge cases, the interface, the trade-offs. Have it write the result to a spec file, then start a fresh session to build from that file. The building session starts clean, with a written plan instead of a long conversation.

8. Review with fresh eyes

A session that just wrote code is inclined to like it. For a real review, open a second session that did not write it:

review the changes on this branch for race conditions and missing error handling. say what you would block a merge on

Then take the findings back to the first session. The same trick works for tests: one session writes the tests, another writes the code that passes them.

The undo button is not Git

Press Esc twice on an empty prompt, or run /rewind, to roll the code back to an earlier prompt. It restores files Claude edited with its edit tools, for sessions saved in about the last 30 days by default. It does not restore a file that only a shell command changed, and it cannot undo database writes or anything pushed to a server. Commit working states as you go, and keep the permission mode tight enough that the things you cannot undo still ask you first. Permissions covers how.

Questions

What is the single most useful Claude Code habit?
Give it a check it can run - a test, a build, a linter or a screenshot to compare against. With a check it can work, test, read the failure and try again until it passes. Without one, it stops when the work looks done, and you have to find the mistakes.
When should I use plan mode?
When you are unsure of the approach, when the change touches several files, or when you do not know the code well. For a change you could describe in one sentence, such as a rename or a typo, skip the plan and ask for it directly.
Why does Claude Code ignore rules in my CLAUDE.md?
Either the file has grown long enough that the rule gets lost, or the rule cannot have exceptions and belongs in a hook. Cut every line it would follow anyway, keep what it cannot work out from the code, and turn rules that must never be broken into hooks.
How many times should I correct Claude Code before starting again?
Anthropic's own advice is 2. After 2 failed corrections on the same problem, the conversation is full of wrong attempts. Run /clear and write one better first message that includes what you learned.

Sources

Where each fact comes from

  1. 1Best practices for Claude Code
  2. 2Choose a permission mode
  3. 3Checkpointing