# dispose

Shut the SDK session down and release the runtime's host resources.

`runtime.dispose()` shuts the SDK session down, waits for logged events to drain, and closes the runtime. It cancels in-flight host calls, model response bodies, and model sockets, and then calls `options.remote.dispose()`. Repeated calls return the same promise.

```ts title="host.ts"
import type { AgentRuntime } from 'nanocode-wasm'

declare const runtime: AgentRuntime

// 1. Unload only a quiescent session
if (await runtime.settle()) {
  // 2. Shut it down. Later commands reject.
  await runtime.dispose()
}
```

## Signature

```ts
// Idempotent
dispose(): Promise<void>
```

## Parameters

`dispose` takes no parameters.

## Returns

* **Type:** `Promise<void>`

Resolves after the runtime is closed. `closed` is then `true`, and pending commands reject with `agent runtime disposed`. A runtime that was never opened closes without the SDK shutdown.

```ts
import type { AgentRuntime } from 'nanocode-wasm'

declare const runtime: AgentRuntime

await runtime.dispose()
// true
console.log(runtime.closed)
```

## Errors

If the SDK shutdown fails, the runtime still closes and `options.remote.dispose()` still runs, and then the promise rejects with the shutdown error. A rejection from `options.remote.dispose()` also rejects the promise.

```ts
import type { AgentRuntime } from 'nanocode-wasm'

declare const runtime: AgentRuntime

// The runtime is closed whether or not this rejects
await runtime.dispose().catch(console.error)
```
