---
title: Command Execution Sequence
---
sequenceDiagram
    participant C as Client
    participant H as Handler
    participant S as Service
    participant E as Executor
    participant P as Pod
    participant SM as StreamManager

    C->>H: POST /projects/{id}/claude
    H->>H: Validate request
    H->>S: ExecuteClaude(req)
    S->>S: Sanitize prompt
    S->>E: Execute(cmd, podName, outputFn)

    E->>P: kubectl exec
    activate P

    Note over C,SM: Client connects to SSE stream

    C->>H: GET /projects/{id}/events?stream_id=xxx
    H->>SM: Subscribe(streamID)
    SM-->>C: event: connected

    loop Output streaming
        P-->>E: stdout/stderr line
        E->>SM: Send("output", line)
        SM-->>C: event: output
    end

    P-->>E: exit code
    deactivate P

    E->>SM: Send("complete", result)
    SM-->>C: event: complete
    C->>C: Close SSE connection
