Manage Long-Running Claude Context with Compaction
Keep a long-running Claude session inside its context window: budget tokens, compact older history into summaries as the window fills, offload durable state to memory files, recall relevant detail on demand, and degrade gracefully on oversized inputs. Submit a single script or notebook for instant, rubric-based feedback.
3 hrs
Est. time
4
Outcomes
7
Rubric criteria
65%
Pass score
What you'll learn
Skills you'll have real reps in after shipping this.
See how it works
Compaction in action
When the window fills, older turns are summarized into a compact note and recent turns are kept verbatim, so the session stays bounded without losing the thread.
Durable memory beyond the window
Facts that must survive compaction live in a memory file, re-injected as a compact preamble, rather than in a history that gets summarized away.
The scenario
Your assistant holds long conversations and works through large documents. After enough turns it either crashes when the context overflows or quietly forgets the early part of the session. A naive fix (keep only the last N turns) throws away decisions made earlier that still matter.
You are going to manage the context deliberately: track how full the window is, compact older turns into summaries before it overflows, keep durable facts in a memory file, and pull the right detail back when it is needed, so the session can run indefinitely without losing the thread.
Your role
You are a Claude solutions architect responsible for long-running context. Your deliverable is one module that keeps a session inside the window through budgeting, compaction, and external memory, without losing important state.
Start the task to unlock the full brief
You'll get the step-by-step requirements, setup commands, the 7-criterion grading rubric, tips, and the ability to submit your solution for instant AI grading.
Free to start · submit when you're ready
Learning resources
What you'll build in this context compaction task
This is a build-and-submit task, not a guided lab. You keep a long-running Claude session inside its context window without crashing or forgetting: budget the tokens, compact older history into summaries as the window fills, offload durable facts to memory, and degrade gracefully when an input is too big. The deliverable is one Python module that can run a session indefinitely.
The skills here are what make a long-lived assistant reliable. You track how full the window is and act before it overflows, you summarize old turns while keeping recent ones verbatim, you persist the facts that must survive into a memory file, and you chunk oversized inputs instead of letting a single request blow the window. Then you prove the session still remembers what matters.
Grading is rubric-based and explainable. Your submission is scored against weighted criteria (SDK integration, context budgeting, compaction, external memory, graceful degradation, recall, and the demonstration) with per-criterion feedback quoted from your code. The pass threshold is 65 percent and you can resubmit. These are the context-management skills the Claude Certified Architect exam tests.