<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mooncake</title>
    <description>The latest articles on DEV Community by Mooncake (@hi_moonssh).</description>
    <link>https://dev.to/hi_moonssh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4247676%2F0aca5373-1683-433c-9748-0daf64edf3b6.png</url>
      <title>DEV Community: Mooncake</title>
      <link>https://dev.to/hi_moonssh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hi_moonssh"/>
    <language>en</language>
    <item>
      <title>A durable SSH workflow for AI coding agents: reconnect, inspect, then reply</title>
      <dc:creator>Mooncake</dc:creator>
      <pubDate>Mon, 16 Nov 2026 11:57:45 +0000</pubDate>
      <link>https://dev.to/hi_moonssh/a-durable-ssh-workflow-for-ai-coding-agents-reconnect-inspect-then-reply-42c6</link>
      <guid>https://dev.to/hi_moonssh/a-durable-ssh-workflow-for-ai-coding-agents-reconnect-inspect-then-reply-42c6</guid>
      <description>&lt;p&gt;&lt;em&gt;AI disclosure: I used an AI writing assistant to help structure and edit this article. The recovery workflow below is a recommendation, not a benchmark or a description of MoonSSH’s internal implementation.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An agent is running tests on my development host. I close my laptop and open my iPhone. Which process still owns the work? Which pane is it in? And if I already tapped Send once, did the agent receive my instruction?&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://apps.apple.com/us/app/moonssh/id6829098322" rel="noopener noreferrer"&gt;MoonSSH&lt;/a&gt; for this workflow. The persistence underneath it comes from the remote host. You can use the commands below with any SSH client.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Put the agent behind a server, not just an SSH connection
&lt;/h2&gt;

&lt;p&gt;On your remote development host, change to your checkout and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux new-session -s checkout -n agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start your coding agent inside that pane. For unattended work, give it a stopping point: “Run the checkout tests and summarize the failures. If a fix would change the public API, show me the proposed change before editing.” Detach with Ctrl-b then d (the default bindings).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Phone terminal → SSH connection → remote tmux client
                                      ↓ local socket
                                  remote tmux server
                                      ↓ pane PTY
                                  shell → coding agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;tmux server&lt;/strong&gt; owns the sessions and pseudo-terminals (PTYs). The &lt;strong&gt;tmux client&lt;/strong&gt; gives you the view and keyboard. If the SSH connection drops and the client disappears, the pane and its processes normally continue while that server survives. The agent can still finish, crash, hang, or pause for approval. A host reboot or tmux server crash does not reconstruct that in-memory state.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Verify the pane before sending input
&lt;/h2&gt;

&lt;p&gt;From a fresh SSH shell on the same host, as the same user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux list-panes -s -t &lt;span class="s1"&gt;'=checkout'&lt;/span&gt; -F &lt;span class="s1"&gt;'#{session_name} #{session_id} #{window_name} #{window_id} #{pane_id} server=#{pid} pane=#{pane_pid} dead=#{pane_dead} cwd=#{pane_current_path} cmd=#{pane_current_command}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The leading equals sign asks for an exact session-name match. The session ID starts with a dollar sign, the window ID with an at sign, and the pane ID with a percent sign. These IDs are stable &lt;strong&gt;for the lifetime of those objects within that tmux server&lt;/strong&gt;, not across servers and restarts. Indexes and names are labels, not proof of which process will get your input.&lt;/p&gt;

&lt;p&gt;Substitute your actual pane ID for this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;pane&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'%3'&lt;/span&gt;
tmux display-message -p -t &lt;span class="s2"&gt;"$pane"&lt;/span&gt; &lt;span class="s1"&gt;'socket=#{socket_path} server=#{pid} session=#{session_id} window=#{window_id} pane=#{pane_id} first_pid=#{pane_pid} dead=#{pane_dead}'&lt;/span&gt;
&lt;span class="nv"&gt;pane_pid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;tmux display-message -p -t &lt;span class="s2"&gt;"$pane"&lt;/span&gt; &lt;span class="s1"&gt;'#{pane_pid}'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
ps -o pid,ppid,tty,args -p &lt;span class="s2"&gt;"$pane_pid"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the host, user, tmux socket, and pane identity together. A different socket may point to a different server. A pane ID or PID can be reused after a restart. If the server or pane no longer matches, don't assume a familiar name means it's the old instance. Also, &lt;strong&gt;pane_pid&lt;/strong&gt; identifies the first process in the pane, often a shell. A living shell is not proof that the agent is still running.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Read the latest output without sending keystrokes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux capture-pane -p -t &lt;span class="s2"&gt;"$pane"&lt;/span&gt; -S -200 &lt;span class="o"&gt;|&lt;/span&gt; tail -n 80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The negative offset starts up to 200 lines back in retained history; the pipe keeps the last 80 lines of the combined capture. This reads the terminal and retained scrollback, not an authoritative run log. A full-screen app can redraw earlier output, and the history is bounded. If you need an audit trail or an unambiguous completion signal, record the test output and exit code separately on the host.&lt;/p&gt;

&lt;p&gt;MoonSSH’s native session controls help me reattach. In Herdr, the navigator and Inbox help me locate work that needs attention. I still check the latest output before replying.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Treat a disconnect during Send as an unknown outcome
&lt;/h2&gt;

&lt;p&gt;A disconnect immediately after Send leaves several possibilities: nothing was sent, only part reached the PTY, or the agent received the whole instruction and is already acting. Reconnecting proves that you have a new connection. It doesn't acknowledge what the terminal app received or did on the old one.&lt;/p&gt;

&lt;p&gt;Reattach with &lt;strong&gt;tmux attach-session -t '=checkout'&lt;/strong&gt;, verify the pane ID, then read or capture its output. Look for the instruction in the agent’s conversation, a new tool invocation, a pending confirmation, or an unfinished input line. An absent echo or missing shell history is not proof of delivery failure. If the operation had side effects, inspect the destination state or the agent’s run history before repeating it. An application with acknowledgments or deduplicated request IDs can do better; a terminal input stream supplies neither on its own.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What I see&lt;/th&gt;
&lt;th&gt;What I do next&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SSH drops during a test run&lt;/td&gt;
&lt;td&gt;Reconnect, identify the server and pane, and inspect the output before starting another run.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;tmux reports no server&lt;/td&gt;
&lt;td&gt;Check host, user, and socket. If the server died, use persisted logs or the agent’s restore mechanism.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The pane exists but the agent is gone&lt;/td&gt;
&lt;td&gt;Check the last output and exit log. A surviving shell is not a running agent.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Send may have reached the agent&lt;/td&gt;
&lt;td&gt;Don't replay. Inspect the transcript and side effects, then send only what remains necessary.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The durable part is the remote server. The safe part is verifying which work you’re looking at before you send another instruction.&lt;/p&gt;

&lt;p&gt;References: &lt;a href="https://github.com/tmux/tmux/wiki/Getting-Started" rel="noopener noreferrer"&gt;tmux upstream guide&lt;/a&gt; and &lt;a href="https://man.openbsd.org/man1/tmux.1" rel="noopener noreferrer"&gt;tmux manual: targets, formats, and capture-pane&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>fastapi</category>
      <category>ai</category>
      <category>ssh</category>
    </item>
  </channel>
</rss>
