Overview
The T3 Code WebSocket API provides real-time communication between the web client and the Node.js server. The protocol uses a JSON-RPC-style request/response pattern with additional push events for server-initiated updates.Connection
Connect to the WebSocket server at the configured port (default: 3773):Authentication
If an auth token is configured, include it as a query parameter:Message Format
Request/Response Pattern
All client-initiated requests follow this structure:Unique request identifier for matching responses
Request body containing the method tag and parameters
Method name identifier (e.g.,
"orchestration.dispatchCommand")Request Example
Response Format
The server responds with either a success or error result:Matches the request ID
The successful result data (present on success)
Error details (present on failure)
Success Response Example
Error Response Example
Push Events
The server sends push events without a corresponding request. Push events are used for real-time updates:Always
"push" for server-initiated messagesEvent channel name (e.g.,
"orchestration.domainEvent")Event payload specific to the channel
Push Event Example
Available Methods
The T3 Code WebSocket API exposes the following method namespaces:Orchestration Methods
Core orchestration and command dispatch:orchestration.getSnapshot- Get current read model snapshotorchestration.dispatchCommand- Dispatch a client commandorchestration.getTurnDiff- Get diff for a turn rangeorchestration.getFullThreadDiff- Get full thread difforchestration.replayEvents- Replay events from a sequence
Project Methods
Project and file operations:projects.list- List all projectsprojects.add- Add a new projectprojects.remove- Remove a projectprojects.searchEntries- Search project files/directoriesprojects.writeFile- Write content to a file
Git Methods
Version control operations:git.status- Get repository statusgit.pull- Pull changes from remotegit.listBranches- List all branchesgit.createBranch- Create a new branchgit.checkout- Switch branchesgit.init- Initialize a new repositorygit.createWorktree- Create a git worktreegit.removeWorktree- Remove a worktreegit.runStackedAction- Execute stacked git operations (commit, push, PR)
Terminal Methods
Interactive terminal sessions:terminal.open- Open a new terminal sessionterminal.write- Write input to terminalterminal.resize- Resize terminal dimensionsterminal.clear- Clear terminal outputterminal.restart- Restart a terminal sessionterminal.close- Close terminal session
Shell Methods
System integration:shell.openInEditor- Open directory in external editor
Server Methods
Server configuration and metadata:server.getConfig- Get server configurationserver.upsertKeybinding- Update keybinding configuration
All methods are defined in
packages/contracts/src/ws.ts and follow the request/response pattern described above.Available Channels
Real-time orchestration events (project/thread/session updates)See Events for detailed event types.
Terminal session output and state changes
Initial server greeting sent on connection
Server configuration changes (keybindings, provider status)
Protocol Schema
The WebSocket protocol is defined using Effect Schema in@t3tools/contracts:
Implementation Reference
The WebSocket server implementation can be found in:- Server:
apps/server/src/wsServer.ts:544-968 - Contracts:
packages/contracts/src/ws.ts - Client Integration:
apps/web/src/api/wsClient.ts
Best Practices
Generate Unique IDs
Use UUIDs or monotonic counters for request IDs to avoid collisions
Handle Connection Loss
Implement reconnection logic with exponential backoff
Validate Schemas
Use Effect Schema for runtime validation of all messages
Subscribe to Push Events
Listen for push events immediately after connection to avoid missing updates
Error Handling
Common error scenarios:| Error | Cause | Solution |
|---|---|---|
| Invalid request format | Malformed JSON or schema violation | Validate against WebSocketRequest schema |
| Unknown method | Method name not recognized | Check available methods in WS_METHODS |
| Unauthorized | Missing or invalid auth token | Include valid token in connection URL |
| Route request error | Business logic failure | Check error.message for details |
Next Steps
Orchestration API
Learn about orchestration commands and queries
Commands
Explore available command types
Events
Understand domain events
