~/ctoruno
← All posts← All posts
AI Tools · 15 min

How I use Claude Code

The habits, files and workflow that keep my long Claude Code sessions on track.

After using Claude Code on a few projects, I have come to believe that most of what makes a long session go well happens before any code is written and after it is written. The part in the middle, the actual coding, is the easy one. So in this post I am going to walk you through the habits that I have settled on: how I keep the context under control, what goes in my CLAUDE.md, how I plan and spec every feature, why I make the AI write tests first, and why the code gets reviewed by an agent that never saw how it was written. This is not the one true way of using Claude Code (I don’t think that exists), it is just what has worked for me. Take what is useful and ignore the rest.

I’m not gonna go deep into what Claude Code is in this post, I’m just going to assume that we all know about it. If that is not the case, feel free to check the “What is Claude Code” lesson on Claude Academy: https://academy.claude.com/courses/claude-code-101/what-is-claude-code

Context management

As with any other agentic system, context management is very important. As you know, at the center of Claude Code we have an LLM, for example, Claude Sonnet. There is a maximum amount of information that we can send to the LLM in order for the coding agent to receive back a response and act based on it. This is known as the context window. For example, Claude Sonnet 5.5 supports a maximum of 1 million tokens in its context window. At any point in a Claude Code session you can type the /context command and see your context usage. Even before you send any message to Claude Code, you will see that your context window already has some percentage used, this is because the system prompt, tools, skills, subagents, MCP servers and memory files already provide some context.

When this context window approaches the limit, Claude Code automatically fires up the /compact command. Compaction summarizes important details and removes unnecessary tool call results to free up space. You can also execute this command manually. However, just because you have 1 million tokens available does not mean you should fill them all.

As Bex Tuychiev writes in this blog post:

Claude’s output starts degrading at 20-40% of the window, well before any limit kicks in, because the attention mechanism gives earlier instructions less weight as context fills.

Drew Breunig makes a similar point in this blog post, arguing that managing your context is the key to successful agents. We might be drawn to assume that drowning our AI agent with information will deliver better results. However, long context windows might introduce poisoning, distraction, confusion, and contradictions.

Personally, I try to keep my Claude Code sessions under 60%. That is more relaxed than what Bex suggests, so take my number as a personal habit and not as a measured threshold.

Worth saying that Anthropic’s own best practices page now lists “manage the context window aggressively” as dated advice, since most current models have a 1 million token window and compaction runs on its own. What they still recommend is using /clear between unrelated tasks, because a focused context gives better answers and costs less. That is the version of context management I care about: not avoiding the limit, but keeping the context focused.

If you want to dive deeper into context engineering for designing AI agents, I would suggest these two articles:

A helpful CLAUDE.md

I am gonna say one thing: keep it short. Anthropic’s memory guide suggests staying under 200 lines. The CLAUDE.md file is read every time you start a session. It is NOT a replacement for the README, it is a set of instructions that steers the behavior of the AI assistant.

First, you need to know that the CLAUDE.md can be split into four different locations:

  1. Managed policy: the org-level file your platform team controls.
  2. User: your personal preferences that follow you across every project on your machine, in ~/.claude/CLAUDE.md.
  3. Project: the CLAUDE.md file shared with your team, checked into the repo root dir.
  4. Local: your personal notes for this one repository only, in CLAUDE.local.md. Add it to .gitignore so it isn’t committed.

I usually use two: user and project. In the user level, I put my own version of the so-called Karpathy skills (which, at its core, is really just a CLAUDE.md). I want these rules to steer the behavior of all my projects. In the project level, I usually describe the rules and principles that will steer the way that the assistant will help me in a project. Usually, here is where I summarize the points of the sections below.

In their Claude Code in Action course Anthropic mentions two things that I have found to be true:

Your CLAUDE.md file is never finished. Treat it like living code that keeps getting edited.

This is because every project will have its own nuances that will need you to step in and correct or adjust.

Treat your CLAUDE.md like production code. If you can’t justify a line, delete it.

Steering long sessions through brainstorming and planning

In their Claude Code 101 course, Anthropic suggests adopting the explore → plan → code → commit workflow. I completely endorse this workflow with a few nuances.

After using Claude Code for a few projects now, I have come to realize that the key parts for long and complex implementations are the first two stages: exploring (or researching) and planning.

As Boris Tane put it in this blog post:

The workflow I’m going to describe has one core principle: never let Claude write code until you’ve reviewed and approved a written plan. This separation of planning and execution is the single most important thing I do. It prevents wasted effort, keeps me in control of architecture decisions, and produces significantly better results with minimal token usage than jumping straight to code.

Actually, there is one piece that has played a big role for me during this research stage and only gets a short section in the Claude Code Docs: Brainstorm first. The docs suggest doing it when you don’t know exactly what you want yet, but I have found this interview useful even when I am (kinda) clear about what I want.

I would usually prompt an AI assistant something like this:

I'd like your help getting ready to [start a new project / implement a new feature / extend my analysis].

Please brainstorm with me first and interview me until the important decisions are clear.

I actually have a more elaborate prompt with 147 lines of text + appendixes that I will share in the future, but you can get an idea for now.

The idea of this brainstorming is to end up with a solid plan which takes the form of two files that I usually put in a subdir called docs/ or notes/ and that I reference in the CLAUDE.md file:

  • technical-plan.md: Context, not a task list: goal and top tasks; stages; architecture sketch; proposed layout; configuration.
  • roadmap.md: An implementation roadmap of the different stages and specific steps that we will call “features” to implement to achieve the end goal.

This is a very important distinction because, unlike Claude Code’s plan mode, where the plan is saved by default in ~/.claude/plans/, outside of your repository, here we are producing a plan that lives inside the project and gets versioned like any other script or file.

One spec at a time

The brainstorming mentioned above is ONLY to outline a general plan with phases and specific steps (features). This might work when you want to implement just a minor feature in your project, a small job. However, if you are starting a very complex endeavor or journey, this plan is still a bit ambiguous. Therefore, we will implement our own explore → plan → code → commit workflow inside each feature. One at a time (or more if different users are working on other fronts). This is sometimes referred to as “Spec-Driven Development”.

A spec (short for specification) is a structured document that defines what a feature needs to do, how it should behave, or how it will be built before the AI coding agent writes the code. The workflow, which is usually described in the CLAUDE.md file, is simple. Let me show you how I have phrased this workflow in the past so the agent behaves accordingly.

## Workflow: one feature at a time

Know the whole plan, build one feature, prove it works, stop. Never start the next feature in the same run.

1. **Orient.** Read `docs/roadmap.md`. Work only on the feature marked `next`, or the one the user names. Read `docs/technical-plan.md` for context, not as a task list.
2. **Check the spec.** The feature needs `docs/specs/NNN-<name>.md` with `Status: Approved`. If it is missing or `Draft`, write or refine it from `docs/specs/_template.md`, then stop and ask for approval.
3. **Plan.** Propose a short plan: files to touch, tests to write, what stays out of scope. Wait for the user's go-ahead before writing code.
4. **Tests first.** Write tests from the acceptance criteria in `tests/acceptance/NNN-<name>/`. Run them and confirm they fail for the right reason.
5. **Implement.** Work on branch `feature/NNN-<name>`. Make the smallest change that satisfies the criteria. Do not touch code belonging to other features. Update `README.md` when the feature changes how users install, configure or run the assistant.
6. **Verify.** Run the acceptance tests, the full test suite, lint, and type checks. Report the exact commands and results.
7. **Independent review.** Run the `spec-reviewer` subagent, giving it only the spec path and the branch name. Do not pass it your plan, reasoning, or summary. Fix any `Verdict: fail` before handing off, or explain why it is wrong.
8. **Hand off and stop.** Report:
   - What changed (files, migrations)
   - How the user can verify it manually
   - Skipped: work left undone, and why
   - Unsure: assumptions the user should check
   - Follow-ups discovered
   - The reviewer's verdict

   Then stop. Do not begin the next feature.
9. **After the user confirms it works.** On the feature branch, mark the feature `done` in `docs/roadmap.md`, mark the next one `next`, and record any non-obvious choice in `docs/decisions.md`. Then suggest a commit message and description. User will commit and perform the PR by himself.

Very important. I start a new session for every new spec. This keeps the context focused and reduces mistakes during implementation.

Two things in there will make more sense further down: the spec-reviewer subagent (see “Independent review”) and the docs/decisions.md file (see “Implement a Decision Record”).

My colleague Brandon Mora has a more refined version of this workflow, actually connected to GitHub Actions. I would invite you to check his chaski GitHub repository.

Test-Driven Development (TDD)

If you paid attention to the workflow above, step number four was “tests first”, and only then implement. In a traditional workflow, we would write the code first, then the tests, run them, and if they fail, fix the bugs. Under a TDD approach, the tests are defined before the code is written. Why? Because of the way that LLMs are trained, when the code comes first the LLM will be drawn to write tests that prove that the code does what the code does.

With TDD we force the coding assistant into a red-green loop: write a test, watch it fail, and only then write the code that makes it pass. This is related to the Goal-Driven Execution principle in the Karpathy-inspired guidelines mentioned above. Instead of adding a validation and then a test that confirms it, the AI first writes tests for invalid behavior or inputs, confirms that they fail, and then implements the validation until they all pass.

If the agent finds a bug, instead of writing code that “fixes the bug” and then a test that confirms what the code intended, we force the AI to first write a test that reproduces the bug, which should fail, and then modify the code until that test passes.

Subagents, Skills and Hooks: When to use each one?

  • Skills: Use when you want to teach your coding agent how to perform a specific task through reusable instructions, workflows, and reference materials.
  • Subagents: Use when you want to delegate a specific task to a specialized agent, allowing multiple agents to work independently or in parallel.
  • Hooks: Use when you want to automate or enforce actions at specific points in the agent lifecycle, such as running tests, formatting code, or validating changes.

A few notes on how I think about them. Subagents are great for running independent pieces of work in parallel, for keeping noisy output (like a broad search through the codebase) out of your main conversation, and for getting a reviewer that has not seen how the code was written. That last one is the case I care about the most, and my spec-reviewer from the workflow above is an example. Keep in mind that every subagent sends its own requests, so all of this costs extra tokens.

Skills and hooks differ in a more subtle way. CLAUDE.md and skills are instructions that the model reads and decides how to apply. Hooks are executed by Claude Code itself, every time, no matter what the model decides. So my workflow lives in CLAUDE.md as a strong suggestion, and anything that must happen without exceptions, like running the reviewer before handing off (step 7 above), is a good candidate for a hook.

Independent review

In a recent blog post from the World Bank, they argue that code that runs and passes all the available tests is not necessarily correct code. Hence the need for an AI peer reviewer. They support using a reusable Skill rather than a one-off prompt, and I agree. Where I would go one step further is that I think the reviewer should be a subagent with a specialized skill, and here is why.

A skill, by default, gets loaded into the session where the code was written. That means the reviewer sees everything the author saw: the plan, the dead ends, the reasoning behind every choice. And that is exactly the problem we had with tests. Just like an LLM will write tests that prove the code does what the code does, a reviewer with the full story will tend to see what the author intended instead of what is actually there.

A subagent starts from a clean slate. By default it does not see your conversation history, the skills that were already invoked, or the files Claude has already read. It works from a delegation message (which the main agent writes, and that is why step 7 of my workflow says to pass only the spec path and the branch name, nothing else), plus its own system prompt, the CLAUDE.md files and any skills it preloads. And you don’t lose the skill, because a subagent can preload skills through the skills field in its definition. The review criteria live in the skill, the independence comes from the subagent.

So it is not skill versus subagent. The skill is the how, the subagent is the who. Anthropic makes a similar point in their best practices page: handing the same task to a subagent does not make the answer any better, but a fresh reviewer does help, because it has not seen your reasoning.

Plugins

If you would rather not build your own reviewer, or you just want to see how others structure these workflows, plugins are worth a look. Plugins are packages that extend an AI coding agent with additional capabilities and workflows. There are two plugins that I think are worth checking out:

  1. Superpowers: A structured software-development methodology that gives an agent workflows for brainstorming, planning, writing implementation plans, test-driven development (TDD), debugging, and code review.
  2. Code Review: Anthropic’s official Code Review plugin. It uses five specialized reviewers working in parallel, confidence scoring, and GitHub PR comments.

Check them out, depending on your needs they might fit in your own workflow. Superpowers is also available for use in Codex.

Implement a Decision Record

I have found it so helpful to keep a decision record inside the project’s repository. During a coding session, a lot of decisions are being made. Either the AI suggests something you were not considering or the other way around. If you do not record those pieces of information, once you close the session, that information is lost. On complex and long projects, having this information recorded somewhere for the AI to read and understand can save a lot of time, money and tokens.

After working with coding agents for a few projects now, I kind of knew this was an issue. However, after reading this post from Phil Morehead and this other one from Andrew Connell, I understood that the documentation can be done in a systematic way that helps the coding agent between sessions.

Three things are important to keep a record of:

  • What was asked, and why.
  • What was chosen, and which options were rejected.
  • What was tried and why it did not work.

Let me show you how you can introduce this in a CLAUDE.md file:

## Decision log

- Record every design or methodology decision in `docs/decisions.md`: changing a default, choosing between code and docs when they disagree, adopting or rejecting an approach.
- Append a new numbered entry (D-001, D-002, …) using the template at the bottom of the file. Never edit an old entry; supersede it with a new one and set the old one's status to "Superseded by D-00X".
- Record only the rationale the user gave. If none was given, write `*TODO: add.*` rather than inventing one.

With a template for the entries that goes like:

## D-00X: Short title

- **Date:** YYYY-MM-DD
- **Status:** Accepted
- **Decision:** What was decided.
- **Rationale:** What the user gave, or *TODO: add.*

Wrapping up

That is more or less how I use Claude Code these days. None of it is magic, most of it comes down to three things: write things down, make the AI prove its work, and keep the context focused. And as with my CLAUDE.md, this list is never finished, so I will probably be back with updates (and with that 147-line prompt, I promise).

Written by Carlos Toruño — development economist, data analyst, still in the endless cycle. More about me.