Skip to main content

Server Mode

Interact with TF Code over HTTP using the headless server.

Usage

tfcode serve [--port <number>] [--hostname <string>] [--cors <origin>]
FlagDescriptionDefault
--portPort to listen on0 (tries 4096)
--hostnameHostname to listen on127.0.0.1
--mdnsEnable mDNS discoveryfalse
--mdns-domainCustom domain name for mDNStfcode.local
--corsAdditional browser origins[]

Authentication

Set TFCODE_SERVER_PASSWORD for HTTP basic auth (username defaults to tfcode):

TFCODE_SERVER_PASSWORD=your-password tfcode serve

How It Works

When you start TF Code normally, it runs both a TUI and a server internally. The TUI is the client. The server exposes an OpenAPI 3.1 spec that also generates the JavaScript SDK.

Run tfcode serve for a standalone server, or tfcode web to start the server and open the web interface. Use tfcode attach http://localhost:4096 to connect a TUI to a running server.

OpenAPI Spec

http://<hostname>:<port>/doc

API Reference

Global

MethodPathDescription
GET/global/healthGet server health and version
GET/global/eventGet global events (SSE stream)

Project

MethodPathDescription
GET/projectList all projects
GET/project/currentGet current project

Config

MethodPathDescription
GET/configGet config info
PATCH/configUpdate config
GET/config/providersList providers and default models

Provider

MethodPathDescription
GET/providerList all providers
GET/provider/authGet provider authentication methods
POST/provider/{id}/oauth/authorizeAuthorize a provider using OAuth
POST/provider/{id}/oauth/callbackHandle OAuth callback for a provider

Sessions

MethodPathDescription
GET/sessionList all sessions
POST/sessionCreate a new session
GET/session/statusGet session status
GET/session/:idGet session details
DELETE/session/:idDelete a session
PATCH/session/:idUpdate session
POST/session/:id/abortAbort a running session
POST/session/:id/shareShare a session
DELETE/session/:id/shareUnshare a session
GET/session/:id/diffGet the diff for this session
POST/session/:id/revertRevert a message
POST/session/:id/unrevertRestore all reverted messages
POST/session/:id/permissions/:permissionIDRespond to a permission request

Messages

MethodPathDescription
GET/session/:id/messageList messages
POST/session/:id/messageSend a message and wait for response
POST/session/:id/prompt_asyncSend a message asynchronously
POST/session/:id/commandExecute a slash command

Files

MethodPathDescription
GET/find?pattern=<pat>Search for text in files
GET/find/file?query=<q>Find files by name
GET/file?path=<path>List files and directories
GET/file/content?path=<p>Read a file

MCP & Agents

MethodPathDescription
GET/mcpGet MCP server status
POST/mcpAdd MCP server dynamically
GET/agentList all available agents
GET/skillList all skills

Events

MethodPathDescription
GET/eventServer-sent events stream

Docs

MethodPathDescription
GET/docOpenAPI 3.1 specification (HTML)