Skip to main content
Providers are the bridge between T3 Code’s orchestration layer and external agent systems. The provider architecture uses a clean adapter pattern to enable multi-provider support while keeping provider-specific logic isolated.

Provider Architecture

The provider layer follows a hierarchical service architecture:
T3 Code is currently Codex-first, with support for additional providers (like Claude Code) reserved in the contracts and architecture.

Provider Service

The ProviderService acts as the unified facade for all provider operations:
apps/server/src/provider/Services/ProviderService.ts
ProviderService resolves provider adapters through ProviderAdapterRegistry, routes session-scoped calls via ProviderSessionDirectory, and exposes one unified provider event stream to callers.

Provider Adapter Contract

Each provider implements the ProviderAdapterShape interface:
apps/server/src/provider/Services/ProviderAdapter.ts

Provider Capabilities

Adapters declare their capabilities through static metadata:
Capabilities enable T3 Code to adapt its behavior based on provider limitations. For example, the UI can prompt for session restart when changing models if the provider requires it.

Codex Adapter

The CodexAdapter implements provider support for Codex:
1

Process Management

Spawns and manages codex app-server child processes via CodexAppServerManager
2

JSON-RPC Communication

Handles JSON-RPC protocol over stdio for session and turn operations
3

Event Transformation

Transforms Codex notifications into standardized ProviderRuntimeEvent format
4

Session Directory Integration

Registers sessions with ProviderSessionDirectory for tracking and routing

Codex-Specific Features

Detects Codex account type and plan to determine model availability:
Normalizes model slugs and applies account-based restrictions:
Supports Codex-specific collaboration modes (default and plan):
Implements intelligent thread resume with automatic fallback:

Provider Events

Providers emit events through a unified event stream:
packages/contracts/src/provider.ts

Event Kinds

session

Lifecycle events: connecting, ready, closed

notification

Provider activity: tool calls, message deltas, turn completion

request

Approval requests: command, file-read, file-change

error

Error events: session errors, protocol errors

Provider Session Directory

The ProviderSessionDirectory tracks active sessions across all providers:
The session directory maintains an in-memory registry of active sessions, enabling quick lookups and routing without database queries.

Provider Adapter Registry

The ProviderAdapterRegistry resolves provider kinds to concrete adapters:

Adding New Providers

To add a new provider adapter:
1

Update Contracts

Add the provider to ProviderKind literal in packages/contracts/src/orchestration.ts:
2

Implement Adapter

Create a new adapter implementing ProviderAdapterShape<TError>:
3

Register Adapter

Register the adapter with ProviderAdapterRegistry during server startup
4

Update UI

Add provider selection and configuration UI in the web app

Provider Errors

Providers use typed errors for robust error handling:
apps/server/src/provider/Errors.ts
Using Effect’s typed errors enables exhaustive error handling and better debugging at the call site.

Event Projection

Provider events are projected into orchestration domain events:
This projection:
  1. Decouples provider protocols from client expectations
  2. Enables consistent event replay and debugging
  3. Supports multiple concurrent provider sessions
  4. Facilitates event sourcing and audit trails

Best Practices

Isolate Provider Logic

Keep provider-specific code in adapters, not in ProviderService

Use Typed Errors

Define specific error types for each provider to enable precise error handling

Emit Rich Events

Include sufficient context in events for debugging and replay

Handle Graceful Degradation

Implement fallback behavior for unsupported capabilities

Provider Health Monitoring

The ProviderHealth service monitors adapter availability:

Next Steps

Sessions

Learn about session lifecycle and management

Runtime Modes

Understand approval policies and security controls

Architecture

Explore the overall system design

API Reference

Browse the complete API documentation