Made a chat UI for Claude Code and Codex without using their SDKs
I built a chat view on top of live Claude Code, Codex and Copilot terminals without an agent SDK or screen scraping, and hit a different trap in each CLI.
Try answering a coding agent from a phone screen. The terminal shrinks to a narrow strip of tiny letters, you pinch to read a diff, and one bad tap sends the wrong key.
Earlier this year I threw out my Telegram bot because reading a terminal screen into chat messages was guesswork. I built Kodosi to put the real terminal on my laptop and my phone. Then I used a remote terminal on my phone for a few days, and I wanted a chat view back.
That put me back in front of a problem I had talked myself out of solving once before. I wanted a chat UI on top of a running terminal agent without wrapping an SDK or scraping the screen.
Why I skipped the SDKs
If you build a chat UI for coding agents today, the normal move is to use the vendor’s SDK. You grab the Claude Agent SDK or the Codex SDK and have a demo by evening. Then you spend the rest of the year chasing the vendor’s CLI.
Every slash command, permission mode and resume flow that the CLI gives you for free becomes code you have to rebuild. People also already have subscriptions and config files wired into their own CLI. Moving them onto an SDK often forces separate API billing or bumps into personal-plan limits.
You lose the escape hatch too. When an agent hits an odd prompt, I want to flip back to the real shell and see what is running. In a pure SDK wrapper, you are stuck staring at your own spinner.
The other common shortcut is reading characters out of the terminal buffer and sending fake keystrokes back in. I tried that in my Telegram bot, and every layout tweak or spinner change in an agent update turns it into brittle regex work.
Watching a running CLI without breaking it
In Kodosi the agent stays inside its normal terminal, using your own account and shell. Beside it sits a small bridge that talks to whatever native hook or server interface the agent exposes. The bridge sends structured events to Kodosi’s host over a local socket. Replies and approvals travel back the same way.
Chat state rides as a sub-stream inside the terminal’s encrypted channel, sending a snapshot first and small updates after that. Both views point at one live process. Approve a command from your phone and the prompt on your laptop disappears. Type into the terminal and the message shows up in chat.
No two coding agents agree on how an external program should observe a live session, though. Wiring up four of them meant hitting a different set of quirks in each one.
Hooking Claude Code
Claude Code exposes a hooks system, so Kodosi ships a
547-line JavaScript hooks module (claude.js)
inside its plugin. When a session starts in Kodosi, the module reads a socket path from the
environment and sends recent history. It then long-polls the host for chat prompts and permission
answers.
The first surprise sits as a warning right at the top of claude.js: do not hook tool.call or
tool.run. Register either hook and Claude Code turns off backgrounding and live output streaming
for those tools. Watching the agent through the obvious hook breaks the agent.
Permission prompts had their own wrinkle because PermissionRequest arrives without a
tool_use_id, so chat couldn’t tell which tool call was waiting. The module catches the ID one step
earlier in tool.check, caches it by tool name and input, and joins the two events together.
Stopping a turn also behaved differently than I expected. Calling turn.abort stops Claude Code’s
turn, while shell commands it already started keep running in the background, tagged
backgroundedByTurnAbort. So Stop in chat watches PostToolUse for a full second and calls
TaskStop on each background task it finds. Commands like /clear and /resume also swap
conversations without firing session.start. Switching models from chat can even trigger a
cache-warming prompt in the terminal, where a phone user can’t see it.
Standing in front of Codex
OpenAI’s Codex has no plugin hooks at all. What it has is
codex app-server, a local
WebSocket server built for editors and external clients.
To keep the terminal working as usual, codex_link.rs
gives each terminal a local Unix socket address. When Codex connects, Kodosi inspects its flags and
environment, spawns a matching codex app-server, and forwards the bytes straight through. Then
Kodosi opens a second WebSocket to that server to watch events and send chat actions. If the chat
link drops, the byte proxy stays up so the terminal never notices.
That broke in an unexpected race: codex app-server records whichever client connects first as its
primary user agent. When Kodosi connected too quickly, it took that identity away from the terminal.
The fix is a 600-millisecond sleep before Kodosi dials its own socket, giving the terminal a head
start to introduce itself.
A promise that never resolves
GitHub Copilot CLI supports local extensions built on
the Copilot SDK. Kodosi’s
copilot.mjs calls
joinSession, subscribes to streaming events, and handles permissions and plan exits.
Node’s http.request doesn’t speak Unix domain sockets on Windows, so on Windows the host opens a
named pipe. Copilot also needs experimental features turned on to load extensions and per-folder
approval before an extension may answer prompts. Mid-turn messages caused trouble too. Kodosi sends
them into the running turn like Enter in the terminal, and Copilot’s abort wiped unread ones. Now
the bridge withdraws unread messages with queue.withdrawMessage before calling abort().
The oddest workaround came from having two live UIs on one prompt. Because Copilot shows a question
in both places at once, you might answer in the terminal while chat is still waiting. For
permissions, Copilot’s hook accepts { kind: 'no-result' } to defer to the terminal. Form prompts
and plan approvals had no equivalent return value, and returning a cancel object from chat would
fight the terminal. So the bridge returns a promise that never settles:
// Elicitation and plan-exit hooks have no "defer to terminal" result (unlike
// permissions' `no-result`), so returning a pending promise leaves the
// terminal in control. After the terminal's answer, Copilot takes no other.
const UNANSWERED = new Promise(() => {})
async function form(context) {
const answer = await wait('form', { message: context.message, requestedSchema: context.requestedSchema })
if (answer && answer.decision) return answer.decision
return answer && answer.closed ? { action: 'cancel' } : UNANSWERED
}
Once you answer in the terminal, Copilot takes that answer and ignores the hanging promise.
When the cleanest protocol isn’t allowed
Antigravity CLI’s terminal app has no extension API. It does speak the Agent Client Protocol, an open JSON-RPC standard from Zed meant to work like LSP for coding agents.
I wrote a bridge for it in acp.rs.
It spawns agy acp in the terminal’s folder and its own process group, so Ctrl+C cancels a turn
without killing the server. When sign-in comes up, Kodosi flips back to the terminal so you go
through the CLI’s own login flow.
Then I left auto-launch off. Google does not support embedding agy inside another app on personal
plans, so Kodosi opens Antigravity CLI in its normal terminal. The code worked, and a policy line
stopped it from shipping on by default.
| Agent | Native interface | Local link | Biggest catch |
|---|---|---|---|
| Claude Code | Plugin hooks module | Unix socket (HTTP) | Hooking tool.call breaks streaming; no tool ID on permission prompts |
| Codex | app-server proxy | Unix socket + 2nd WebSocket | 600 ms delay so the terminal connects first as primary client |
| Copilot CLI | CLI extension (joinSession) | Unix socket / Windows named pipe | No defer result on form hooks; needs new Promise(() => {}) |
| Antigravity CLI | Agent Client Protocol (ACP) | JSON-RPC over stdio | No TUI hook, and personal plans disallow embedding |
What four bridges cost
Keeping the real CLI means carrying a bridge and a Rust adapter for each agent, plus tests that replay real CLI sessions. Across the whole chat layer in Kodosi, that adds up to 11,456 lines of code.
| Item | Value |
|---|---|
| Claude Code (claude.js + claude.rs) | 2,176 lines |
| Codex (codex_link.rs + codex.rs) | 2,020 lines |
| Antigravity CLI (acp.rs + antigravity.rs) | 1,883 lines |
| Copilot CLI (copilot.mjs + copilot.rs) | 1,735 lines |
Every adapter parses incoming fields leniently so an unknown event or a missing field from a CLI update doesn’t crash the session. Once chat worked on phones, adding on-device voice was straightforward too, apart from one timing quirk. Recognized words lag a second or two behind your voice, so Kodosi times three seconds of silence from microphone loudness. It also pauses auto-send if the agent opens a question while you speak.
For day-to-day use, the trade paid off. On my laptop I still work in the real terminal. On my phone I tap Allow or dictate into chat, and my accounts stay with the CLIs. All the same, maintaining eleven thousand lines of translation code across four fast-moving tools gets tiring. If coding agents converge on one open protocol that keeps your terminal and account, I’d gladly throw most of this away.