跳到正文
DEV Community· Theory·· 3 小時前AI 評分64

如何透過 iPhone 遠端使用不同 AI 編碼智能體與模型

Any Agent, Any Model: Run Your AI Coding Setup From an iPhone

AI 導讀

這套配置讓用戶把 AI 編碼智能體安裝在雲端 Linux 伺服器,再透過 iPhone 的 Termius 連線使用,毋須在 iOS 裝置本機運行。指南以 Claude Code、OpenAI Codex CLI、Google Gemini CLI 和 Aider 示範設定,並用 tmux 保留斷線後可重新連接的工作階段。

正文

Any Agent, Any Model: Run Your AI Coding Setup From an iPhone

The Mission

Run an AI coding agent from your iPhone using a cloud server. No laptop needed. Full terminal, full power, accessible from anywhere — the jobsite, the truck, home.

This is the vendor-neutral version of the pattern. I first wrote it up as a Claude Code guide, and Claude Code is still one of the examples below — but the setup itself doesn't belong to any one tool. The pieces are boring on purpose: a small cloud server is the computer, your phone is just the window into it, and your sessions live on the server so they survive every disconnect. Pick the agent you like, pick the model you like. The plumbing is the same.

The examples below use four real harnesses — Claude Code, OpenAI's Codex CLI, Google's Gemini CLI, and Aider — because they're the ones with public, documented install routes. The steps are written pattern-first: do the step generically, then take your harness's version of it.


What You'll Have When Done

  • A cloud server (a DigitalOcean droplet in NYC) that stays on when your phone doesn't
  • An AI coding agent installed and authenticated — your pick of harness and model
  • SSH access from your iPhone via Termius
  • Browser-based terminal access (optional)
  • Persistent sessions that survive disconnects
  • MCP browser tools so your agent can browse the web
  • A standing context file, so your agent already knows your work when a session starts
  • Your codebase cloned and ready to build

Total monthly cost: ~$6–36/mo for most people (server + one agent subscription, or pay-per-use API credit). It can run lower — even $0 for the model itself — if you go the local-model route in Part 5.
First 2 months: The droplet is free via the $200 DigitalOcean signup credit.


Part 1: Choose Your Cloud Server

Why You Need a Cloud Server

AI coding agents require a real Linux environment with process spawning, filesystem access, and streaming API calls. iOS is sandboxed and can't run them natively. The workaround is the whole idea: install the agent on a remote server and SSH in from your phone.

Provider Comparison

Provider Cheapest Useful Plan US Datacenter Best For
DigitalOcean $6/mo (1 vCPU, 1GB, 25GB SSD) NYC, SF, Atlanta Simplest UI, $200 free credit
Vultr $6/mo (1 vCPU, 1GB, 25GB NVMe) NJ, NY, Atlanta, Miami NVMe storage, more US locations
Hetzner ~$4/mo (2 vCPU, 4GB, 40GB NVMe) EU only (cheapest tier) Best specs per dollar, but higher latency from US
GitHub Codespaces Free (120 core-hours/mo) N/A (cloud) Zero cost, but limited hours

Recommended: DigitalOcean — simplest setup, $200 free credit covers 12+ months of a $16/mo droplet, NYC datacenter gives low latency from the US East Coast.


Part 2: Create the DigitalOcean Droplet

Step 1: Sign Up

  1. Go to digitalocean.com (not the sponsored Google results — scroll past the ads)
  2. Create an account
  3. Claim the $200 free credit (60-day trial)
  4. Add a payment method (required to activate, won't be charged until credit runs out)

Step 2: Create Droplet

On the "Create Droplets" page, configure:

Setting Value
Region New York — NYC1
Image Ubuntu 24.04 (LTS) x64
Droplet Type Shared CPU → Basic
CPU Options Premium Intel (NVMe SSD)
Plan $16/mo — 2 vCPU, 2GB RAM, 70GB NVMe, 2TB transfer
Authentication SSH Key (not password — see Part 3)
Backups Skip (your code lives in Git)
Monitoring Check the free monitoring box
Managed Database Skip the $15/mo add-on
Hostname Something memorable like tradestack-dev

What NOT to Select

  • Don't pick the $32/mo plan (overkill for a dev terminal box)
  • Don't use password authentication (SSH keys are more secure and easier from Termius)
  • Don't add the managed database (you'll install PostgreSQL directly on the droplet)

Part 3: Set Up Termius on iPhone

Termius is the SSH client you'll use to connect to your droplet from your phone. It doesn't care which agent runs on the other end — it's just the door.

Step 1: Install Termius

Download Termius from the App Store (free tier works fine).

Step 2: Generate an SSH Key

  1. Open Termius → tap Vaults tab (bottom left)
  2. Tap Keychain
  3. Tap the + button → Generate Key
  4. Name it something like tradestack-do
  5. Leave defaults (ED25519 or RSA) → tap Save

Step 3: Copy the Public Key to DigitalOcean

  1. Tap the key you just created
  2. Tap Export to Clipboard (copy the public key)
  3. Go back to the DigitalOcean droplet creation page in Safari
  4. Under "Authentication" → select SSH Key → paste your public key
  5. Finish creating the droplet
  6. Copy the IP address DigitalOcean gives you

Step 4: Add Your Droplet as a Host

  1. In Termius → tap Hosts → tap +
  2. Fill in:
    • Hostname: your droplet IP address
    • Username: root
    • SSH Key: select the key you generated (tradestack-do)
    • Leave Password blank
  3. Tap the blue checkmark to save

Step 5: Connect

Tap the host to SSH in. You should see a root@your-hostname:~# prompt.


Part 4: Server Setup + Install Your Agent

Once you're SSH'd into your droplet, set up a persistent session first so you don't lose progress if your phone disconnects:

apt update && apt upgrade -y
apt install -y tmux git curl wget htop unzip build-essential
tmux new -s setup

Install Node.js 20

Some agents install themselves without Node (Claude Code's native installer, for one), but several harnesses ship as npm packages, and you'll want Node for your own projects either way:

curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
node -v  # Should show v20.x

Install Your Agent

The step is the same everywhere: install the harness on the server, verify it runs, fix the PATH if the shell can't find it. Take your pick — install one, or install two and compare; they coexist fine.

Claude Code (Anthropic) — native installer:

curl -fsSL https://claude.ai/install.sh | bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
claude --version

Codex CLI (OpenAI) — npm package:

npm i -g @openai/codex
codex --version

Gemini CLI (Google) — npm package:

npm i -g @google/gemini-cli
gemini --version

Aider (open source, model-flexible) — Python:

python -m pip install aider-install
aider --version

(pip install aider-chat is the other documented route to the same tool.)

Whichever you picked, the check is identical: the version command answers, and the agent launches inside your tmux session. If the shell says "command not found," the install landed somewhere your PATH doesn't look — for npm packages that's the global npm bin folder; for Claude Code it's ~/.local/bin, which the export line above handles.

Install PostgreSQL (Optional, for Database Projects)

apt install -y postgresql postgresql-contrib
systemctl enable postgresql
systemctl start postgresql

Configure tmux

Create a tmux config for better phone terminal experience:

cat > ~/.tmux.conf << 'EOF'
set -g mouse on
set -g history-limit 50000
set -g status-bg colour235
set -g status-fg colour136
set -g status-left '#[fg=green]#S '
set -g status-right '#[fg=yellow]%H:%M '
bind | split-window -h
bind - split-window -v
set -g detach-on-destroy off
EOF

Harden SSH + Firewall

# Disable password auth (SSH keys only)
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd

# Enable firewall
ufw allow OpenSSH
ufw --force enable

Part 5: Authenticate Your Agent

Every harness needs to know whose models it's spending. There are three routes, and most harnesses offer at least two of them. Pick one per harness — you can mix routes across harnesses on the same server.

Option A: Subscription Sign-In (Simplest if it works)

Several harnesses let you sign in with a subscription account instead of an API key — flat monthly cost, no per-token meter. Claude Code signs in with a Claude Pro or Max account. Codex CLI signs in with a ChatGPT account. The flow is the same shape everywhere:

  1. Run the agent in your terminal
  2. It will display a long sign-in URL (or open a sign-in flow)
  3. Long-press the URL in Termius to copy it
  4. Open Safari → paste the entire URL (make sure nothing gets cut off)
  5. Log in with your subscription account
  6. Copy the auth code back to the terminal prompt, if it gives you one

Common issue: The URL is very long and can get truncated when copying. If you get an "invalid request" error from the sign-in page, the URL was cut off. Try again, or use Option B.

Option B: API Key (Works with Everything)

The universal route: every major model provider issues API keys, and every harness accepts them, usually through an environment variable. This is pay-per-use — powerful, and the meter is always running.

  1. Open Safari → go to your provider's console (Anthropic, OpenAI, and Google AI Studio all issue keys)
  2. Sign in → find API Keys → create a new key
  3. Copy the key
  4. Back in Termius, set the variable your harness reads:
export ANTHROPIC_API_KEY=<your key>    # Claude Code / Aider with Claude models
export OPENAI_API_KEY=<your key>       # Codex CLI / Aider with OpenAI models
export GEMINI_API_KEY=<your key>       # Gemini CLI / Aider with Gemini models

Important: When pasting an API key, make sure your phone keyboard doesn't insert spaces in the middle of the key. Use the Termius text input bar at the bottom for cleaner pasting.

  1. Save the ones you use permanently, the same way as any other environment variable:
echo 'export ANTHROPIC_API_KEY=<your key>' >> ~/.bashrc
source ~/.bashrc

Option C: Local Models — Turn the Meter Off

If the harness accepts a custom or OpenAI-compatible model endpoint, you can point it at a model you run yourself with Ollama, and no API bill ever arrives. Aider documents Ollama support directly, and endpoint-flexible harnesses follow the same pattern:

curl -fsSL https://ollama.com/install.sh | sh
ollama pull qwen3-coder

Then configure your harness to use the local endpoint and that model name — each harness keeps this in its own settings, so follow its docs for the exact field.

Honest limits: a $6–16 droplet cannot run a serious coding model. The local route makes sense on a bigger server or on a machine at home that your droplet can reach. What it buys you is real: private code never leaves your hardware, and the per-token meter is gone. What it costs you is frontier-level capability on the hardest work. Plenty of people run both — a frontier model for the hard jobs, a local model for everything else.

What It Costs to Authenticate

  • Subscription: one flat plan per vendor you use (Claude Pro is $20/mo, Max runs $100–200/mo; ChatGPT plans cover Codex sign-in) — predictable, no per-token math
  • API keys: pay-per-use at each provider's published per-token rates — cheap for light use, unbounded for heavy use
  • Local models: $0 in model fees; you pay for the hardware that runs them

None of these routes cares that you're connecting from a phone. The server is authenticated once; you just visit it.


Part 6: The Context Layer + Clone Your Project

Installing the agent gets you a smart stranger. The context layer is what turns it into your agent: standing instructions it reads every session, so you stop re-explaining your work every time you connect.

Step 1: Give Your Agent a Standing Instruction File

Every major harness reads a standing instruction file at session start. The convention is the same; only the filename changes:

Harness Standing instruction file
Claude Code CLAUDE.md
Codex CLI AGENTS.md
Gemini CLI GEMINI.md
Aider A conventions file (e.g. CONVENTIONS.md) it is told to read

You keep one in your home folder for the system-level stuff — who you are, your projects, how you like work done — and the pattern some harnesses support is a global file plus a per-project file that overrides it. Write it once, in plain language: your name, what you're building, your rules, your preferences. Every session starts oriented instead of cold.

Step 2 (Optional, Deeper): A Full Personalization System

If you want more than a file — persistent memory, custom skills, goal tracking — frameworks exist that build that layer on top of a harness. The one I run is PAI (Personal AI Infrastructure), Daniel Miessler's open-source framework for Claude Code: think of the harness as the engine and the framework as everything that makes it yours. Its shape is worth copying in any harness:

  • Persistent memory — decisions and learnings carry across sessions
  • Custom skills — packaged instructions for the work you repeat
  • Goal orientation — your mission, beliefs, and strategies loaded into every session
  • Your context, in files you own — mission, beliefs, strategies, editable any time

Whatever harness you chose, build toward that shape: context in plain files, under your control, that the agent reads before it works.

Step 3: Clone Your Projects

mkdir -p ~/projects
cd ~/projects
git clone https://github.com/YOUR_USERNAME/your-repo.git
cd your-repo

For private repos, authenticate with a GitHub Personal Access Token (generate one at github.com/settings/tokens) and use it as the password when Git prompts during the clone.

Step 4: Orient Your Agent on the Codebase

Drop a project-level instruction file in the repo root — the same filename your harness reads (see the table above). It tells the agent about the project's architecture, conventions, tech stack, and current priorities. The global file handles who you are; the repo file handles what this project is.

Then launch the agent in the project folder and tell it: "Read the instruction files and orient on the codebase."

Context Layer + Your Project = Full Stack

  • Who you are — goals, mission, beliefs (from your global context)
  • What you're building — architecture, conventions, priorities (from the repo's file)
  • Persistent memory — what happened in past sessions carries forward, if your setup keeps it
  • One pattern, any harness — swap the agent and the context files still describe the same you

Part 7: Add Browser Access via MCP

MCP (Model Context Protocol) is a shared protocol — the same tool servers plug into many different harnesses, so this part is nearly identical no matter which agent you picked. The two most useful servers for a headless box: web browsing and URL fetching.

Add Playwright (Headless Browser)

Lets your agent navigate websites, fill forms, click buttons, take screenshots, and extract data — all without a display.

npm install -g @playwright/mcp
claude mcp add playwright -- npx @playwright/mcp@latest --headless

Add Fetch Tool

Lets your agent grab and read any URL:

apt install -y pipx
pipx install uv
claude mcp add fetch -- uvx mcp-server-fetch

A Note on Syntax

Those two claude mcp add commands are Claude Code's form. The server definitions underneath — a name, the command npx or uvx, and its arguments — are the portable part: other harnesses take the same definitions in their own MCP configuration (a settings file or their own add command). Copy the command and args, not the wrapper.

Restart Your Agent

After adding MCP servers, restart the agent session for them to load.

What This Unlocks

  • Browse documentation while building features
  • Test your web app's UI automatically
  • Scrape websites for research
  • Pull data from web services
  • Read API docs, Stack Overflow, GitHub issues

Part 8: Daily Workflow

Starting a Session

  1. Open Termius on your iPhone
  2. Tap your droplet host to connect
  3. Reattach to your session:
tmux attach -t setup
  1. You're right back where you left off — your agent, your project directory, everything intact

If Your Phone Disconnects

No problem. Your tmux session keeps running on the server. Just SSH back in and reattach:

tmux attach -t setup

This is the step that makes the whole setup field-proof: the signal drops in a stairwell, the agent never notices.

Starting Fresh

tmux new -s agent
cd ~/projects/your-repo
# launch your agent: claude, codex, gemini, or aider

tmux Cheat Sheet

Action Keys
Detach (leave session running) Ctrl+B then D
Split screen vertical Ctrl+B then `
Split screen horizontal {% raw %}Ctrl+B then -
New window Ctrl+B then C
Switch windows Ctrl+B then 0-9
Scroll up Ctrl+B then [ then arrow keys
Exit scroll mode Q
List all sessions tmux ls
Kill a session tmux kill-session -t name

Part 9: Optional — Browser-Based Terminal (ttyd)

If you want to access your terminal from any browser without Termius:

apt install -y ttyd

Run it with basic auth on a random port:

ttyd -p 9473 -c your_username:YourStrongPassword tmux attach -t setup

Then open Safari: http://YOUR_DROPLET_IP:9473

Security notes:

  • Use a random high port (not 80, 8080, etc.)
  • Always use the -c flag for basic authentication
  • Open the port in your firewall: ufw allow 9473/tcp
  • For production use, put it behind HTTPS with a reverse proxy

Part 10: Cost Breakdown

Item Monthly Cost Notes
Cloud server (DigitalOcean droplet) $6–16/mo Free for the first stretch via the $200 signup credit
Termius $0 Free tier is sufficient
Agent subscription (if you sign in with one) $20–200/mo Depends on vendor and plan — Claude Pro is $20/mo; heavier plans run more
API usage (if you use keys instead) Pay-per-use Each provider's published per-token rates; replaces the subscription line, doesn't stack on it
Local models (Ollama route) $0 in model fees You supply the hardware; needs more than the $6–16 droplet to be useful
Total ~$6–36/mo typical Server + one subscription covers most people; the range stretches if you run premium plans or heavy API volume

The honest summary: the server is the fixed cost. Everything after that is a choice — subscription, metered API, or your own hardware — and you can change your mind per harness without rebuilding anything.


Troubleshooting

"command not found" when running your agent

Its install location isn't on your PATH. npm-installed agents live in npm's global bin folder; Claude Code's installer uses ~/.local/bin:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Sign-in URL gives an "Invalid Request" error

The URL got truncated during copy/paste. Use the API key method instead (Part 5, Option B) — it's the more reliable route from a phone anyway.

API key has spaces inserted by phone keyboard

iPhone keyboards sometimes auto-insert spaces in long strings. Use the Termius text input bar at the bottom of the screen, or type the export command and carefully paste the key without spaces.

Can't connect via SSH

  • Check the droplet is running in the DigitalOcean dashboard
  • Verify the IP address is correct
  • Make sure you selected the right SSH key in Termius
  • Try destroying and recreating the droplet if all else fails

tmux session gone

tmux ls          # List existing sessions
tmux new -s dev  # Create a new one

Agent not responding

# Verify the install (use your harness's name)
claude --version   # or: codex --version / gemini --version / aider --version

Exit the session and relaunch the agent; check for an update command in its help if problems persist.

Running out of disk space

df -h             # Check usage
apt autoremove    # Clean up
docker system prune  # If using Docker

What You've Built

You now have a full cloud development environment accessible from your iPhone:

  • Termius → SSH into your server from anywhere
  • tmux → Sessions persist through disconnects
  • Your agent → An AI coding agent — whichever harness and model you chose — with your full codebase and your standing context in reach
  • MCP tools → Your agent can browse the web and fetch URLs
  • Git → Push code, create branches, manage your repo

This is a real dev setup. The same thing people run on $2,000 MacBooks, running on a $6/month server, controlled from your phone — and none of it is locked to one company's agent. Swap the harness next year and the server, the sessions, and the context files are still yours.

來源:DEV Community · dev.to