Context Window Strategy for Long-Running Agents

Context exhaustion is the #1 failure mode for long-running agents. Here's how to design around it.

The Context Problem

Claude Code has a finite context window. In a long-running session — hours of coding, many files read, many outputs generated — the context window fills up. When it does, either the agent stops working or (with amux) it auto-compacts. Auto-compact helps, but poorly structured sessions lose important context during compaction and produce lower-quality output afterward.

The solution is to design tasks and sessions so that context usage is efficient from the start — not treating compaction as a fix for poor session hygiene.

Task Scoping Rules

amux's Auto-Compact

When amux detects context exhaustion, it:

  1. Sends /compact to summarize the conversation
  2. Monitors for the summary confirmation
  3. Resumes the agent

This keeps agents running, but compacted context loses detail. After a compaction, agents are working from a summary, not the full conversation. Quality can drop. The goal is to design tasks that complete before compaction is needed.

Context Checkpointing Patterns

For genuinely long tasks that can't be broken up:

Get started with amux

Run dozens of Claude Code agents in parallel. Python 3 + tmux. Open source.

git clone https://github.com/mixpeek/amux && cd amux && ./install.sh
amux register myproject --dir ~/Dev/myproject --yolo
amux start myproject
amux serve  # → https://localhost:8822
View on GitHub