session-lifecycle

session-lifecycle is a skill for Claude Code, Codex from latestaiagents/agent-skills. It costs 95 tokens per session (1,319 once invoked), scanned A, original, MIT.

A guide to managing durable agent conversations, including starting, resuming, compacting, forking, archiving, and ending sessions. A session is a conversation thread that can continue over time.

In plain words
What is it for?
Use it when designing multi-turn agent experiences, handling context pressure, choosing between resuming and forking, or setting session-retention rules.
Why use it?
It helps prevent lost context, oversized conversations, and confused users when agents work across many turns or days.

Skill for Claude CodeCodex

Part of the claude-agent-sdk plugin — 5 skills shipped together , and of latestaiagents

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/latestaiagents/agent-skills/session-lifecycle
Any agent
npx skills add latestaiagents/agent-skills --skill session-lifecycle
Clone the repo
git clone --depth 1 https://github.com/latestaiagents/agent-skills

Made for: Claude Code, Codex.

Or install claude-agent-sdk, the plugin that ships this one along with the rest of its 5 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for session-lifecycle

README.md
[![agentmods](https://agentmods.dev/badge/skills/latestaiagents/agent-skills/session-lifecycle.svg)](https://agentmods.dev/skills/latestaiagents/agent-skills/session-lifecycle)
Your own site
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/session-lifecycle"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/session-lifecycle.svg" alt="Measured on agentmods" height="20"></a>
Per session 95 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,319 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00095 $0.01319
Opus 5 $0.00048 $0.00660
Sonnet 5 $0.00019 $0.00264
Haiku 4.5 $0.00010 $0.00132

Measured yesterday against content hash 53098f1beb4d, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

session-lifecycle scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/claude-agent-sdk/session-lifecycle/SKILL.md · 173 lines

How it starts

The opening of the file, as written. The whole thing — 173 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Session Lifecycle

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.

When to Use

  • Designing multi-turn agent UX
  • Debugging context-loss or context-overflow
  • Choosing when to fork vs resume vs start fresh
  • Setting retention policies for session storage

Session States

[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.

Creating a Session

// 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.

Resuming

// 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:

  • Same user, same topic — preserve context
  • Debugging an earlier decision — replay state
  • Continuing a long-running workflow

When to Start Fresh

Don't resume when:

  • Topic changed completely (user pivoted to a new project)
  • Session has stale or incorrect state you can't prompt-correct
  • User logged in as a different identity
  • Context is so full that compaction would lose critical recent info

Starting fresh is free. Resuming a bad session is expensive.

Compaction

When context approaches the model's limit, older messages are compressed into a summary. Two flavors:

  1. Auto-compaction (Managed default, SDK opt-in): system summarizes older turns
  2. Manual compaction: your app triggers it, optionally with custom instructions

Read the full file on GitHub · 173 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 173 lines · 95 tokens per session scan A 53098f1beb4d

Subscribe to this mod's changes

session-lifecycle is a skill published in the GitHub repository latestaiagents/agent-skills (5 stars, last pushed 4mo ago), licensed MIT. It adds 95 tokens to every session and 1,319 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.