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
TheProviderService 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 theProviderAdapterShape 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
TheCodexAdapter implements provider support for Codex:
1
Process Management
Spawns and manages
codex app-server child processes via CodexAppServerManager2
JSON-RPC Communication
Handles JSON-RPC protocol over stdio for session and turn operations
3
Event Transformation
Transforms Codex notifications into standardized
ProviderRuntimeEvent format4
Session Directory Integration
Registers sessions with
ProviderSessionDirectory for tracking and routingCodex-Specific Features
Account Detection
Account Detection
Detects Codex account type and plan to determine model availability:
Model Normalization
Model Normalization
Normalizes model slugs and applies account-based restrictions:
Collaboration Modes
Collaboration Modes
Supports Codex-specific collaboration modes (default and plan):
Resume Fallback Logic
Resume Fallback Logic
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
TheProviderSessionDirectory 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
TheProviderAdapterRegistry 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 startup4
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:- Decouples provider protocols from client expectations
- Enables consistent event replay and debugging
- Supports multiple concurrent provider sessions
- Facilitates event sourcing and audit trails
Best Practices
Isolate Provider Logic
Keep provider-specific code in adapters, not in
ProviderServiceUse 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
TheProviderHealth 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
