The complete guide to Claude Code setup (Opus 4.6, Sonnet 4.6, Haiku 4.5). 1M token context window. 100+ hours saved. 25 hook events. Agent teams and task management. Production-tested patterns for skills, hooks, and MCP integration.
Four releases in four days (March 11-14, 2026) landed a cluster of features that change how sessions manage context, how worktrees handle large repos, and how MCP servers interact with users. This chapter covers each feature with practical configuration examples.
Context compaction discards old messages to free up space. The problem: compaction can drop critical instructions that were loaded at session start. The new PostCompact hook fires immediately after compaction completes, giving you a chance to reload anything important.
Session start: CLAUDE.md loaded, rules loaded, context full of instructions
...100 messages later...
Compaction: old messages removed, including those initial instructions
Result: Claude forgets project conventions mid-session
Add to .claude/settings.json (project) or ~/.claude/settings.json (global):
{
"hooks": {
"PostCompact": [
{
"hooks": [
{
"type": "command",
"command": "/home/you/.claude/hooks/post-compact-reload.sh"
}
]
}
]
}
}
Create ~/.claude/hooks/post-compact-reload.sh:
#!/bin/bash
# PostCompact Hook — Reload critical context after compaction
PROJECT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")
RELOAD_FILES=""
# Reload project instructions
[ -f "$PROJECT_ROOT/CLAUDE.md" ] && RELOAD_FILES="$RELOAD_FILES $PROJECT_ROOT/CLAUDE.md"
# Reload critical rules
for rule in "$PROJECT_ROOT/.claude/rules/"*.md; do
[ -f "$rule" ] && RELOAD_FILES="$RELOAD_FILES $rule"
done
if [ -n "$RELOAD_FILES" ]; then
echo "Reloaded context files after compaction:$RELOAD_FILES"
fi
exit 0
chmod +x ~/.claude/hooks/post-compact-reload.sh
| Hook | Fires | Use Case |
|---|---|---|
PreCompact |
Before compaction runs | Save state, warn about important context |
PostCompact |
After compaction ends | Reload critical files, re-inject rules |
Use both together for a complete compaction lifecycle: save before, restore after.
Set the model’s reasoning effort level within a running session.
/effort high # Maximum reasoning depth
/effort medium # Balanced (default)
/effort low # Fast responses, less reasoning
Like /model, this command works while Claude is actively responding – you do not need to wait for the current response to finish. The change takes effect on the next message.
| Level | Best For |
|---|---|
high |
Architecture decisions, complex debugging, code review |
medium |
General development, feature implementation |
low |
Simple lookups, formatting, file renaming |
Set a display name for the session at startup:
claude --name "feature/auth-refactor"
claude -n "hotfix-prod-db"
The name appears on the prompt bar. You can change it mid-session with /rename.
When working across multiple branches in separate terminals, session names prevent confusion:
# Terminal 1
cd ~/project && git checkout main
claude -n "main"
# Terminal 2
cd ~/project && git checkout feature/new-api
claude -n "feature/new-api"
# Terminal 3
cd ~/project && git checkout hotfix/auth-bug
claude -n "hotfix/auth-bug"
Each terminal’s prompt bar shows which branch context it belongs to.
For large monorepos using --worktree, the new worktree.sparsePaths setting limits which directories get checked out. This uses git sparse-checkout under the hood, avoiding the cost of cloning an entire monorepo into each worktree.
Add to .claude/settings.json:
{
"worktree": {
"sparsePaths": [
"packages/my-service/",
"packages/shared-lib/",
"configs/",
"package.json",
"tsconfig.json"
]
}
}
claude --worktree (or use EnterWorktree)sparsePaths are materialized| Repo Size | Use sparsePaths? | Why |
|---|---|---|
| < 1 GB | No | Full checkout is fast enough |
| 1-10 GB | Optional | Helps if you only touch a few packages |
| > 10 GB | Yes | Avoids multi-minute checkout and disk bloat |
{
"worktree": {
"sparsePaths": [
"packages/api/",
"packages/shared/",
"packages/types/",
"package.json",
"pnpm-lock.yaml",
"tsconfig.base.json",
".eslintrc.js"
]
}
}
This checks out three packages plus root config files, skipping packages/web/, packages/mobile/, and any other large directories you do not need.
MCP servers can now request structured input from the user mid-task. Previously, MCP tools could only receive input at invocation time. With elicitation, a tool can pause execution, ask the user a question, and resume with the answer.
| Hook | Fires | Use Case |
|---|---|---|
Elicitation |
When an MCP server requests user input | Log, filter, or auto-respond |
ElicitationResult |
After the user responds to the elicitation | Log responses, audit input patterns |
{
"hooks": {
"Elicitation": [
{
"hooks": [
{
"type": "command",
"command": "echo 'MCP elicitation requested' >> /tmp/mcp-elicitation.log"
}
]
}
]
}
}
The elicitation appears as a prompt in the Claude Code interface. The user responds, and the MCP server receives the answer to continue its operation.
Claude Opus 4.6 now defaults to a 1,000,000-token context window on Max, Team, and Enterprise plans. Previously, the 1M window required enabling extended thinking or extra usage allocation.
| Plan | Opus 4.6 Context | Before 2.1.75 |
|---|---|---|
| Max | 1M (default) | 200K default |
| Team | 1M (default) | 200K default |
| Enterprise | 1M (default) | 200K default |
| Pro | 200K | 200K |
/context command shows capacity based on the 1M limitNo configuration change is needed. The larger window activates automatically when using Opus 4.6 on a supported plan.
SessionEnd hooks previously had a hard-coded 1.5-second timeout. If your hook needed to write a session summary, sync to a remote service, or process observation logs, 1.5 seconds was often not enough.
Set the timeout via environment variable (in milliseconds):
# In ~/.bashrc or ~/.zshrc
export CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS=10000 # 10 seconds
| Hook Complexity | Timeout |
|---|---|
| Simple logging | 2000 (2s) |
| Git-based session summary | 5000 (5s) |
| Remote sync (Basic Memory, API) | 10000 (10s) |
| Heavy processing (AI compression) | 15000 (15s) |
If you use the auto-session-summary pattern from Chapter 51, increase the timeout to give git operations time to complete:
export CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS=8000
Without this, complex SessionEnd hooks silently fail when they exceed the default timeout.
By default, Claude Code stores auto-memory (the CLAUDE.md entries created by /memory and automatic observations) alongside your project. The autoMemoryDirectory setting lets you redirect this to a custom location.
Add to ~/.claude/settings.json (global) or .claude/settings.json (project):
{
"autoMemoryDirectory": "/home/you/claude-memory"
}
| Scenario | Directory | Why |
|---|---|---|
| Centralized memory | ~/claude-memory/ |
All projects write to one searchable location |
| Synced across machines | ~/Dropbox/claude-memory/ |
Memory available on multiple workstations |
| Separated from code | ~/.claude/auto-memory/ |
Keep memory out of git repos |
| Per-project (default) | (not set) | Memory stays in project directory |
If you use Basic Memory MCP, you can point autoMemoryDirectory to your Basic Memory content folder so auto-observations flow directly into the searchable knowledge base:
{
"autoMemoryDirectory": "/home/you/basic-memory/auto-observations"
}
The /context command now provides actionable diagnostics instead of just showing raw token counts.
Context-Heavy Tools: Identifies which tools are consuming the most context. If a single Bash output used 50K tokens, /context flags it.
Memory Bloat Detection: Warns when CLAUDE.md files, rules, or loaded skills are consuming a disproportionate share of the context window.
Capacity Warnings: Shows color-coded capacity status:
| Capacity Used | Status | Action |
|---|---|---|
| < 50% | Normal | No action needed |
| 50-75% | Moderate | Consider compacting soon |
| 75-90% | High | Compaction recommended |
| > 90% | Critical | Compaction imminent, reduce tool output |
Actionable Suggestions: Instead of just “context is 80% full,” the command now suggests specific actions: “Consider adding head_limit to Grep calls” or “3 rules files account for 15% of context – consider path-specific loading.”
Previously, if you used ToolSearch to fetch a deferred tool’s schema, compaction could discard the schema from context. The tool would appear available but fail on invocation. Fixed in 2.1.76 – deferred tool schemas are now preserved across compaction events.
Hebrew, Arabic, and other right-to-left scripts now render correctly in Claude Code’s terminal output. Previously, mixed LTR/RTL content could produce garbled display, particularly in code blocks containing RTL string literals.
When a background agent (launched via TaskCreate) is killed or times out, its partial results are now preserved and accessible via TaskGet. Previously, killing a background agent discarded all accumulated output.
Worktrees created by --worktree or EnterWorktree are now automatically cleaned up when the associated branch is deleted or the worktree directory becomes stale. Previously, orphaned worktrees accumulated on disk and required manual git worktree prune.
All settings from this chapter in one reference:
{
"hooks": {
"PostCompact": [
{
"hooks": [
{
"type": "command",
"command": "/home/you/.claude/hooks/post-compact-reload.sh"
}
]
}
]
},
"worktree": {
"sparsePaths": [
"packages/my-service/",
"packages/shared-lib/",
"configs/"
]
},
"autoMemoryDirectory": "/home/you/claude-memory"
}
Environment variables:
export CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS=8000
See Also: