packages/serverpod/skills/serverpod-sessions/SKILL.md
Serverpod session types, lifecycle, InternalSession, cleanup callbacks. Use when creating manual sessions, debugging session-closed errors, or understanding session lifecycle.
npx skillsauth add serverpod/serverpod serverpod-sessionsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A Session provides access to database, cache, storage, messages, passwords, and logging. The framework creates and closes sessions automatically; only InternalSession requires manual management. Do not store a request session for work that outlives the request/stream/future call.
| Type | Created for | Lifetime | | ---- | ----------- | -------- | | MethodCallSession | Endpoint methods | Single request | | WebCallSession | Web server routes | Single request | | MethodStreamSession | Stream methods | Stream duration | | StreamingSession | WebSocket connections | Connection duration | | FutureCallSession | Future calls | Task execution | | InternalSession | Manual creation | Until closed |
Always close in a finally block:
var session = await Serverpod.instance.createSession();
try {
await doWork(session);
} finally {
await session.close();
}
Unclosed sessions leak memory and never persist logs. Using a closed session throws StateError.
session.addWillCloseListener((session) async {
// Runs just before session closes (all session types)
});
Sessions close when the endpoint returns. Do not capture for later use:
// BAD — session already closed when callback runs
Timer(Duration(seconds: 5), () => user.updateLastSeen(session));
Fix: Use a future call (session.serverpod.futureCalls.callWithDelay(...)) or create a new InternalSession inside the callback and close it in finally.
development
Build highly distinctive, production-ready Flutter interfaces with exceptional design fidelity. Include this skill whenever a user requests Flutter widgets, screens, or full apps.
testing
Serverpod Authentication — Signing in users, verify if they are authenticated, assinging scopes (e.g., admin). Use when adding features that require the user to be signed in.
development
Serverpod web server (Relic) — REST APIs, webhooks, middleware, static files, server-rendered HTML, SPAs, Flutter web. Use when adding HTTP routes, serving web pages or web apps, intercepting requests, or working with the Relic web server.
tools
Serverpod overview — what it is, project structure, how to work with. Always use at least once when working with projects that use Serverpod.