Skip to main content

Overview

Close a coding session and optionally attach a summary. This marks the session’s ended_at timestamp and stores any provided summary text.
This tool is part of the agent profile and uses deferred loading.

Parameters

id
string
required
Session identifier to closeMust match the id used in mem_session_start. If the session doesn’t exist, an error is returned.
summary
string
Summary of what was accomplished during the sessionA brief description of the session’s work. For detailed summaries, use mem_session_summary instead, which creates a structured observation.This field is stored directly on the session record and is useful for quick session overviews.

Response

result
string
Confirmation message with session ID
Example:
Session "session-2026-03-03-1430" completed

Usage Examples

End Session Without Summary

{
  "id": "session-2026-03-03-1430"
}
Response:
Session "session-2026-03-03-1430" completed

End Session With Summary

{
  "id": "opencode-abc123",
  "summary": "Added JWT authentication to API endpoints and updated login flow"
}
Response:
Session "opencode-abc123" completed

Session End vs Session Summary

Two ways to summarize:
  1. mem_session_end with summary parameter (simple):
    • Stores a short summary on the session record
    • Good for brief overviews
    • Doesn’t create a searchable observation
  2. mem_session_summary (recommended for detailed work):
    • Creates a structured observation with Goal/Instructions/Discoveries/Accomplished/Files format
    • Searchable via mem_search
    • Provides rich context for future sessions
    • Referenced 16 times across agent protocols
For significant work, use both: call mem_session_summary first, then mem_session_end with a brief summary.

Session Lifecycle

When to Use

  • Session completion: When the coding session is definitively over
  • Agent shutdown: Before the agent exits
  • Timeout/idle: When a session has been inactive and should close
  • Manual end: When using CLI or API to close a session

Idempotency

This tool is idempotent — calling it multiple times on the same session won’t cause errors. The ended_at timestamp and summary will be updated on subsequent calls.

What Gets Updated

The session record is updated with:
  • ended_at: ISO 8601 timestamp of when mem_session_end was called
  • summary: The summary text (if provided)
Previously saved observations and prompts associated with the session remain unchanged.

Error Handling

If the session ID doesn’t exist:
Failed to end session: session not found
Make sure to call mem_session_start before mem_session_end.
// 1. Start session
await mem_session_start({
  id: "session-123",
  project: "my-app"
});

// 2. Do work (save observations, search, etc.)
await mem_save({ ... });

// 3. Create structured summary (recommended for significant work)
await mem_session_summary({
  project: "my-app",
  session_id: "session-123",
  content: `## Goal\n...\n## Discoveries\n...`
});

// 4. End session with brief summary
await mem_session_end({
  id: "session-123",
  summary: "Implemented feature X and fixed bug Y"
});

Build docs developers (and LLMs) love