Advanced (Updated: 6/1/2026)

Claude Code Context Management: Use /context, /compact, CLAUDE.md, and Obsidian Well

A practical guide to keeping Claude Code sessions focused with /context, /compact, memory, and handoff notes.

Claude Code Context Management: Use /context, /compact, CLAUDE.md, and Obsidian Well

Many Claude Code sessions fail because the model is weak. Many more fail because the session is full of stale context.

Context management is the habit of deciding what Claude should know now, what should live in project memory, what should be summarized, and what should be left in external notes.

This guide shows a practical operating rhythm using /context, /compact, /clear, /memory, CLAUDE.md, and Obsidian-style notes.

Think of the Context Window as the Working Desk

The context window is the working set of the session. It includes conversation history, files Claude has read, tool results, CLAUDE.md, auto memory, loaded rules, and loaded skills. When it fills, the session gets harder to steer because important constraints compete with old output.

What enters contextWhy it gets heavyPractical response
ConversationLong discussion and side questsCut by task boundary
FilesReading huge files wholeSearch first, then read narrow ranges
Tool outputLong logs and repeated failuresSummarize into a note
MemoryOversized CLAUDE.mdMove details to rules or docs

Use /context, /compact, /clear, and /memory Differently

/context shows what is consuming the window. /compact summarizes the current conversation so you can continue. /clear starts a fresh conversation when the task boundary is real. /memory shows loaded CLAUDE.md, local memory, rules, and auto memory entries.

/context all
/compact focus on files changed, failing tests, and next command
/clear
/memory

Set a Context Budget Before the Task

Before a serious task, give Claude the objective, files in scope, out-of-scope areas, completion criteria, and verification commands. Do not ask it to read an entire repository when a focused rg search and two files would do.

# narrow discovery before asking Claude to read files
rg -n "getUserById|User not found|auth middleware" src tests
git diff --stat
npm test -- --runInBand

Copy-Paste Runbook for Long Work

Use this runbook before refactors, security fixes, long articles, or monetization experiments. It keeps the session narrow and leaves a receipt for the next pass.

## Task brief
- Objective:
- In scope:
- Out of scope:
- Files likely involved:
- Done when:
- Verification commands:

## Handoff receipt
- Changed files:
- Commands run:
- Result:
- Remaining risk:
- Next best action:

What Survives Compaction

After compaction, project-root CLAUDE.md and auto memory are re-injected. Nested CLAUDE.md files and path-scoped rules return only after matching files are read again. Instructions that exist only in conversation are the most fragile, so durable rules should move into files.

# CLAUDE.md

## Compact Instructions
- Keep the current business objective and monetization hypothesis.
- Keep changed files, verification commands, deploy state, and blockers.
- Drop raw logs unless a line explains the root cause.
- If article work is in progress, preserve slug, locale list, and quality gaps.

Three Use Cases: Code, Content, Conversion

  1. For a large refactor, delegate broad research to a subagent or separate session and return only the decision summary to the main implementation context.
  2. For publishing work, keep raw research in Obsidian, editorial rules in CLAUDE.md, and final MDX in the repository. This makes analytics-driven iteration easier.
  3. For conversion work, capture the metric, hypothesis, change, and verification result as a small ticket instead of dragging a week of chat history forward.

Common Failures and Fixes

  1. Failure 1: assuming /compact preserves every detail. It preserves a summary, not the entire transcript. Put durable constraints in CLAUDE.md or a handoff file.
  2. Failure 2: doing massive discovery before implementation. Summarize discovery into a small file, then start the implementation pass with only that summary and the files in scope.
  3. Failure 3: treating auto memory as shared team documentation. It is local memory. Shared conventions belong in committed CLAUDE.md or project docs.

How Obsidian Fits In

This workflow pairs naturally with CLAUDE.md best practices, token optimization guide, and prompt engineering guide. If your team uses notes heavily, also read Claude Code and Obsidian integration. For team setup help, use the training and consultation page.

PlaceBest information
CLAUDE.mdShort rules needed every session
ObsidianLong research, hypotheses, article ideas
MDX / docsPublished content, specs, handoff notes
Auto memoryLocal preferences and repeated learnings

What I Verified for This Article

For this update I checked the current context window, commands, and memory docs and removed older guidance that centered everything on /cost. The article now focuses on /usage, /context, /compact, and /memory as separate tools. Official references: context window, commands, memory, and common workflows.

#claude-code #context management #token optimization #productivity
Free

Free PDF: Claude Code Cheatsheet

Enter your email and download the one-page Claude Code cheatsheet for commands, review habits, and safe workflows.

We handle your data with care and never send spam.

Level up your Claude Code workflow

Start with the free PDF, use Gumroad guides when you need repeatable workflows, and book consultation when rollout or revenue paths need human judgment.

Masa

About the Author

Masa

Engineer focused on practical Claude Code workflows. Runs claudecode-lab.com, a 10-language technical media site.