Semantic events
Snapshots make UI state reliable. Semantic events make integrations simple.
const unsubscribe = surface.onEvent((event) => {
if (event.type === 'tool.completed') {
refreshBusinessState(event.conversationId);
}
});Event guarantees
Every event includes:
type: a product-shaped discriminant;seq: a surface-local monotonic sequence number;occurredAt: an ISO timestamp;origin:action,notification, orlifecycle;conversationIdwhen the event belongs to one conversation;- event-specific serializable data.
The matching snapshot mutation is applied before the event is emitted.
Event families
| Family | Examples |
|---|---|
| Surface | connection, ready/error, bootstrap, close |
| Authentication | account state, login progress/completion, logout |
| Catalogs | conversations, models, skills, plugins, permissions |
| Conversation | selection, settings, rename, archive/delete, history replacement and incremental prepends |
| Messages | add/update/complete/delete, generated media |
| Turns | start/complete/error, interruption, context compaction |
| Tools | start/progress/complete, confirmations, user input |
| File activity | read, edit, and create paths for host-owned navigation |
| Sub-agents | collaboration tool calls and agent activity for host-owned presentation |
| Plans and goals | plan updates, goal set/clear/status |
| Queues and diffs | queued prompts, git diff updates |
| Usage | context occupancy, attributed execution usage, and account rate limits |
| Remote control | connection status changes for host-owned native behavior |
Local usage accounting
Use conversation.executionUsageChanged for turn-key replacements, not contextUsage as a consumption metric. Store usage.execution only for observed starts, and retain null as unknown. Repeated observations replace the same turn; they are not increments. Conversations created through the SDK can attribute their first turn from a known zero baseline; resumed or forked conversations need a prior provider-counter observation when using public counters alone. Local hosts can enable originalHistoryUsage to replace these estimates with verified native per-turn counters, including compaction usage. The SDK checks the provider-supplied history path and conversation identity; unreadable or unsupported history leaves the existing evidence unchanged. The default is off for hosts whose provider files are not on the same filesystem. A terminal event carries the latest usage, but later corrections can invalidate it. Keep this revisable evidence local rather than sending irreversible usage totals.
For request-aware pricing, inspect usage.requestUsage. The current public app-server protocol reports status: 'unavailable' with requests: null: thread/turn counters cannot identify independently billable requests or their actual model and served tier. Keep that coverage unknown. Selected model/tier settings and local event timestamps do not supply missing request evidence. See the field capability matrix.
Account-wide summaries are separate: call readAccountUsage() explicitly for an account settings screen, never once per observing agent or as a sum of local turns. Use readRateLimits({ excludeResetCreditDetails: false }) for fresh earned-reset details. See execution usage and account reads for exact contracts.
For a confirmed reset action, call consumeRateLimitResetCredit() once with a key retained for that logical attempt, then explicitly re-read limits. A timeout or account change leaves the outcome uncertain; never automatically retry with a new key. See earned resets.
Conversation-scoped subscription
Node conversation handles filter the same stream by identity:
const conversation = surface.conversation(conversationId);
conversation.onEvent((event) => {
console.log(event.type, event.conversationId);
});Vue controller
useCodexSurface exposes the last event and a local subscription API:
const surface = useCodexSurface(rendererApi);
const stop = surface.onEvent((event) => {
if (event.type === 'turn.completed') celebrate();
});Vue scope disposal automatically unregisters the underlying renderer listeners. rendererApi may come from Electron preload or createCodexWebSurfaceClient(); event semantics are identical.
When to use which
- Render from snapshots.
- Use
conversation.historyPrependedfor progressive background hydration; each event contains only the newly materialized chronological batch. - Trigger business refreshes or analytics from semantic events.
- Use
file.activityto reveal or focus the full path in an app-owned sidebar; the SDK reports the operation but does not own file navigation. - Use
subagent.*to maintain an app-owned agent tree or workspace. The SDK exposes typed activity but deliberately provides no standard sub-agent UI. - Use
remoteControl.statusChangedwhen app-owned native behavior depends on whether Codex remote control is disabled, connecting, connected, or errored. - Never rebuild full conversation state by replaying events.
- Use
readConversationHistoryafter a history-replacement event when an integration needs the full historical payload.
See the event API, history guide, and remote-control guide.