Remote Claude Code Terminal Access: Check on Your AI Agent from Anywhere

Beginner3h 36m readFull-stack developers

Remote Claude Code Terminal Access: Check on Your AI Agent from Anywhere Introduction You start a Claude Code session, give it a big task, and then you need to leave your desk.

Primary Focus

ai development

AI Tools Covered

AI-firstNext.jsConvex

What You'll Learn

  • What is `tmux` and Why is it Important?
  • Installing `tmux`
  • Core `tmux` Commands
  • Handling Terminal App Conflicts
  • Convenience Aliases for AI Agents
  • Key Takeaways

Guide Curriculum

Understanding `tmux`: Persistent Terminal Sessions

6 lessons
  • What is `tmux` and Why is it Important?12m
  • Installing `tmux`12m
  • Core `tmux` Commands12m
  • Handling Terminal App Conflicts12m
  • Convenience Aliases for AI Agents12m
  • Key Takeaways12m

Using `ttyd` for Browser-Based Terminal Access

5 lessons
  • What is `ttyd`?12m
  • Installing `ttyd`12m
  • Testing `ttyd`12m
  • Securing Your Terminal Access12m
  • Key Takeaways12m

Establishing a Permanent Public URL with Cloudflare Tunnel

4 lessons
  • Why Use Cloudflare Tunnel?12m
  • Installing Cloudflare Tunnel12m
  • Creating and Configuring a Tunnel12m
  • Key Takeaways12m

Automating Agent Session Management with systemd

2 lessons
  • Auto-Start Agent Sessions12m
  • Key Takeaways12m

Conclusion

By leveraging `tmux`, `ttyd`, and Cloudflare Tunnel, you can establish a powerful and flexible remote access setup for your AI coding agents. This guide has equipped you with the tools to manage your sessions from anywhere, ensuring your projects continue running smoothly regardless of your location. Embrace the power of remote access and keep your development process agile and efficient.

1 lessons
  • Conclusion12m

Preview: First Lesson

Understanding `tmux`: Persistent Terminal Sessions

What is `tmux` and Why is it Important?

tmux is a terminal multiplexer. It runs multiple terminal sessions inside one window, and the part that matters here: those sessions keep running even after you close the terminal app that started them. Start a task, shut the lid, come back hours later, and the session is exactly where you left it.

For AI coding agents, that persistence is the whole point:

  • Long-running tasks: Initiate a process, close your laptop, and return hours later to find it still active.
  • Remote access: Reconnect to your session from any device, anywhere in the world.
  • Collaboration: Multiple users can simultaneously view and interact with the same session.
  • Organization: Assign each agent its own named session to maintain clarity.
Free Access

Start learning with this comprehensive guide

This guide includes:

5 modules with 18 lessons
3h 36m estimated reading time

About the Author

H
✨ Vibe Coder
@hiram-clark

Hiram Clark is the founder and managing editor of vybecoding.ai and sets editorial direction for the guides and news published here. Articles are drafted with AI assistance and edited before publication. He works hands-on with the AI development tools, workflows, and infrastructure covered on the site.

Full Guide Content

Complete lesson text — start the interactive course above for exercises and progress tracking.

Module 1Understanding `tmux`: Persistent Terminal Sessions

1.1What is `tmux` and Why is it Important?

tmux is a terminal multiplexer. It runs multiple terminal sessions inside one window, and the part that matters here: those sessions keep running even after you close the terminal app that started them. Start a task, shut the lid, come back hours later, and the session is exactly where you left it.

For AI coding agents, that persistence is the whole point:

  • Long-running tasks: Initiate a process, close your laptop, and return hours later to find it still active.
  • Remote access: Reconnect to your session from any device, anywhere in the world.
  • Collaboration: Multiple users can simultaneously view and interact with the same session.
  • Organization: Assign each agent its own named session to maintain clarity.

1.2Installing `tmux`

To start using tmux, you'll need to install it on your system. Here's how to do it across different operating systems:

# Ubuntu / Debian / Pop!_OS
sudo apt install tmux

# macOS
brew install tmux

# Fedora / RHEL / Rocky
sudo dnf install tmux

# Arch
sudo pacman -S tmux

# Windows: Install WSL2 first, then run the Ubuntu command above

Verify it with tmux -V. On the Pop!_OS machine I tested this on, that printed tmux 3.4. Anything in the 3.x range behaves the same for everything below.

1.3Core `tmux` Commands

These five commands cover almost everything you'll do day to day. I ran tmux new-session -d -s claude followed by tmux ls on my own box and it listed the detached session immediately, alongside the other agent sessions already running there (cursor-agent, copilot-agent, and so on). That ls output is your proof the session survived.

# Create a named session
tmux new-session -s claude

# Detach from session (session keeps running)
# Press: Ctrl+B, then D

# List running sessions
tmux ls

# Re-attach to a session
tmux attach-session -t claude

# Switch between sessions (from inside tmux)
tmux switch-client -t cursor-agent

# Kill a session
tmux kill-session -t claude

1.4Handling Terminal App Conflicts

Some terminal applications, like Warp, use tmux internally, which can lead to conflicts. If you encounter the error sessions should be nested with care, unset $TMUX to force, resolve it by clearing the TMUX variable:

TMUX= tmux new-session -s claude
TMUX= tmux attach-session -t claude

1.5Convenience Aliases for AI Agents

To streamline your workflow, create aliases for each AI agent session. Add these to your ~/.bashrc or ~/.zshrc:

# Claude Code
function cn {
  if tmux has-session -t claude 2>/dev/null; then
    tmux attach-session -t claude
  else
    tmux new-session -d -s claude -c ~/Projects/your-project
    tmux send-keys -t claude "claude --dangerously-skip-permissions" Enter
    tmux attach-session -t claude
  fi
}

# Cursor Agent
function cu {
  if tmux has-session -t cursor-agent 2>/dev/null; then
    tmux attach-session -t cursor-agent
  else
    tmux new-session -d -s cursor-agent -c ~/Projects/your-project
    tmux send-keys -t cursor-agent "cursor agent" Enter
    tmux attach-session -t cursor-agent
  fi
}

# Additional aliases for other agents...

Reload your shell configuration with source ~/.bashrc.

1.6Key Takeaways

  • tmux provides persistent terminal sessions, crucial for managing long-running AI tasks.
  • Essential commands like creating, detaching, and re-attaching sessions are fundamental for effective use.
  • Aliases can significantly streamline your workflow by simplifying session management.

Module 2Using `ttyd` for Browser-Based Terminal Access

2.1What is `ttyd`?

ttyd is a small program that serves a terminal over HTTP and WebSocket, so you can drive a full interactive shell from any browser tab. It renders with xterm.js, the same engine VS Code's terminal uses, so the typing and scrollback feel identical to a native terminal. The build I used for this guide was ttyd 1.7.4.

2.2Installing `ttyd`

Install ttyd using the following commands:

# Ubuntu / Debian
sudo apt install ttyd

# macOS
brew install ttyd

# Fedora
sudo dnf install ttyd

# Manual installation for other Linux distributions
sudo curl -L https://github.com/tsl0922/ttyd/releases/latest/download/ttyd.x86_64 \
  -o /usr/local/bin/ttyd && sudo chmod +x /usr/local/bin/ttyd

Verify with ttyd --version. Mine reported ttyd version 1.7.4.

2.3Testing `ttyd`

To test ttyd, start it with your claude session:

# Start ttyd pointing at your claude session (port 7682)
ttyd -p 7682 tmux new-session -A -s claude

# Open http://localhost:7682 in your browser

You should see a terminal interface where you can interact with your tmux session.

2.4Securing Your Terminal Access

To ensure your terminal is secure, never expose an unauthenticated terminal to the public internet. Use a two-port strategy:

  • Port 7682: Loopback only, no authentication (for local admin panel).
  • Port 7681: Authenticated and exposed via Cloudflare for remote access.
# Loopback only
ttyd --port 7682 --interface lo --writable tmux new-session -A -s claude

# Authenticated access
ttyd --port 7681 -c yourusername:your-password --writable tmux new-session -A -s claude

2.5Key Takeaways

  • ttyd allows browser-based terminal access, making remote management more accessible.
  • Always secure your terminal access with authentication to prevent unauthorized access.

Module 3Establishing a Permanent Public URL with Cloudflare Tunnel

3.1Why Use Cloudflare Tunnel?

Cloudflare Tunnel gives your terminal a permanent public URL without opening a single port on your firewall. The tunnel dials out to Cloudflare, so there's nothing inbound to attack. Access control rides on your existing Cloudflare account. The cloudflared version I installed was 2026.5.0.

3.2Installing Cloudflare Tunnel

Install cloudflared using the following commands:

# macOS
brew install cloudflare/cloudflare/cloudflared

# Ubuntu / Debian
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb \
  -o cloudflared.deb && sudo dpkg -i cloudflared.deb

# Arch
sudo pacman -S cloudflared

# Windows (PowerShell)
winget install Cloudflare.cloudflared

3.3Creating and Configuring a Tunnel

Authenticate and create a tunnel:

# Authenticate (opens browser to Cloudflare login)
cloudflared tunnel login

# Create the tunnel
cloudflared tunnel create terminal

# Route your subdomain to this tunnel
cloudflared tunnel route dns terminal terminal.yourdomain.com

Configure the tunnel by creating a configuration file ~/.cloudflared/terminal-config.yml:

tunnel: YOUR-TUNNEL-UUID-HERE
credentials-file: /home/YOUR-USERNAME/.cloudflared/YOUR-TUNNEL-UUID.json

ingress:
  - hostname: terminal.yourdomain.com
    service: http://localhost:7681
    originRequest:
      noTLSVerify: true
      connectTimeout: 30s
  - service: http_status:404

Test your setup with:

cloudflared tunnel --config ~/.cloudflared/terminal-config.yml run terminal

3.4Key Takeaways

  • Cloudflare Tunnel provides a secure, always-on public URL for your terminal sessions.
  • Proper configuration ensures seamless integration with your existing infrastructure.

Module 4Automating Agent Session Management with systemd

4.1Auto-Start Agent Sessions

To ensure your agent sessions start automatically, create systemd user services. Here's an example script for the claude session:

~/.local/bin/start-claude-session.sh:
#!/bin/bash
export HOME=/home/YOUR-USERNAME
export PATH=/home/YOUR-USERNAME/.local/bin:/usr/local/bin:/usr/bin:/bin
export TERM=xterm-256color
export TMUX_TMPDIR=/tmp

tmux kill-session -t claude 2>/dev/null || true
tmux new-session -d -s claude -c /home/YOUR-USERNAME/Projects/your-project \; \
  send-keys "claude --dangerously-skip-permissions" Enter

Make the script executable:

chmod +x ~/.local/bin/start-claude-session.sh

Create similar scripts for other agents and configure them as systemd services to start on boot.

4.2Key Takeaways

  • Automating session management with systemd ensures your AI agents are always ready to go.
  • Custom scripts can be tailored to fit the specific needs of each agent.

Module 5Conclusion

5.1Conclusion

Three tools, one pipeline. tmux keeps the session alive, ttyd puts it in a browser, and Cloudflare Tunnel hands you a URL you can hit from a phone on the train. The piece people skip is the security step: keep the unauthenticated terminal on loopback, and only expose the password-protected port through the tunnel. Get that wrong and you've published a root shell to the internet. Get it right and you can babysit a long agent run from anywhere without an SSH key in sight.