# checkpoint

Canonical URL: https://developers.iagenify.com/sdk/agent/events/checkpoint/
Language: en

`{ type: "checkpoint", n, files, durationMs }`

The workspace was photographed before your message. One per message, and the number is what rewind() takes.

Status: once per message · needs a session · never blocks

## Fields {#fields}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `n` | integer |  | This message's number in the session. `rewind(n)` goes back to just before it. |
| `files` | integer |  | How many files the point records. |
| `durationMs` | integer |  | How long the snapshot took. |

## When it is emitted {#when}

Before your message is added to the conversation, so it records the workspace **as it was** — the state a rewind returns to. It is the first event of a run.

## No event means no point {#silence}

| Why there is none | Consequence |
| --- | --- |
| The agent has no session (`memory` is off) | `rewind()` answers `session_required` |
| `checkpoints: false` | `rewind()` answers `checkpoints_disabled` |
| It is a subagent | A subagent keeps none |
| The snapshot could not be taken at all | The run continues, and that message cannot be returned to |

> **A failed snapshot never stops an answer**
>
> Going back is a comfort, not a requirement — so a store that cannot be written is skipped in silence rather than failing the run. Listening for this event is how an interface knows whether « go back to here » can be offered.

## What durationMs tells you {#duration}

A snapshot is content-addressed, so an unchanged workspace is nearly free — only the list is new. A duration that grows steadily means a lot of changed content per message; one that is large from the start means a large workspace.

## Offering it {#use}

```javascript
const points = [];

onEvent: (e) => {
  if (e.type === "checkpoint") points.push({ n: e.n, files: e.files });
};

// Later: await agent.checkpoints() for the full list, with what each one cannot undo
```

- [Checkpoints](/sdk/agent/checkpoints): The whole mechanism.
- [checkpoint_partial](/sdk/agent/events/checkpoint-partial): When it could not take everything.

```python
points = []

def on_event(event):
    if event["type"] == "checkpoint":
        points.append({"n": event["n"], "files": event["files"]})

# Later: agent.checkpoints() for the full list
```
