Discussion - 

0

Discussion - 

0

Claude Code + tmux: Stop Losing Your Terminal Sessions Every Time Your Mac Sleeps

You launch a Claude Code session on your Mac.

Then:

  • you close the lid,
  • the terminal crashes,
  • your SSH session disconnects,
  • or VSCode restarts.

And the entire session disappears.

Context gone. History gone. Work gone.

The issue is not Claude Code itself.

The issue is that the agent is running directly inside your active terminal session.

When the terminal dies, the process dies with it.

Why tmux Completely Changes the Claude Code Experience

tmux lets you detach terminal sessions from your current terminal window.

That means:

  • your Claude session keeps running even if the terminal closes,
  • you can reconnect later exactly where you left off,
  • Claude keeps its loaded context,
  • and long-running tasks continue in the background.

This is especially useful:

  • over SSH on VPS instances,
  • for long-running sessions,
  • in multi-project workflows,
  • with multiple Claude agents,
  • on remote servers,
  • or simply to avoid keeping a MacBook awake 24/7.

The Setup: a cc Alias

The goal:

  • automatically create a tmux session,
  • launch claude remote-control,
  • instantly attach your terminal,
  • generate a unique session name per project.

Quick Installation

Bash

echo "alias cc='SESSION=claude-\$(basename \"\$PWD\")-\$(date +%s); tmux new-session -d -s \$SESSION \"cd \\\"\$PWD\\\" && claude remote-control\" && tmux attach -t \$SESSION'" >> ~/.bashrc && source ~/.bashrc

Zsh

echo "alias cc='SESSION=claude-\$(basename \"\$PWD\")-\$(date +%s); tmux new-session -d -s \$SESSION \"cd \\\"\$PWD\\\" && claude remote-control\" && tmux attach -t \$SESSION'" >> ~/.zshrc && source ~/.zshrc

Usage

From any project directory:

cc

The alias will:

  1. create a dedicated tmux session,
  2. launch Claude Code inside the current project,
  3. automatically attach your terminal to the session.

Reconnecting to a Claude Session

Even after closing your terminal, the session remains active.

To list active sessions:

tmux ls

To reconnect to a session:

tmux attach -t session-name

Why This Matters for Engineering Teams

In real-world infrastructure and development environments, this approach helps:

  • maintain persistent AI agents,
  • reduce context loss,
  • improve SSH workflows,
  • streamline DevOps operations,
  • run multiple Claude environments simultaneously,
  • and avoid interruptions caused by user workstations.

It is especially useful for:

  • Kubernetes,
  • CI/CD pipelines,
  • Linux administration,
  • backend development,
  • automation,
  • cybersecurity,
  • and long-running operational tasks.

Bonus: Clean Multi-Project Isolation

Because the session name automatically includes the current directory, every project gets its own isolated Claude environment.

Example:

claude-api-1748812941
frontend-1748812958
infra-prod-1748812972

You can work across multiple projects simultaneously without conflicts.

Conclusion

Most developers use Claude Code like an advanced terminal assistant.

But once paired with tmux, it becomes a persistent AI workspace.

The difference is immediate:

  • fewer interruptions,
  • fewer lost sessions,
  • less context rebuilding,
  • and far more stable workflows.

For advanced engineering workflows, it quickly becomes difficult to work without it.


Need help designing secure Linux, DevOps, self-hosted, or AI-assisted infrastructure workflows?

DYB helps companies with:

  • systems architecture,
  • cybersecurity,
  • automation,
  • self-hosted infrastructure,
  • hybrid/cloud environments,
  • and AI-powered engineering workflows.

Tags:

Arthur Perrot

Vous allez surement aimer :

No Results Found

The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.