Key Takeaway
Context exhaustion is the number one reason Claude Code sessions fail silently. When context usage crosses 50 percent, Claude enters what practitioners call the agent dumb zone: it starts forgetting earlier instructions, repeating work, and making decisions that contradict earlier context. The fix is manual compaction at 50 percent usage. Run /compact to summarize the conversation and reclaim context space. This single habit is worth more than any other productivity technique in this guide.
Context Management: The Critical Skill
Every Claude Code session has a finite context window. Everything that happens in the session consumes tokens from this window: your prompts, Claude's responses, file reads, tool outputs, error messages, and CLAUDE.md loading. Once the window is full, the oldest content is evicted and Claude literally forgets it happened. This is not a minor inconvenience. It means Claude will re-read files it already analyzed, contradict decisions it already made, and lose track of multi-step plans.
The context usage indicator in the Claude Code interface shows your current usage as a percentage. Learning to read this indicator and act on it is the single most important productivity skill for power users. Below 30 percent, you have plenty of room. Between 30 and 50 percent, start thinking about whether to compact. At 50 percent, compact immediately. Above 70 percent, the session is degraded and you should start a new one for any complex task.
Context Usage Zones
| Usage | Zone | Action | Symptoms if Ignored |
|---|---|---|---|
| 0-30% | Green zone | Work freely. Full reasoning capacity available. | None |
| 30-50% | Yellow zone | Plan your remaining work. Consider compacting if more complex tasks remain. | Slight repetition in responses |
| 50% | Compact trigger | Run /compact immediately. This is non-negotiable for quality output. | Instructions from early in the session start being forgotten |
| 50-70% | Orange zone | Only continue if task is nearly complete. Consider starting fresh. | Contradicts earlier decisions, re-reads files, forgets plan steps |
| 70%+ | Red zone | Start a new session for any non-trivial work. Current session is unreliable. | Significant quality degradation, circular reasoning, lost context |
| 95%+ | Critical | Session is effectively dead. Auto-compaction may trigger but quality is already gone. | Claude may produce incoherent output or fail to complete tasks |
Auto-compaction triggers at 95 percent, but by that point the damage is done. The session has already been producing degraded output for thousands of tokens. Manual compaction at 50 percent is a proactive strategy. Auto-compaction is an emergency backstop. Do not rely on it.
Hooks: Automating Development Events
Hooks are scripts that Claude Code runs automatically when specific events occur during a session. They are configured in .claude/settings.json under the hooks key. Each hook targets one of 16 lifecycle events and runs a command or sends a prompt. Hooks are the automation glue that connects Claude Code to your existing development infrastructure.
There are two hook types. Command hooks run a shell command and are useful for side effects like sending notifications, updating dashboards, or triggering CI pipelines. Prompt hooks inject text into the conversation and are useful for adding context, reminders, or instructions at specific points in the workflow.
Hook Event Categories
The 16 hook events cover the full session lifecycle. PreToolUse and PostToolUse fire before and after any tool invocation, letting you validate inputs or process outputs. Notification fires when Claude wants to alert you. SessionStart and SessionStop bookend the entire session. Stop fires when Claude finishes a response turn. There are also events for specific tool types like PreEdit, PostEdit, PreBash, and PostBash that give you fine-grained control over file editing and command execution.
Hook exit codes control flow. Exit code 0 means continue normally. Exit code 1 means abort the operation, which is useful for PreToolUse hooks that validate inputs and want to prevent dangerous operations. Exit code 2 means the hook handled the event and Claude should skip its default behavior.
Practical Hook Examples
{
"hooks": {
"PreCommit": [
{
"type": "command",
"command": "pnpm --filter web check-types"
}
],
"PostToolUse": [
{
"type": "command",
"command": "echo \"Tool used: $TOOL_NAME at $(date)\" >> .claude/tool-log.txt",
"matcher": "Bash"
}
],
"Notification": [
{
"type": "command",
"command": "osascript -e 'display notification \"$MESSAGE\" with title \"Claude Code\"'"
}
],
"SessionStart": [
{
"type": "prompt",
"prompt": "Remember: always run check-types before creating any commit."
}
]
}
}Unlock the full Knowledge Base
This article continues for 34 more sections. Upgrade to Pro for full access to all 96 articles.
That's just $0.10 per article
- Full access to all blueprints, frameworks, and playbooks
- Interactive checklists with progress tracking
- Downloadable templates (.xlsx, .pptx, .docx)
- Quarterly Technology Radar updates