# SSE Streaming

**Last Updated:** 2025-01
**Confidence:** High

## Summary

Server-Sent Events (SSE) stream command output in real-time. Clients connect to a stream URL and receive output as it's produced.

**Key Facts:**
- Endpoint: `GET /projects/{id}/events/{stream_id}`
- Content-Type: `text/event-stream`
- Events: `output` (stdout/stderr), `done` (completion)
- In-memory stream publisher for current implementation
- Stream URLs returned from command execution endpoints

**File Pointers:**
- Handler: `internal/handlers/projects.go` (events endpoint)
- Publisher: `internal/adapter/memory/stream.go`
- Port: `internal/port/stream.go`

## Client Usage

```bash
curl -N -H "X-API-Key: $KEY" \
  "http://localhost:8080/projects/my-project/events/stream-123"
```

## Event Format

```
event: output
data: {"type": "stdout", "content": "Hello world\n"}

event: output
data: {"type": "stderr", "content": "Warning: ...\n"}

event: done
data: {"exit_code": 0, "duration_ms": 1234}
```

## Flow

1. Client calls `POST /projects/{id}/claude`
2. Response includes `stream_url`
3. Client connects to `stream_url` via SSE
4. Server streams output events as produced
5. `done` event signals completion

## Related Topics

- [Command Execution](./command-execution.md)
- [Project Service](../services/project-service.md)
