Session Hygiene & Plugin Management
CoreDesign content boundaries, schema output, session hygiene, and plugin management · Difficulty 2/5
Explanation
Session Hygiene
Because the Messages API is stateless and the context window is finite, what carries forward from turn to turn is a deliberate design decision, not an automatic default. Good Session hygiene means:
- Summarizing/compacting long threads instead of resending an ever-growing raw transcript
- **Starting a fresh Session** when context is polluted (dominated by stale, irrelevant, or noisy history) rather than continuing to build on a degraded thread
- Not letting stale tool output accumulate -- a large tool result that answered an earlier question doesn't need to ride along in every subsequent call
This is the same discipline as context curation generally, applied specifically to Session-level lifecycle decisions: when to keep going, when to compact, and when to cut over to a clean start.
Plugin Management
Connected extensions -- MCP servers, plugins -- need to be managed explicitly, not left as an implicit, undocumented set of capabilities:
- Which are enabled for a given Session or deployment
- What permissions they hold (least privilege matters here just as much as for any other tool access)
- Their versions (so an upstream plugin update doesn't silently change behavior)
Common exam traps
- Assuming a stateless API "just works" if you resend everything -- unbounded accumulation of history and tool output degrades quality even though nothing is technically wrong with the request.
- Continuing to patch a polluted Session with more instructions rather than recognizing that a fresh Session is sometimes the correct fix.
- Treating connected plugins/MCP servers as a fixed, install-once inventory rather than something that needs ongoing tracking of enablement, permissions, and version.
Key Takeaways
- Session hygiene means deliberately deciding what carries forward: compacting long threads, avoiding stale tool-output accumulation
- Starting a fresh session is sometimes the correct fix for a polluted context, not a failure to patch around
- Plugin/MCP server management means explicitly tracking which are enabled, their permissions, and their versions
- A stateless API resending everything without curation still degrades quality even though the request itself is valid
Glossary Terms
The practice of actively reducing a conversation's token footprint so it fits within the model's context window without silent truncation. Encompasses multiple strategies — rolling window eviction, progressive summarization, external storage with retrieval, and prompt caching — each with different loss profiles and complexity trade-offs. Understanding this menu of options, and knowing what must never be compressed, is a core Domain 5 skill.
A process that implements the MCP protocol and exposes tools, resources, and prompts to MCP clients. Built with official SDKs (Python, TypeScript). Deployed locally via stdio or remotely via StreamableHTTP. Claude Code auto-discovers servers configured in .mcp.json.
A stateful container in the Claude Agent SDK that holds an agent's conversation history, accumulated tool results, and metadata across multiple turns. Sessions can be persisted to durable storage, resumed after a process restart, and forked into independent branches. Session lifecycle management — not the model or tools — is what makes long-running agentic tasks recoverable.
A context management approach that condenses older conversation turns or completed task phases into compact summaries, preserving essential conclusions while freeing token budget. Inherently lossy — never summarize active tool results, in-flight constraints, or partially completed tasks. One specific technique under the broader umbrella of [context compression](/glossary/context-compression).
Related Concepts
Content Boundaries & Schema Design
Trusted instructions and untrusted data (user input, retrieved documents, tool output) must be kept separate and clearly delimited
Messages API Request Shape, stop_reason & usage
A Messages API request needs messages (alternating user/assistant), model, and required max_tokens; system and tools are optional