Skip to main content

Module callback

Module callback 

Source
Expand description

Event callback — a simple observe/filter hook for SDK consumers.

The EventCallback is invoked for each ThreadEvent before it is yielded from the stream. It can:

  • Observe events (return Some(event) unchanged)
  • Transform events (return Some(modified_event))
  • Filter events (return None to suppress)

§Processing order

The EventCallback runs after the hook system (crate::hooks). Events that are blocked or aborted by a hook never reach the EventCallback. The pipeline per event is:

  1. crate::hooks::dispatch_hook — async, classified, first-match
  2. EventCallback — sync, raw event (only if the hook did not block/abort)

§Example

use std::sync::Arc;
use codex_cli_sdk::callback::EventCallback;
use codex_cli_sdk::ThreadEvent;

// Log all events, pass them through unchanged:
let logger: EventCallback = Arc::new(|event: ThreadEvent| {
    eprintln!("received: {event:?}");
    Some(event)
});

// Filter out turn-started events:
let filter: EventCallback = Arc::new(|event: ThreadEvent| {
    match &event {
        ThreadEvent::TurnStarted => None,
        _ => Some(event),
    }
});

Functions§

apply_callback
Apply an event callback, or pass through if no callback is set.

Type Aliases§

EventCallback
Optional callback invoked for each event received from the CLI.