Talk to the AI coding sessions running on your own computers from your Android phone.
selfchat connects a phone app to an already running assistant session — Claude Code, Codex desktop, or DeepSeek Harness — through a small relay server you host yourself. You type on the phone, the message is delivered into that exact session (with its context, tools and working directory), and the session's final answer comes back to the phone. Files travel both ways.
It is a personal tool: one relay, your devices, your sessions. There is no hosted service and no account system beyond the tokens in your own config file.
Android app ──HTTPS/WSS──▶ ┌────────────┐ ◀──WSS (outbound)── bridge ── Claude Code session
cloud_cli.py ─────────────▶ │ relay │ ◀──WSS (outbound)── bridge ── Codex desktop chat
│ (aiohttp + │ ◀──WSS (outbound)── bridge ── DeepSeek Harness session
│ SQLite) │
└────────────┘
- Features
- How it works
- Repository layout
- Requirements
- Try it on one machine
- Deploy the relay
- Connect a host session
- Use it
- Updating
- Security
- Limitations
- Legacy v1: direct TCP mode
- Development
- License
- Reaches the session you already have open. No new model client is created; the message lands in the chat you chose, and local use of that chat keeps working.
- Several sessions, several machines. Each connected session shows up in the app's session list with its name and online state. Every session has its own conversation history and queue.
- No inbound ports on your work machines. Bridges only make outbound connections to the relay. Only the relay needs to be reachable.
- Files in both directions. Attach files to a message from the phone; the assistant returns files by linking them in its answer.
- Durable delivery. Messages are queued while a session is busy or offline (24 hours by default), survive restarts of the relay, bridge and app, and are never silently run twice.
- Android app with chat bubbles, Markdown rendering of replies, upload progress, dark mode, and long-press to copy.
- Command-line client speaking the same protocol, for scripts and testing.
| Component | Runs on | Role |
|---|---|---|
Relay (server/cloud_server.py) |
A server reachable over HTTPS | Authenticates tokens, stores conversations, queued jobs and files in SQLite, routes each message to the right bridge. |
Bridge (bridge_common/runtime.mjs + one adapter per host) |
The machine where the assistant runs | Keeps an outbound WebSocket to the relay, journals every job to disk, hands the text to the host session and reports the final answer. |
| Host adapter | Same machine as the bridge | Knows how to put text into one kind of session and read its final answer: Claude Code (plugin hooks), Codex desktop (app tools pipe), DeepSeek Harness (plugin). |
Client (Android app, server/cloud_cli.py) |
Your phone or a terminal | Lists sessions, sends messages and files, shows results. |
- A credential is a token with a role:
client(phone, CLI) orbridge. Bridge credentials also carry abridge_id. All credentials of oneaccountshare that account's conversations. - A binding is one host session, named by a
bindingIdyou choose in the bridge config. Its identity is permanent: a different chat needs a newbindingId. - There is exactly one conversation per account and binding. Every message records both, so switching the visible session in the app never redirects a pending message.
- The client
POSTs the message (with an id it chose) to the relay, which stores it as a job in statequeued. - If the binding's bridge is connected, the relay sends the job over the WebSocket; the
bridge writes it to its journal and acknowledges →
dispatched/running. - The adapter delivers the text into the host session and waits for the session's final answer.
- The bridge uploads any files the answer refers to, then reports
completed(orfailed) with the answer text. The relay stores the result and notifies clients. - Clients read results from an event log by cursor, so nothing is lost if the push notification is missed.
If the bridge cannot tell whether the host ran a task (for example a crash after
submission), the job becomes unknown and that session's queue pauses. It is never
resubmitted automatically; you inspect the host and release the queue from the app or CLI.
- Claude Code. The
bridgechatplugin installs hooks. A backgroundStophook waits for the next queued message and wakes the idle session with it; when that turn ends, the same hook publishes the assistant's final message as the answer. If you type in the terminal while a phone task is running, the result is withheld and reported asCLAUDE_MIXED_INPUTrather than sending output that mixes two requests. - Codex desktop. The bridge is started from inside the target chat and uses the desktop app's tools pipe to submit a turn and read that turn's final output. It only works with app-tools proxy versions it recognises by fingerprint.
- DeepSeek Harness (DSH). A DSH plugin adds
/selfchat-on,/selfchat-statusand/selfchat-off; each enabled session gets its own isolated bridge.
- Phone → host: the app uploads the file to the relay, then the next message carries
it. The bridge downloads it (size and SHA-256 checked) into
<workdir>/.selfchat/<binding>/<message>/and appends the local path to the prompt. - Host → phone: any local file the final answer references with a Markdown link or
image, and that lies inside
workdirorallowedOutputDirs, is uploaded and shown as an attachment. Nothing else is scanned or sent.
The full wire format and recovery rules are in protocol/v2.md.
| Path | What it is |
|---|---|
server/cloud_server.py |
The v2 relay (aiohttp + SQLite). |
server/cloud_cli.py |
Command-line client for the relay. |
bridge_common/ |
Shared bridge runtime, start/stop/status control script, example config. |
bridgechat/ |
Claude Code plugin: hooks, /bridgechat:listen commands, cloud adapter. |
.claude-plugin/marketplace.json |
Makes this repository a Claude Code plugin marketplace. |
bridgechat_for_codex/ |
Codex desktop adapter, compatibility probe, local installer, skill. |
bridgechat_for_dsh/ |
DeepSeek Harness plugin and installer. |
android/ |
The Android app (plain Java; OkHttp is the only dependency). |
deploy/ |
Example Caddyfile and systemd unit for the relay. |
protocol/v2.md |
Relay protocol reference. |
docs/ |
Deployment notes and verification records. |
tests/ |
Python and Node test suites. |
server/selfchat_server.py, server/selfchat_cli.py |
Legacy v1 direct-TCP server and client. |
| Part | Needs |
|---|---|
| Relay | Python 3.11+, aiohttp, cryptography (server/requirements.txt); a reverse proxy with a TLS certificate your phone trusts. |
| Bridges | Node.js 22.13+ and npm ci at the repository root. The Claude Code hooks also need a python3 command (standard library only). |
| Android app | Android 8.0+ (API 26). To build: JDK 17+ and Android SDK 35, with Gradle 8.9+ or the bundled no-Gradle script. |
This runs the relay on loopback and attaches a Claude Code session, with no TLS and no phone. It is the quickest way to see the whole path working.
git clone <this repository> selfchat && cd selfchat
# 1. relay
python3 -m venv .venv && .venv/bin/pip install -r server/requirements.txt
.venv/bin/python server/cloud_server.py --config ~/.config/selfchat/credentials.local.json --init
.venv/bin/python server/cloud_server.py --config ~/.config/selfchat/credentials.local.json &
# 2. bridge dependencies and the Claude Code plugin
npm ci
claude plugin marketplace add "$PWD"
claude plugin install bridgechat@selfchatStart (or restart) a Claude Code session, then find its session id:
python3 bridgechat/bin/cloud_hook.py sessionsCreate ~/.config/selfchat/claude.local.json (use the claude-pc bridge token from the
credentials file, and absolute paths):
{
"server": "http://127.0.0.1:8765",
"token": "<claude-pc bridge token>",
"bindingId": "claude-demo",
"name": "Claude · demo",
"stateDir": "/home/you/.selfchat/bridges/claude-demo",
"workdir": "/home/you/selfchat-files",
"sessionId": "<session id from the previous command>"
}Start the bridge and send a message with the client token:
node bridge_common/control.mjs start claude ~/.config/selfchat/claude.local.json
node bridge_common/control.mjs status claude ~/.config/selfchat/claude.local.json # "state": "online"
export SELFCHAT_TOKEN=<client token>
.venv/bin/python server/cloud_cli.py --server http://127.0.0.1:8765 --list
.venv/bin/python server/cloud_cli.py --server http://127.0.0.1:8765 --binding claude-demo "hello"The message is delivered when the Claude Code session finishes its current turn (if the
session was idle when the plugin loaded, finish one turn in it first). The CLI prints the
job with "state": "completed" and the answer.
python3 -m venv .venv
.venv/bin/pip install -r server/requirements.txt
.venv/bin/python server/cloud_server.py --config /etc/selfchat/credentials.local.json --init--init writes a new file (it refuses to overwrite one) with mode 600, containing one
client token and three bridge tokens (claude-pc, codex-pc, dsh-pc):
{
"credentials": [
{"account": "personal", "role": "client", "token": "<64 hex chars>"},
{"account": "personal", "role": "bridge", "bridge_id": "claude-pc", "token": "<64 hex chars>"}
]
}- Give each device only its own token. The phone gets the
clienttoken; each bridge machine gets onebridgetoken. - For more machines, add
bridgeentries with a uniquebridge_idand a random token of at least 32 characters. For more phones, addcliententries. - Optional top-level keys:
max_file_size(bytes, default 128 MiB) andquota(bytes per account, default 2 GiB). - Restart the relay after editing the file.
.venv/bin/python server/cloud_server.py \
--config /etc/selfchat/credentials.local.json --data /var/lib/selfchat \
--host 127.0.0.1 --port 8765| Option | Default | Meaning |
|---|---|---|
--config |
required | Credentials file. |
--data |
~/.selfchat-cloud |
Directory for selfchat.sqlite3 and uploaded files. |
--host / --port |
127.0.0.1 / 8765 |
Listen address. Keep it on loopback behind a TLS proxy. |
--init |
Create the credentials file and exit. |
deploy/selfchat.service is a hardened systemd unit for a dedicated selfchat account
(/opt/selfchat, /etc/selfchat, /var/lib/selfchat). Without root you can run the same
command as a systemd user service and enable lingering (loginctl enable-linger) so it
starts at boot.
The Android app only accepts https:// addresses and only trusts certificates from public
certificate authorities, so a self-signed certificate will not work. Bridges also require
HTTPS unless the relay is on the same machine (loopback).
With a domain (simplest). Point DNS at the server and use Caddy, which obtains the
certificate itself. deploy/Caddyfile:
selfchat.example.com {
reverse_proxy 127.0.0.1:8765
}
With nginx. Any site with a valid certificate works; the proxy must pass WebSocket upgrades and allow large request bodies:
map $http_upgrade $selfchat_connection { default upgrade; '' close; }
server {
listen 443 ssl;
server_name selfchat.example.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/key.pem;
client_max_body_size 128m;
location / {
proxy_pass http://127.0.0.1:8765;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $selfchat_connection;
proxy_set_header Host $http_host;
proxy_request_buffering off;
proxy_buffering off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
}With only an IP address. Let's Encrypt issues short-lived certificates (about six
days) for IP addresses. With acme.sh 3.1+ and a web root served on port 80:
acme.sh --issue --server letsencrypt -d 203.0.113.10 -w /var/www/html \
--cert-profile shortlived --days 3
acme.sh --install-cert -d 203.0.113.10 \
--key-file /etc/nginx/ssl/selfchat/key.pem \
--fullchain-file /etc/nginx/ssl/selfchat/fullchain.pem \
--reloadcmd "systemctl reload nginx"Run acme.sh --cron at least daily so the certificate is renewed in time. Clients send no
server name when connecting to a bare IP, so if port 443 already serves another site, give
selfchat its own port (for example listen 8443 ssl;) and use
https://203.0.113.10:8443 as the server address. Remember to open that port in the
firewall.
Check from the phone's browser: the server address should show a plain 404: Not Found
page with no certificate warning. That 404 is the relay answering.
History and attachments are kept until you delete them; there is no automatic retention.
Back up the SQLite database together with the files directory. When the quota is
reached, new uploads are rejected and nothing old is removed.
Run npm ci once at the repository root. Then copy bridge_common/example.config.json
to a private file whose name ends in .local.json (that pattern is git-ignored).
| Key | Meaning |
|---|---|
server |
Relay origin, e.g. https://selfchat.example.com. Plain http:// is accepted only for localhost / 127.0.0.1. |
token |
This machine's bridge token (32+ characters). Never the phone's client token. |
bindingId |
Unique, permanent id for this one session: 1–100 letters, digits, _ or -. |
name |
Label shown in the app's session list. |
stateDir |
Absolute path for this binding's journal, status and log. One per binding. |
workdir |
Absolute path where incoming attachments are stored; reply file paths resolve against it. |
allowedOutputDirs |
Extra absolute directories from which the assistant may return files. |
timeoutMs |
How long to wait for an answer (default one hour, maximum 24 hours). |
sessionId |
Claude Code only: the session to attach to. |
Use a distinct bindingId and stateDir for every session, and do not reuse them for a
different chat. The control script is the same for Claude Code and Codex:
node bridge_common/control.mjs start claude|codex /absolute/config.local.json
node bridge_common/control.mjs status claude|codex /absolute/config.local.json
node bridge_common/control.mjs stop claude|codex /absolute/config.local.jsonstart only launches the background process. The bridge is ready when status shows
"state": "online" and "processAlive": true. Its log is <stateDir>/host.log.
-
Install the plugin from this repository's marketplace:
/plugin marketplace add /path/to/selfchat /plugin install bridgechat@selfchat /reload-pluginsOr from a shell:
claude plugin marketplace add /path/to/selfchatandclaude plugin install bridgechat@selfchat. -
In the session you want to reach, nothing needs to be typed: the plugin's
SessionStarthook records the session. List recorded sessions and copy the id:python3 bridgechat/bin/cloud_hook.py sessions
-
Put that id in the config as
sessionIdand start the bridge:node bridge_common/control.mjs start claude /absolute/claude.local.json
Notes:
- A message is delivered when the session's current turn ends. If the plugin was loaded while the session sat idle, finish one local turn to start the waiting hook.
- The bridge is bound to one session id. A new Claude Code session needs its own config
(
sessionId,bindingId,stateDir). - The session keeps its normal permission rules. A remote task that needs an approval waits at the terminal; there is no remote approval.
- State shared between hooks and bridge lives in
~/.bridgechat-cloud(override withSELFCHAT_CLAUDE_STATEfor the hooks andclaudeStateRootin the config; they must match). - Do not use the legacy
/bridgechat:listenqueue and the cloud bridge on the same session at the same time.
Run these from the intended Codex chat's own execution environment, because the bridge
inherits CODEX_THREAD_ID and the desktop tools pipe from it:
node bridgechat_for_codex/probe.mjs # read-only compatibility check
node bridge_common/control.mjs start codex /absolute/config.local.json
node bridge_common/control.mjs status codex /absolute/config.local.jsonnode bridgechat_for_codex/install-local.mjs https://selfchat.example.comregisters a local Codex skill that wraps these commands, so you can ask the chat to "enable selfchat". It copies no secrets; the whole checkout and itsnode_modulesmust stay in place.- The adapter only talks to app-tools proxy builds whose fingerprint it knows. After a Codex desktop upgrade the probe may report an unsupported version.
- Only the final output of a turn the bridge itself submitted is sent back. Mixed local and remote input, truncated output or an uncertain completion fail closed.
- Restarting the desktop app requires starting the bridge again from the chat.
node bridgechat_for_dsh/install.mjs /absolute/dsh/profile /absolute/config.local.jsonThe installer backs up the profile's patch file and adds one plugin row pointing at the config file. Reload DSH, then in the session you want to reach:
/selfchat-on /selfchat-status /selfchat-off
Each session gets its own runtime, with a binding id and state directory derived from the session's identity, so several sessions in one DSH host can be enabled independently. The installer targets the DSH 0.2.1-rc.5 plugin interfaces.
More host-specific detail is in docs/cloud-v2.md.
Build
cd android
./build.sh # Gradle 8.9+: app/build/outputs/apk/debug/app-debug.apk
./build-nogradle.sh # no Gradle: needs a JDK and the SDK build tools; build/selfchat.apkbuild-nogradle.sh looks for the SDK in $ANDROID_HOME or android/.android-sdk,
downloads OkHttp and its dependencies from Maven Central once, and signs with a local
debug key. An APK signed with a different key cannot update an installed copy; uninstall
the old app first.
Set up
- Install the APK and open the app. Enter the relay address (
https://…, no path) and theclienttoken under ⋮ → 云服务器设置. - Tap 切换会话 and pick a session. Online sessions are marked; an offline one still accepts messages, which wait until it reconnects or they expire.
Chat
- Type and press 发送. Your message shows its state underneath: waiting to send, queued, dispatched, running, done, failed.
- + uploads a file. It is listed above the input box as waiting, and is delivered with the next message you send (up to eight per message).
- Replies are rendered from Markdown. A reply with files shows an attachment chip; tap it to save a file through Android's document picker. ⋮ → 会话文件 lists every file of the conversation.
- Long-press a bubble to copy its text. Tap a queued message to cancel it.
- A message marked 结果待核实 means the bridge could not confirm what the host did. Check the session on the computer, then tap the message to release the queue.
- ⋮ → 旧版 TCP 客户端 opens the legacy v1 screen.
The interface text is currently Chinese. History is cached on the phone and synchronised again from the relay on reconnect.
server/cloud_cli.py reads the client token from the SELFCHAT_TOKEN environment
variable.
export SELFCHAT_TOKEN=<client token>
S=https://selfchat.example.com
python server/cloud_cli.py --server $S --list # sessions and their binding ids
python server/cloud_cli.py --server $S --binding BINDING "run the tests and summarise"
python server/cloud_cli.py --server $S --binding BINDING --put report.pdf "review this"
python server/cloud_cli.py --server $S --binding BINDING --files # files in the conversation
python server/cloud_cli.py --server $S --binding BINDING --get ATTACHMENT_ID --directory downloads
python server/cloud_cli.py --server $S --binding BINDING --cancel MESSAGE_ID
python server/cloud_cli.py --server $S --binding BINDING --resolve MESSAGE_ID --host-stopped-confirmedSending a message waits and prints the finished job as JSON. --put always sends a
message along with the files (a default text if you give none); it is not an upload-only
command.
Ask the assistant to save its output in the bridge's workdir (or a directory listed in
allowedOutputDirs) and to link it in the answer, for example
[report.pdf](/home/you/selfchat-files/report.pdf). The bridge uploads linked files and
the client shows them as attachments.
After pulling a new version:
| Changed | Do |
|---|---|
server/ |
Restart the relay. |
bridge_common/, bridgechat/cloud.mjs, Codex adapter |
control.mjs stop, wait for it to stop, start again (run npm ci first if package.json changed). |
| Claude Code plugin hooks or commands | /reload-plugins in each running session, or start a new one. /plugin marketplace update selfchat only if the marketplace file changed. |
android/ |
Rebuild and reinstall the app. |
Read this before exposing a relay to the Internet.
- A client token is remote control of your sessions. Whoever holds it can make every connected session do whatever that session is allowed to do on its machine, and can read the conversation history and files. Treat it like an SSH key.
- Not end-to-end encrypted. TLS ends at the relay (or its reverse proxy). The relay stores messages, results and files in plain form. Host it on a machine you trust.
- Tokens are compared in constant time, sent only in the
Authorizationheader or the first WebSocket frame, never in URLs. Rotate by editing the credentials file and restarting the relay. - Scope. A bridge token only receives jobs for its own bindings and can only fetch attachments of those conversations. Accounts cannot read each other's data.
- Files leaving a host must be explicitly referenced in the final answer and lie
inside
workdirorallowedOutputDirs. Point those at directories made for the purpose, not at your home directory. - Permissions are the host's. selfchat does not bypass or answer approval prompts. Conversely, a session configured to run without approvals will run remote requests without them too.
- Keep
*.local.jsonfiles private (mode 600); they are git-ignored by default.
- Final answers only: no streaming of partial output or tool activity.
- No remote approval of permission prompts, and no creating new sessions from the phone.
- A bridge attaches to one existing session; it does not follow you to a new chat.
- No exactly-once guarantee across the host boundary: uncertain outcomes are reported as
unknownand need a human decision. - Interrupted file transfers restart from the beginning.
- No automatic retention or cleanup on the relay.
- Android only; the app has not been through broad device testing.
- The Codex adapter depends on undocumented desktop internals and is gated to known versions.
The original version needs no relay: the phone connects straight to a small server on the machine running Claude Code. It is still included, for use on a LAN or over a VPN.
Android app ──TCP, AES-GCM──▶ selfchat_server.py ──▶ bridgechat send ──▶ Claude Code (listen mode)
-
Install the
bridgechatplugin as described above and run/bridgechat:listenin the session (/bridgechat:unlistenstops it). Check from a shell:python3 bridgechat/bin/bridgechat send "hello" # queues the message, prints the reply python3 bridgechat/bin/bridgechat status
-
Start the server (Python 3.9+ and
cryptography):python3 server/selfchat_server.py # listens on 0.0.0.0:8765 python3 server/selfchat_server.py --show-tokenOn first start it creates a random 16-byte token in
~/.selfchat/tokenand prints it as 32 hex characters. Options:--host,--port,--token-file,--new-token,--bridgechat PATH,--reply-timeout SECONDS,--workdir DIR,--max-file-size MIB. The server and the session must use the sameBRIDGECHAT_DIR(default~/.bridgechat). -
In the app open ⋮ → 旧版 TCP 客户端, then Server settings, and enter address, port and token. From a terminal:
python3 server/selfchat_cli.py "hello", or--put,--list,--getfor files in the server's working directory (~/selfchat-filesby default).
v1 protocol. Every frame is a 4-byte big-endian length followed by that many bytes.
The client sends "SELFCHAT1" plus 16 random bytes, the server answers with 16 random
bytes, and both derive two AES-128 keys with
HMAC-SHA256(token, "selfchat c2s"|"selfchat s2c" + client_nonce + server_nonce)[:16].
Every later frame is AES-128-GCM over UTF-8 JSON, with a per-direction frame counter as
nonce. The token is never sent. Messages are msg / ack / reply / error /
ping / pong, and files use file_put, file_data, file_end, file_saved,
file_get, file_start, file_list, file_abort, file_error with base64 chunks of at
most 192 KiB. There is no forward secrecy: if the token leaks, recorded sessions can be
decrypted.
pip install -r server/requirements.txt && npm ci
python -m unittest discover -s tests -p 'test_*.py' -v
npm testThe suites cover routing, account and session isolation, restart recovery, stale connection fencing, attachment scope, ambiguous completion, Claude hook ownership, Codex final-output filtering, DSH mixed-input handling, and a real relay-to-bridge attachment round trip with a fake host. They do not exercise a real model or a real phone; see docs/validation-v2.md for what has and has not been verified.
Reference documents: protocol/v2.md (wire format and recovery), docs/cloud-v2.md (deployment and host notes).
No license has been chosen yet. Until a LICENSE file is added, the code is published
for reading only and default copyright applies.