Engineering Notes
Tooling · March 18, 2026

TelePi: A Telegram Remote Control for the Pi Coding Agent

I have been using the Pi coding harness for a while now. It is probably the most AI-native coding harness available: just four tools, and everything else it can build by itself. After canceling Claude Code because I kept running into token limits, I doubled down on Pi and built my own remote control. But instead of a dedicated app, I chose Telegram — because I was already using it for my OpenClaw agent, and its dynamic buttons and slash commands make it a surprisingly good fit.

Why Pi, and why it matters for this story

Pi is a coding harness that takes a deliberately minimal approach: four core tools — read, write, edit, and bash — and everything else the agent can build for itself. That constraint is the feature. It means Pi does not try to be a framework or an IDE. It is a thin, composable layer between you and whatever model you want to use.

It also happens to be genuinely model agnostic. You can use any API-based model, or reuse your existing OpenAI or GitHub Copilot subscription. There is already a growing ecosystem of packages and extensions that anyone can install. But what matters most to me — and what made this project inevitable — is that no other coding harness gives you better control over the context window.

"As everybody who is serious about AI engineering knows: AI engineering is context engineering. Pi gives you more control over that than anything else I have used."

That context discipline is why I stayed with Pi after canceling Claude Code. Claude is an excellent model. But Claude Code's shared usage limits kept burning through budget in ways that felt wasteful for my architecture-first workflow. With Pi, I control exactly what goes into the context, which model handles each turn, and how sessions are structured. The only thing I was missing was a way to keep working when I stepped away from the terminal.

The idea: Telegram as a coding remote control

Anthropic solved this for Claude Code by building the Claude app — a dedicated mobile and desktop client that connects to the same backend. That is a reasonable approach when you own the entire stack. But I do not own a model provider. I own a workflow preference and a Telegram account.

Telegram was already my remote interface for OpenClaw, a separate agent I run for operational tasks. The bot API is mature. Inline keyboards give you dynamic buttons without building a custom UI. Slash commands map naturally to session operations. And the message format supports HTML, code blocks, and structured replies out of the box.

So the question became: can I bridge Pi's SDK to Telegram in a way that preserves full session context in both directions?

4
Core Pi tools
2
Hand-off directions
0
Context lost on switch

What TelePi actually does

TelePi is a Telegram bot that wraps Pi's AgentSession SDK. It is not a thin proxy. It manages real Pi sessions with full tool execution, model switching, and streaming responses — all accessible from Telegram's chat interface.

The core commands map to what you would expect:

  • /new — Create a session in any known workspace (shows a picker when you have multiple projects)
  • /sessions — Browse all sessions across all workspaces, grouped by project, with tap-to-switch
  • /model — Switch models on the fly via inline keyboard
  • /handback — Hand the session back to CLI (copies the exact resume command to your clipboard)
  • /abort — Cancel the current operation

But the part I care about most is the hand-off.

Bi-directional hand-off: no context lost

The hand-off works because Pi stores sessions as JSONL files under ~/.pi/agent/sessions/. That file is the single source of truth. When either side — CLI or Telegram — opens a session, it reconstructs the full message history from the JSONL entries. That means hand-off is lossless by design.

CLI → Telegram: Type /handoff in Pi CLI. The extension kills any running TelePi instance, launches TelePi pointed at your current session, and shuts down the CLI. Open Telegram and keep typing.

Telegram → CLI: Type /handback in Telegram. TelePi disposes the session and sends you the exact pi --session <path> command. On macOS, it is copied to your clipboard. Paste it in your terminal and you are back where you left off — including everything that happened on Telegram.

This is not a sync mechanism. There is no server in the middle. The JSONL file is the context, and whichever side opens it gets everything.

Cross-workspace awareness

One thing that surprised me about how useful this became: TelePi can see sessions from every project workspace. Pi stores sessions in directories keyed by the workspace path. TelePi uses SessionManager.listAll() to discover all of them.

That means from Telegram I can switch from a TelePi debugging session to an OpenClaw operational task to a website update — all without leaving the chat. Each switch re-scopes the coding tools to the correct project directory, so bash, read, write, and edit always operate in the right workspace.

Why not build an app?

The honest answer is that Telegram is already open. I already have notifications tuned, the keyboard is familiar, and the bot API gives me inline keyboards, typing indicators, and formatted HTML without writing a line of frontend code. Building a dedicated app would have meant solving distribution, push notifications, auth, and UI rendering — all problems Telegram has already solved.

There is also a philosophical alignment. Pi is minimal by design. Four tools. No framework. TelePi follows the same principle: it is a bridge, not a product. The session file is the product. Everything else is just a way to read and write to it.

Technical choices

TelePi is TypeScript, built on Grammy for the Telegram side and Pi's AgentSession SDK for the agent side. It runs as a simple Node process — no Docker required for local use, though there is a Docker setup for production with non-root containers and granular volume mounts.

Streaming responses use a debounced edit pattern: as the agent emits text deltas, TelePi accumulates them and edits the Telegram message every 1.5 seconds. This avoids Telegram's rate limits while still feeling responsive. Long responses that exceed Telegram's 4096-character limit are split across multiple messages automatically.

Tool execution shows up inline. Depending on your verbosity setting, you see either full tool output, summaries (bash ×2, read, edit), errors only, or nothing. The abort button appears as an inline keyboard button during streaming, so you can cancel from the chat without typing a command.

The broader point

TelePi exists because Pi's SDK made it straightforward to build. The AgentSession API, the SessionManager, the ModelRegistry — these are not internal implementation details. They are public, documented interfaces that third-party code can compose with. That is rare in the coding agent space.

Most coding agents are closed loops. You use their UI, their model, their context management. Pi is the opposite: it gives you the primitives and lets you build the interface that fits your workflow. TelePi is my interface. Someone else might build a Slack bridge, a web dashboard, or a voice interface. The session file does not care.

If you are interested in building something similar, TelePi is open source.