From latestaiagents
Manage Claude Agent SDK / Managed Agents sessions — creation, resumption, compaction, forking, and termination. Covers when to start fresh, when to resume, and how to handle context window pressure in long sessions. Use this skill when building multi-turn agents, debugging "my agent forgot the earlier context", or designing session retention policies. Activate when: agent session, session resume, conversation compaction, session fork, context window overflow, session lifecycle.
npx claudepluginhub latestaiagents/agent-skills --plugin skills-authoringThis skill uses the workspace's default tool permissions.
**A session is a durable conversation thread between user and agent. Manage it well and you avoid blown context windows, lost state, and confused users.**
Manages context window health in long Claude sessions: monitors triggers, assesses states, compresses stale content for subagents, recommends fresh starts to prevent degradation.
Manages Clawdbot/Moltbot agent session context via bash scripts: lists usage, generates AI summaries, compresses by resetting and injecting summaries. Use when nearing 70-80% context usage.
Manages Claude AI sub-agent sessions via agent-deck CLI: launch child sessions, check status, retrieve outputs, attach MCP tools like exa.
Share bugs, ideas, or general feedback.
A session is a durable conversation thread between user and agent. Manage it well and you avoid blown context windows, lost state, and confused users.
[idle] → [running] → [idle] # user sends → agent responds → waits
[idle] → [compacting] → [idle] # background context reduction
[idle] → [archived] # user/TTL-triggered
Sessions are long-lived. A single session can span hours to weeks with compaction keeping context in budget.
// SDK
const sessionId = crypto.randomUUID();
for await (const msg of query({ prompt: firstMessage, options: { sessionId } })) { /* ... */ }
// Managed
const session = await client.beta.sessions.create({ agent_id, metadata: { user_id } });
Always attach your own identifiers in metadata — user ID, tenant, feature flag — so you can filter and audit later.
// SDK
for await (const msg of query({ prompt: followUp, options: { resume: sessionId } })) { /* ... */ }
// Managed
await client.beta.sessions.messages.create({ session_id, content: followUp });
Resume when:
Don't resume when:
Starting fresh is free. Resuming a bad session is expensive.
When context approaches the model's limit, older messages are compressed into a summary. Two flavors:
Manual example (SDK):
await compactSession({
sessionId,
instruction: "Preserve every architectural decision and all file paths mentioned.",
});
Compaction is lossy. If something matters, pin it to memory (see the memory-tool skill) or re-inject it in the next user message.
Sometimes you want to explore a branch without polluting the main session:
const fork = await client.beta.sessions.fork({
source_session_id: session.id,
metadata: { purpose: "hypothesis-check" },
});
Both sessions share history up to the fork point, then diverge. Useful for:
await client.beta.sessions.archive({ session_id });
// Archived sessions are retained but not resumable without un-archive
Set retention policies:
Storage adds up at scale. Default retention may be longer than you need.
If compaction still can't fit context (rare but possible on huge sessions):
prompt-caching-ttl)metadata: {
user_id: "u-42",
tenant_id: "t-3",
thread_type: "support",
topic: "billing",
started_at: "2026-04-15T10:30:00Z",
feature_flag: "beta-v2",
}
This becomes your query surface. Use it for:
User starts on mobile, continues on web. Two options:
Prefer (1) unless you have strong reason — Managed handles concurrent writes with last-writer-wins; simple enough.