> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Gentleman-Programming/engram/llms.txt
> Use this file to discover all available pages before exploring further.

# mem_session_end

> Mark a coding session as completed

## Overview

Close a coding session and optionally attach a summary. This marks the session's `ended_at` timestamp and stores any provided summary text.

<Note>
  This tool is part of the **agent** profile and uses deferred loading.
</Note>

## Parameters

<ParamField path="id" type="string" required>
  Session identifier to close

  Must match the `id` used in `mem_session_start`. If the session doesn't exist, an error is returned.
</ParamField>

<ParamField path="summary" type="string">
  Summary of what was accomplished during the session

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

## Response

<ResponseField name="result" type="string">
  Confirmation message with session ID
</ResponseField>

**Example:**

```
Session "session-2026-03-03-1430" completed
```

## Usage Examples

### End Session Without Summary

```json theme={null}
{
  "id": "session-2026-03-03-1430"
}
```

**Response:**

```
Session "session-2026-03-03-1430" completed
```

### End Session With Summary

```json theme={null}
{
  "id": "opencode-abc123",
  "summary": "Added JWT authentication to API endpoints and updated login flow"
}
```

**Response:**

```
Session "opencode-abc123" completed
```

## Session End vs Session Summary

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

## Session Lifecycle

```mermaid theme={null}
graph LR
    A[mem_session_start] --> B[Work: mem_save, mem_search]
    B --> C[mem_session_summary<br/>detailed structured summary]
    C --> D[mem_session_end<br/>brief summary]
    style C fill:#a78bfa
    style D fill:#8b5cf6
```

## 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

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

## 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`.

## Recommended Workflow

```typescript theme={null}
// 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"
});
```

## Related Tools

* [`mem_session_start`](/mcp/mem-session-start) - Register session start
* [`mem_session_summary`](/mcp/mem-session-summary) - Save detailed structured summary
* [`mem_save`](/mcp/mem-save) - Save observations during session
* [`mem_context`](/mcp/mem-context) - Retrieve recent session context
