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.
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 context | Why it gets heavy | Practical response |
|---|---|---|
| Conversation | Long discussion and side quests | Cut by task boundary |
| Files | Reading huge files whole | Search first, then read narrow ranges |
| Tool output | Long logs and repeated failures | Summarize into a note |
| Memory | Oversized CLAUDE.md | Move 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
- For a large refactor, delegate broad research to a subagent or separate session and return only the decision summary to the main implementation context.
- 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.
- 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
- Failure 1: assuming
/compactpreserves every detail. It preserves a summary, not the entire transcript. Put durable constraints in CLAUDE.md or a handoff file. - 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.
- 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.
| Place | Best information |
|---|---|
| CLAUDE.md | Short rules needed every session |
| Obsidian | Long research, hypotheses, article ideas |
| MDX / docs | Published content, specs, handoff notes |
| Auto memory | Local 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.
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.
About the Author
Masa
Engineer focused on practical Claude Code workflows. Runs claudecode-lab.com, a 10-language technical media site.
Related Posts
Claude Code Permission Receipt Pattern: Record Scope, Proof, and Rollback
A permission receipt pattern for Claude Code: allowed actions, approval boundaries, proof commands, rollback, and revenue CTA checks.
Safe Agent Harness Design for Claude Code and Codex: Permissions, Checks, and Rollback
Build a practical agent harness for Claude Code and Codex with policy, planning, verification, and recovery layers.
Claude Code Subagents: A Practical Guide to Safe Agent Delegation
Claude Code subagent guide for safe parallel article and code work: delegation rules, prompts, pitfalls, and checks.
Related Products
Claude Code Quick Reference Cheatsheet
A free one-page reference for daily Claude Code work.
Keep the essential commands, file-reference patterns, CLAUDE.md reminders, prompting habits, review cues, and debugging workflow notes next to your editor.
50 Battle-Tested Claude Code Prompt Templates
Copy, paste, ship. 50 production-ready prompts.
Use proven prompts for code review, refactoring, testing, documentation, debugging, architecture, and incident response.