Complete guide to managing context window, compression, and conversation flow.
From claude-code-expertnpx claudepluginhub markus41/claude --plugin claude-code-expertThis skill uses the workspace's default tool permissions.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Complete guide to managing context window, compression, and conversation flow.
Claude Code manages a conversation context window that accumulates messages, tool calls, and results throughout a session.
// settings.json
{
"autoCompact": true,
"contextWindow": {
"compactThreshold": 0.8,
"warningThreshold": 0.9
}
}
/compact # General compression
/compact focus on authentication # Preserve auth-related context
What gets preserved:
What gets summarized/dropped:
/clear
Complete reset — use between unrelated tasks.
Offload research to sub-agents to keep main context clean:
// Instead of reading 20 files in main context:
Agent(subagent_type="Explore", prompt="Find all API endpoint definitions")
// The agent researches and returns a summary
// Main context only gets the summary, not all file contents
// Bad: Read entire large file
Read(file_path="/path/to/large-file.ts")
// Good: Read specific section
Read(file_path="/path/to/large-file.ts", offset=100, limit=50)
// Good: Search first, then read specific matches
Grep(pattern="function authenticate", path="/path/to/")
Long-running operations in background don't consume main context:
Agent(run_in_background=true, ...)
Bash(command="npm test", run_in_background=true)
| Tool | Context Impact | Mitigation |
|---|---|---|
| Read (large files) | Very High | Use offset/limit |
| Bash (verbose output) | High | Pipe through head/tail |
| Grep (many matches) | High | Use head_limit |
| Agent (results) | Medium-High | Agent summarizes internally |
| Tool | Context Impact |
|---|---|
| Glob | Low (just file paths) |
| Write | Low (content sent, not echoed back) |
| Edit | Low (just the diff) |
| TodoWrite | Very Low |
| AskUserQuestion | Very Low |
1. /clear (fresh start)
2. State the objective clearly
3. Claude researches and plans
4. Claude implements
5. Claude tests
6. Session ends
1. Task A work
2. /compact (preserve Task A context)
3. Task B work
4. /compact (preserve A+B context)
5. Task C work
6. ...
1. Spawn research agents (background)
2. Work on other tasks while agents research
3. Agents return summaries
4. Synthesize findings
5. Implement based on research
Claude Code can automatically save important context across sessions:
~/.claude/projects/<project>/memory/MEMORY.md — Auto-loaded# Disable auto-memory
export DISABLE_AUTOMEMORY=1
# Or in settings.json
{ "autoMemory": false }
/memory # View current memories
/memory add <text> # Add memory entry
/memory clear # Clear all memories
# In conversation
"Remember that we always use pnpm, not npm"
"Forget the previous instruction about yarn"
Shows current session costs:
/cost
Output includes:
/compact to reduce repeated contextclaude-haiku-4-5 for simple tasks (/model claude-haiku-4-5-20251001)Grep to find specific content instead of reading everything# Resume last conversation
claude --continue
claude -c
# Resume specific session
claude --resume <session-id>
# Set specific session ID
claude --session-id my-session-123
# Set conversation ID within session
claude --conversation-id conv-456
/clear for unrelated work/cost periodicallyrun_in_background for slow operations