---
title: "Real-Time Notifications"
description: "Real-time notifications keep teams informed while an agent runs. You can stream progress to Slack, send email summaries, or call a webhook when milestones complete."
sidebar:
  label: "Real-time notifications"
seo:
  title: "Real-Time Notifications | Autohand Code Agent SDK"
  description: "Send real-time notifications from Autohand Code Agent SDK agents. Stream events to Slack, email, and webhooks as the agent works."
---

## Notification strategies

- **Stream events** - forward message\_update and tool\_end events to a channel for live progress.
- **Session summary** - collect output and send one message when the session ends.
- **Alerts** - watch for error and permission\_request events and notify operators immediately.

## Slack notification example

Send notifications from SDK events when you need routing or formatting logic, and use curl when a shell hook is enough.

```js title="JavaScript"
for await (const event of sdk.streamPrompt({ message: 'Deploy the api service' })) {
  if (event.type === 'session_end') {
    await fetch(process.env.SLACK_WEBHOOK, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ text: `Autohand completed in ${event.duration}ms.` })
    });
  }
}
```

```ts title="TypeScript"
for await (const event of sdk.streamPrompt({ message: 'Deploy the api service' })) {
  if (event.type === 'session_end') {
    await notifySlack({
      text: `Autohand completed in ${event.duration}ms.`,
      sessionId: event.sessionId
    });
  }
}
```

```python title="Python"
async for event in sdk.stream_prompt("Deploy the api service"):
    if event["type"] == "session_end":
        await notify_slack({
            "text": f"Autohand completed in {event['duration']}ms.",
            "session_id": event["session_id"],
        })
```

```go title="Go"
events, _ := sdk.StreamPrompt(ctx, "Deploy the api service")
for event := range events {
  if event.Type == "session_end" {
    notifySlack(ctx, fmt.Sprintf("Autohand completed in %dms.", event.Duration))
  }
}
```

```java title="Java"
sdk.streamPrompt("Deploy the api service").forEach(event -> {
  if (event.type().equals("session_end")) {
    slack.notify("Autohand completed in " + event.duration() + "ms.");
  }
});
```

```swift title="Swift"
for try await event in sdk.streamPrompt("Deploy the api service") {
    if event.type == .sessionEnd {
        try await slack.notify("Autohand completed in \(event.duration)ms.")
    }
}
```

```bash title="curl"
curl -X POST "$SLACK_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{"text":"Autohand session completed."}'
```

## Hooks versus SDK events

If you only need notifications, configure shell hooks in `.autohand/config.json`. Use SDK events when you need to transform the payload, route to different channels, or conditionally suppress messages.

## Best practices

- Batch rapid events to avoid rate limits.
- Include the session ID and a link to full logs in every message.
- Do not send secrets or file contents in notifications.
- Provide a quiet mode for sensitive sessions.
