agentleFS
wakqasahmedwakqasahmed/ai-engineering-workflow-skills/skills/engineering/tmux-orphaned-socket/SKILL.md

tmux-orphaned-socket

Skill2 starsChanged 2 months agoMITView on GitHub

Diagnose and recover from "error connecting to /tmp/tmux-*/default (No such file or directory)" when tmux ls or attach fails but sessions were working before. Use when a tmux socket has gone missing, especially after any /tmp cleanup, disk-space sweep, or agent-run cleanup script — never assume the sessions are lost before checking.

  • Deletes or force-pushes

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Check whether the server process is still alive, and identify the server specifically — ps aux | grep '[t]mux' lists clients and the server …

    line 25
  2. Very specific:

    Check when the socket directory was recreated, to date the event: stat /tmp/tmux-$(id -u) — a Birth timestamp much later than the server's …

    line 32
  3. Very specific:

    Kill and restart: Only way to regain tmux ls/attach/new-window.

    line 62
  4. Distinctive:

    Default to leaving it running and reporting what's alive, unless the user has already confirmed losing those panes is fine.

    line 66

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Tmux Orphaned Socket

tmux ls failing with error connecting to /tmp/tmux-<uid>/default (No such file or directory) does not mean the sessions are gone. A running tmux server keeps its windows alive in memory even after its own socket file is deleted out from under it — deleting a Unix domain socket file doesn't touch the process holding it open, it only blocks new connections. This is the usual outcome of a /tmp cleanup (a cron sweep, an agent-run script, a manual rm -rf /tmp/*) that didn't exclude /tmp/tmux-*.

Diagnose, don't assume

  1. Confirm the socket is actually missing, not just misnamed: ls -la /tmp/tmux-$(id -u)/ — expect it empty, not absent: tmux itself recreates /tmp/tmux-<uid> (mode 0700) on its own next invocation, including the tmux ls/attach that surfaced the error, so by the time you're reading this the directory almost always exists again — an "absent" directory is essentially unreachable once any tmux command has run as that uid. pam_systemd creates /run/user/<uid>, not this directory, and systemd-tmpfiles manages /tmp broadly rather than per-uid tmux dirs specifically, so don't attribute the recreation to either of them.
  2. Check whether the server process is still alive, and identify the server specifically — ps aux | grep '[t]mux' lists clients and the server indistinguishably: ps -eo pid,ppid,cmd | grep '[t]mux' and look for the process with no controlling terminal (? in a ps -eo pid,tty,cmd listing), often shown as tmux: server; exact presentation is tmux-version- and platform-dependent, so treat this as a strong hint, not a guarantee. Cross- check by connecting once (tmux ls) and then finding who holds the socket: lsof /tmp/tmux-$(id -u)/default or fuser -v /tmp/tmux-$(id -u)/default.
  3. Check when the socket directory was recreated, to date the event: stat /tmp/tmux-$(id -u) — a Birth timestamp much later than the server's start time means the directory was deleted and silently recreated. Birth isn't always available (tmpfs and some filesystems omit it and print -); when it's missing, fall back to stat -c '%Y' (mtime) or the server's own start time (ps -o lstart= -p <server-pid>) for the same comparison.
  4. Confirm live windows/panes under the orphaned server before deciding anything: pstree -p <server-pid> and ps --ppid <server-pid>. All panes under a surviving server process keep running regardless of whether their client is currently attached or detached — survival depends on the server process, not on client attachment. An already-attached client's terminal also stays usable, since its connection was established before the socket vanished; a detached session is not at any extra risk and should be checked with the same care as an attached one.
  5. Rule out the routine suspects before blaming an ad hoc script: check whether systemd-tmpfiles-clean.timer actually ages /tmp with systemd-tmpfiles --cat-config (merges /usr/lib/tmpfiles.d, /etc/tmpfiles.d, and /run/tmpfiles.d in override order — checking only the vendor file under /usr/lib/tmpfiles.d/tmp.conf can miss an /etc override) — a bare - age field in the effective config means aging is disabled — and whether a known cleanup cron's schedule lines up with the timestamp from step 3.

Recovery is a trade-off, not a fix

There is no way to make a running tmux server re-bind a socket that was deleted while it was alive — stock tmux has no "recreate my socket" or "adopt an orphaned server" command. The choice is:

  • Leave it running. Already-attached panes keep working exactly as before. You lose the ability to tmux ls, attach a new client, or open new windows on that server — but nothing currently running is interrupted. Right default whenever any pane holds work you can't easily reproduce (an active agent session, a long build, an SSH tunnel).
  • Kill and restart. Only way to regain tmux ls/attach/new-window. Kills every window on that server, including ones you didn't check. Never do this without first walking through the diagnosis steps above and confirming with whoever depends on those panes.

Default to leaving it running and reporting what's alive, unless the user has already confirmed losing those panes is fine.

Prevention

Any cleanup routine that touches /tmp broadly — cron job, agent-run script, disk-space recovery — must exclude /tmp/tmux-* (and other live-process sockets: /tmp/ssh-*, /tmp/.X11-unix, /tmp/.ICE-unix, etc.). A directory holding a live process's control socket is not stale just because its files look old; staleness has to be judged by whether the owning process still exists, not by file age alone.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.