Vivek's Field Notes

Claude Code

β€’ 6 min read

Introduction

Like every LLM, Claude Code suffers from context rot: the longer and noisier the context window gets, the worse the performance and the more tokens you burn.

A few habits that help:

For design work, prompt Claude to create 10 different variations (e.g. HTML files), explore them quickly, then narrow down to a good one.

I used to ask Claude to write Markdown files, but HTML turned out to be better. It really helps to see a solution or an explanation visualised.

Commands

CommandWhat it does
/initCreate initial documentation of the repo in CLAUDE.md
/clearClear context (do it if you are stuck)
/compact <focus>Summarize context, optionally saying what to keep (use when stuck or in a long session)
/modelSelect the model for the session (Opus: complex tasks, Sonnet: normal tasks)
/batchExecute tasks in parallel using agents
/simplifyRefactor and remove redundancy
/resumeResume the last session
/contextShow context usage
/exportSave the current chat to the clipboard or a file
/configRecommended: disable auto-compact (it rarely helps)
Shift + TabPlan mode: Claude asks clarifying questions before complex features
TabThinking mode, for complex reasoning
EscInterrupt
Esc EscRevert to a previous state
Ctrl + GEdit your prompt in your default text editor

Custom commands

Create ~/.claude/commands/ and drop Markdown files in it, such as follow-up.md. Each file becomes a command you can call with /follow-up, which injects your custom instructions and saves you retyping them.

Skills

Skills automatically load relevant instructions based on the conversation’s context, which makes them a powerful way to customize your agents.

They are loaded lazily. Claude’s context only receives a brief name and description for each available skill upfront. When a task triggers a skill, Claude reads the full SKILL.md at runtime before writing any code or creating any files. This keeps the context lean while still following proven patterns when it matters.

Workflow

Explore β†’ Plan β†’ Code β†’ Commit. Without this, most people jump straight to asking Claude to write code, which means more course-correcting later.

Under the hood the agent runs a loop: gather context, take action, verify the result, and repeat until done. You can interrupt, steer or add context at any point.

Agentic loop: your prompt, then gather context, take action and verify results on repeat, then done. You can interrupt, steer or add context at any time.

Plan

The fastest way to handle the first two steps is Plan Mode. In plan mode Claude can’t edit files; it only reads them to work out how it will tackle the implementation.

Press Shift + Tab until you see “Plan Mode” under the text input. Claude will read relevant files, run some web searches, and give you a plan of action. Review it and decide if it meets your criteria. If not, ask it to revise specific areas.

Code

Once the plan looks good, approve it and let Claude work through the list. You can choose whether Claude auto-accepts file edits or asks each time.

Claude will try to troubleshoot before calling the plan “finished”, but sometimes you’ll need to step in. That’s the benefit of Plan Mode: after execution you also have the context of how you got to the result, which helps guide Claude’s next decisions.

Commit

Once you’ve tested the changes and are happy, it’s time to push. Before committing, run a subagent code reviewer over your work. A subagent gets a fresh pair of eyes on the codebase and doesn’t carry the bias the main agent built up during the session.

Context window

When you approach the limit, the context window is compacted automatically. Compaction summarizes the important details and drops unnecessary tool-call results to free up space. Note that this can lose details.

To see why context grows, here is how the prompt is built over a session. The first request is assembled from system instructions, tools, permissions, developer instructions, project instructions (AGENTS.md / CLAUDE.md), environment context, and finally your message.

Snapshot 1: building the initial prompt from system, developer and user items

When the model calls a tool, the reasoning, the function call and its output are appended to the input, and the whole thing is sent again.

Snapshot 2: reply with tool call output appended to the original input

On a new turn, everything from the previous turn is kept and your next message goes at the end. Nothing is dropped until you compact or clear.

Snapshot 3: starting a new turn, with the previous turn kept in the input

Rule of thumb

Other ways to save context

CLAUDE.md

Without a CLAUDE.md, Claude Code starts fresh every time. It has to re-explore your codebase, work out the dependencies, and figure out which features already exist. Sometimes it makes assumptions, which makes it harder to steer.

CLAUDE.md solves this. It’s a Markdown file at the root of your project that Claude Code reads automatically at the start of every session, and its contents are appended to your prompt. Think of it as an onboarding script for your codebase.

Tip: Save corrections to memory. If you keep correcting Claude, such as telling it to always use server actions instead of API routes, explicitly ask it to save that rule. Next time you open the project, it’ll know.

Subagents

A lot of the context window is consumed by tool calls exploring your codebase or running web searches, and what Claude finds there isn’t always relevant to the feature you’re building.

Subagents fix this. Claude spawns one for a task like “explore this codebase for me”. It runs in parallel with its own context window, does all the exploration, and returns only a summary to Claude. You get the answer without the whole journey cluttering your main context.

Subagents are defined in Markdown files with YAML frontmatter. The easiest way to start is to let Claude generate one:

/agents

Then select Create new agent. You’ll walk through choosing the agent’s scope, defining its purpose, selecting the tools it can access, and even picking a color for it.

Claude generates a name, description and prompt for the subagent. The description also tells Claude when to call it based on the prompts you give.

#LLM #Notes