> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Stream session events with the Devin SDK

> Consume every Devin session update as one typed SessionEvent union in the Devin SDK, identical for cloud and local sessions.

Every event is a member of one discriminated union, `SessionEvent`, so a `switch` on
`event.type` narrows it. Tool calls carry a normalized `detail` that says which tool it is and
what it was given, the same for local and cloud sessions:

```ts theme={null}
for await (const event of session.run("Explain three uses for a coding agent SDK")) {
  switch (event.type) {
    case "message_delta":
      process.stdout.write(event.text);
      break;
    case "thought_delta":
      break; // Devin's reasoning, if you want to show it
    case "tool_call": {
      const { detail, status } = event.call;
      if (detail.tool === "exec") console.log(`$ ${detail.command ?? ""}`, status, detail.exitCode);
      if (detail.tool === "edit") console.log("edited", detail.path);
      if (detail.tool === "mcp") console.log("mcp", detail.server, detail.name);
      break;
    }
    case "plan":
      console.log(event.entries.filter((e) => e.status !== "completed"));
      break;
  }
}
```

## Tool calls, the same on both agents

The local CLI and the cloud describe tools differently on the wire (typed `rawInput` and
`cognition.ai/inferenceToolName` locally; `cognition.ai/eventType` plus `_meta` details such as
`cognition.ai/command` and `cognition.ai/fileUpdates` on the cloud). `ToolCall.detail` normalizes
both into one discriminated union — `exec`, `read`, `write`, `edit`, `list_directory`,
`file_search`, `mcp`, `permission_request`, `ask_user_question`, `computer_use`, `report_blocker`,
or `other` — so consumers narrow on `detail.tool` and never see the difference. `computer_use`
(added in `0.0.1-beta.2`) is Devin driving its browser or desktop on the cloud; `detail.actions`
lists the typed actions it took (`key`, `type`, `screenshot`, …). The raw `rawInput`, `meta`,
`toolName` and `inferenceToolName` stay on the call for anything the union does not cover.

## Cognition extension notifications

Cognition-specific events (`_cognition.ai/*` notifications — agent stop causes, context
compaction, connection retries, …) are surfaced as a typed union via `session.onExtension`:

```ts theme={null}
import { CognitionExtensionMethod, isExtension } from "@cognition-ai/sdk";

session.onExtension = (notification) => {
  if (isExtension(notification, CognitionExtensionMethod.AgentStopped)) {
    console.log(notification.cause, notification.stats);
  }
};
```

The same event stream is what you get from a session you did not start; see
[Watch a session](https://docs.devin.ai/sdk/guides/watching-sessions.md). The [quickstart example](https://docs.devin.ai/sdk/examples/quickstart.md)
switches over every event type in one file.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.