Tips & tricks10 min read

Context Management - Tips

SFEIR Institute•

TL;DR

Mastering context management in Claude Code transforms your productivity: you leverage every useful token, avoid memory loss, and scale your sessions across multiple terminals. Here are 18 actionable tips to optimize your context window, enable smart compaction, and make the most of Plan mode.

Mastering context management in Claude Code transforms your productivity: you leverage every useful token, avoid memory loss, and scale your sessions across multiple terminals. Here are 18 actionable tips to optimize your context window, enable smart compaction, and make the most of Plan mode.

Context management in Claude Code is the set of techniques that maximize the use of the 200,000 tokens available per session. Claude Code (v1.0.x, based on Claude Sonnet 4.6) offers one of the widest context windows on the market, but without an optimization strategy, you will fill it in less than 30 minutes of intensive work.

How does the 200k-token window work in Claude Code?

The context window is your Claude Code session's working memory. Visualize it as a circular buffer: every message sent, every file read, and every command result consumes tokens.

In practice, a 500-line TypeScript file takes up about 4,000 tokens. A detailed Claude response consumes between 1,500 and 3,000. You therefore have a real budget of roughly 50 complete exchanges before saturation.

ElementAverage tokens% of window
User message50-2000.1%
File read (300 lines)2,5001.25%
Full Claude response1,500-3,0001.5%
Bash command result500-5,0002.5%
CLAUDE.md loaded at boot800-2,0001%

the 200k-token window corresponds to approximately 150,000 English words or 120,000 French words. To dive deeper into the full mechanics, consult the context management deep dive that details each component.

Tip 1 - Monitor your consumption. The Claude Code status bar displays a fill indicator. When it exceeds 60%, consider compaction or a new session.

Tip 2 - Limit reading of large files. Use the --lines option or specify a range to read only the relevant lines: Read file.ts:50-120 instead of the entire file. You save 70% of tokens on a 400-line file.

Tip 3 - Prefer targeted grep over full reads. Rather than reading a file to search for a function, use Grep. In practice, a targeted search consumes 200 tokens versus 3,000 for a full file read.

Key takeaway: every token counts - measure your consumption and target your reads to maximize the number of productive exchanges.

What context optimization strategies should you apply daily?

Context optimization relies on a simple principle: inject only the information necessary for the current task. You will find complementary techniques in the context optimization guide dedicated to this topic.

Tip 4 - Structure your CLAUDE.md sparingly. This file is loaded every session. Keep it under 100 lines (roughly 800 tokens). Move specific instructions into separate .claude/ files that Claude Code loads on demand.

Tip 5 - Use concise and precise prompts. A well-crafted 20-word prompt produces better results than a 150-word paragraph. In practice, replacing "Could you please look at file X and tell me what's wrong with function Y" with "Fix the bug in X:functionY" reduces consumption by 60%.

# Bad: verbose prompt
claude "I would like you to look at the file src/auth.ts and analyze the login function to find why it doesn't work correctly when the user enters a wrong password"

# Good: targeted prompt
claude "Fix the error handling bug in src/auth.ts:login"

Tip 6 - Group related modifications in a single request. Instead of asking for 5 separate modifications on a React component, describe all 5 changes in one message. You save the context tokens accumulated between each exchange.

Tip 7 - Avoid verbose command outputs. Redirect the output of long commands into a file then read only the relevant lines.

# Instead of letting Claude ingest 10,000 lines of logs
npm test 2>&1 | head -50

users who apply these strategies maintain productive sessions 3 times longer on average.

StrategyTokens savedDifficulty
Concise prompts30-60%Easy
Targeted reads50-70%Easy
Optimized CLAUDE.md10-15%Medium
Grouped modifications40-50%Medium
Filtered results60-80%Easy

Key takeaway: focus each message on the essentials - a surgical prompt is worth more than a lengthy explanation.

How does Plan mode save tokens?

Plan mode is a Claude Code feature that separates the thinking phase from the execution phase. Activate it with the /plan command or the Shift+Tab shortcut to toggle between modes. You will find other shortcuts in the essential slash commands tips.

In Plan mode, Claude Code analyzes your request and proposes a strategy without executing any actions. This separation reduces token waste on unnecessary attempts.

Tip 8 - Activate Plan mode for complex tasks. Before a refactoring that touches more than 3 files, switch to Plan mode. Claude Code will propose a structured plan that you validate before execution. Result: 40% tokens saved compared to a direct exploratory approach.

Tip 9 - Use Plan to explore an unfamiliar codebase. When approaching a new project, Plan mode lets you get a map without Claude Code reading every file. Ask: "Plan: which files do I need to modify to add OAuth authentication?"

# Switch to Plan mode from the session
> /plan

# Claude Code analyzes and proposes without executing
# You validate or adjust before any action

Tip 10 - Combine Plan with CLAUDE.md instructions. Write your architectural constraints in CLAUDE.md so that Plan mode respects them automatically. In practice, a directive "Never modify files in the core/ directory" prevents Claude Code from proposing plans that touch that directory.

To learn how to formulate your first prompts effectively, consult the tips for your first conversations with Claude Code.

Key takeaway: Plan mode is your best ally for multi-file tasks - plan first, execute second.

How does automatic compaction work in Claude Code?

Automatic compaction is the mechanism by which Claude Code summarizes old exchanges to free up space in the context window. Trigger it manually with /compact or let it activate automatically beyond 80% fill.

The compaction process preserves key decisions, modified files, and persistent instructions, while removing intermediate details. A typical compaction reduces context by 60 to 70%.

Tip 11 - Configure a custom compaction threshold. By default, compaction triggers at 80%. You can lower this threshold to 60% in your settings if you prefer more responsive sessions.

// .claude/settings.json
{
  "contextCompaction": {
    "autoThreshold": 0.6,
    "preserveLastN": 5
  }
}

Tip 12 - Use PreCompact hooks to save critical context. PreCompact hooks run a script before each compaction. Create a hook that exports the current state into a summary file.

#!/bin/bash
# .claude/hooks/pre-compact.sh
echo "=== Session compacted $(date) ===" >> .claude/session-log.md
echo "Modified files: $(git diff --name-only)" >> .claude/session-log.md

To configure other advanced hooks, explore the headless mode and CI/CD tips that cover complete automation.

Tip 13 - Add a summary message before compaction. Before running /compact, write a recap message: "Summary: I modified auth.ts and user.ts to add JWT validation. Next step: unit tests." This message will be preserved and guide Claude Code after compaction.

ActionContext beforeContext afterPreserved
Standard compaction180k tokens55k tokensDecisions + files
Compaction with summary180k tokens60k tokensSummary + decisions
Compaction with hook180k tokens55k tokensExternal log + summary

You can dive deeper into these mechanisms in the context management tutorial with hands-on exercises.

Key takeaway: compaction is your safety net - customize its threshold and save critical context via PreCompact hooks.

Can you use multiple Claude Code sessions in parallel?

Multi-sessions is a horizontal scaling strategy where you run multiple Claude Code instances simultaneously on the same project. Each session has its own 200k-token window, multiplying your total capacity.

Tip 14 - Dedicate one session per functional domain. Open one terminal for the backend, another for the frontend, and a third for tests. Each session maintains a specialized context without cross-pollution.

# Terminal 1 - Backend
cd /project && claude "Focus on src/api/"

# Terminal 2 - Frontend
cd /project && claude "Focus on src/components/"

# Terminal 3 - Tests
cd /project && claude "Run and fix the tests"

Tip 15 - Share context between sessions via files. Create a .claude/shared-context.md file that each session can read. Record architectural decisions made in one session so that others benefit from them.

In practice, 3 parallel sessions on a 50,000-line project allow covering the entire codebase without saturating any window. multi-sessions reduces refactoring time by 45% on projects with more than 100 files.

Tip 16 - Use Git worktrees to isolate sessions. Create a worktree per working branch. Each Claude Code session operates on a distinct directory, eliminating file conflicts.

# Create worktrees for parallel work
git worktree add ../project-feature-auth feature/auth
git worktree add ../project-feature-ui feature/ui

# Launch Claude Code on each worktree
cd ../project-feature-auth && claude

For advanced workflows with MCP (Model Context Protocol), you can connect your sessions to shared context servers.

Key takeaway: multi-sessions transforms Claude Code into a parallel team - isolate each domain and share decisions via common files.

What pitfalls should you avoid in context management?

Certain common practices waste your context window without you realizing it. Identify these anti-patterns to eliminate them from your workflow. You will find complementary recommendations in the advanced best practices for Claude Code.

Tip 17 - Never start a message with "do you remember..." Claude Code has access to the entire session context. Restating information already present wastes tokens. Reference directly: "Continue the auth.ts refactoring" rather than "Do you remember that we had started refactoring auth.ts with the new architecture..."

Tip 18 - Do not paste entire logs into the chat. A 200-line stack trace consumes 1,600 tokens. Copy only the relevant error message (5-10 lines maximum) or redirect the log into a file that Claude Code will read in a targeted manner.

Anti-patternTokens wastedAlternative
"Do you remember..."100-300Direct reference
Pasting a complete log1,000-5,000Extract the key error
Re-reading an already-read file2,000-4,000Trust the context
Prompt of 150+ words200-400Prompt of 20-30 words
Asking for unnecessary explanations1,500-3,000Ask only for the action

To go further on custom commands and skills, you can create shortcuts that encapsulate your optimized workflows.

Key takeaway: every wasted token is one fewer productive exchange - eliminate redundancies and trust the already-loaded context.

How to structure a long session to avoid losing anything?

A long session (over 2 hours) requires a context conservation strategy. Plan your compaction checkpoints and transitions between sessions. The complete context management guide covers all of these strategies in detail.

Tip - Break your work into 30-minute sprints. Each sprint corresponds to a specific feature or fix. Between sprints, run /compact with an explicit summary. This approach maintains 85% performance over 4-hour sessions.

Tip - Export your state before leaving. At the end of a session, ask Claude Code to summarize decisions made, files modified, and remaining tasks. Save this summary in a .claude/session-handoff.md file that the next session can load.

<!-- .claude/session-handoff.md -->
## Session state - February 20, 2026

### Decisions made
- Architecture: JWT with refresh tokens
- Database: PostgreSQL 16 with Drizzle ORM

### Modified files
- src/auth/login.ts (validation added)
- src/middleware/jwt.ts (new file)

### Next steps
- Write tests for login.ts
- Implement the /refresh endpoint

According to SFEIR Institute trainers, developers who use handoff files reduce their session resumption time by 75%. The Claude Code one-day training teaches you these productivity techniques with hands-on labs.

To go further, the AI-Augmented Developer 2-day training covers complete integration into your development workflow, and the AI-Augmented Developer - Advanced one-day training covers multi-agent strategies and horizontal scaling for teams.

Key takeaway: a long session is managed like a project - split into sprints, compact regularly, and document the state for resumption.


Recommended training

Claude Code Training

Master Claude Code with our expert instructors. Practical, hands-on training directly applicable to your projects.

View program