[{"data":1,"prerenderedAt":859},["ShallowReactive",2],{"\u002Fwriting\u002Fmoshi-herdr-auto-reattach":3,"\u002Fwriting\u002Fmoshi-herdr-auto-reattach-related":858},{"id":4,"title":5,"body":6,"description":835,"extension":836,"featured":837,"kind":838,"meta":839,"navigation":384,"ogImage":840,"order":328,"path":841,"publishedAt":842,"relatedWork":843,"seo":844,"stem":845,"summary":846,"takeaways":847,"technologies":852,"videoDuration":840,"videoId":840,"__hash__":857},"articles\u002Fwriting\u002Fmoshi-herdr-auto-reattach.md","Reattach to Herdr Automatically When Moshi Reconnects (No Pro Needed)",{"type":7,"value":8,"toc":819},"minimark",[9,14,32,40,43,47,57,63,67,74,93,96,106,110,121,152,155,159,165,175,178,182,197,202,205,239,249,253,275,279,286,669,673,732,736,760,764,793,797,815],[10,11,13],"h2",{"id":12},"the-problem","The problem",[15,16,17,18,25,26,31],"p",{},"I run Claude Code inside ",[19,20,24],"a",{"href":21,"rel":22},"https:\u002F\u002Fherdr.dev",[23],"nofollow","Herdr"," on my Ubuntu desktop. When I'm away from the desk I check on it from my Pixel 8 with ",[19,27,30],{"href":28,"rel":29},"https:\u002F\u002Fgetmoshi.app",[23],"Moshi",", an SSH terminal built for coding agents.",[15,33,34,35,39],{},"Android kills Moshi's SSH connection soon after the app goes to the background. When I come back and reconnect, I get a plain shell. Then I type ",[36,37,38],"code",{},"herdr",", every single time.",[15,41,42],{},"Moshi Pro has \"auto-attach after reconnect\" for tmux and Herdr. I wanted the same result on the free version, without touching other SSH clients.",[10,44,46],{"id":45},"why-this-works-at-all","Why this works at all",[15,48,49,50,53,54,56],{},"Herdr splits into a server and clients. ",[36,51,52],{},"herdr server"," runs detached in its own session, with no terminal. Each ",[36,55,38],{}," you run is a client that attaches to it, and several clients can attach at once.",[15,58,59,60,62],{},"When the phone's SSH connection drops, only the phone's client dies. The server keeps running, and so do Claude Code and every other pane. All I need on reconnect is to run ",[36,61,38],{}," again, automatically, and only for Moshi.",[10,64,66],{"id":65},"recognizing-moshi-from-the-server","Recognizing Moshi from the server",[15,68,69,70,73],{},"The shell has to know a login came from Moshi, and that took some digging. Moshi has a \"MOSHI_CLIENT env\" toggle in Settings, off by default. When it's on, Moshi exports ",[36,71,72],{},"MOSHI_CLIENT=1"," into the remote shell, but the docs don't say how the variable gets there.",[15,75,76,77,80,81,84,85,88,89,92],{},"That matters because Ubuntu's sshd ships with ",[36,78,79],{},"AcceptEnv LANG LC_*",". If a client sends ",[36,82,83],{},"MOSHI_CLIENT"," as an SSH env request, sshd throws it away. I tried it with ",[36,86,87],{},"ssh -o SendEnv=MOSHI_CLIENT"," and the variable arrived unset, while one named ",[36,90,91],{},"LC_MOSHI_CLIENT"," got through. My live Moshi shell didn't have it either.",[15,94,95],{},"So the hook has a fallback. I reach my desktop over Tailscale, and a device keeps the same Tailscale IP, so logins from the phone's IP also count as Moshi. Any other SSH app on that phone would trigger it too, which I can live with.",[15,97,98,99,101,102,105],{},"I didn't change sshd. Adding ",[36,100,83],{}," to ",[36,103,104],{},"AcceptEnv"," is a global change and needs an sshd restart, and the IP fallback works without it.",[10,107,109],{"id":108},"what-the-hook-does","What the hook does",[15,111,112,113,116,117,120],{},"The hook lives in its own file, ",[36,114,115],{},"~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh",", and ",[36,118,119],{},"~\u002F.zshrc"," loads it with one line. At the first prompt of a login it:",[122,123,124,140,146],"ol",{},[125,126,127,128,131,132,135,136,139],"li",{},"Exits right away unless the shell is interactive, has an SSH terminal (",[36,129,130],{},"SSH_TTY","), and is not already inside Herdr (",[36,133,134],{},"HERDR_ENV","). That keeps it away from local shells, Herdr panes, ",[36,137,138],{},"ssh host command",", scp, and sftp.",[125,141,142,143,145],{},"Checks for ",[36,144,72],{},", then the fallback IP list.",[125,147,148,149,151],{},"Runs ",[36,150,38],{},", which attaches to the running default session. It only starts a new server if none is running, so it never makes a duplicate.",[15,153,154],{},"It runs once per login. If I detach from Herdr, I get a normal shell instead of being thrown back in. It also checks the first three prompts, not only the first, in case Moshi types the export after login instead of sending it with the connection.",[10,156,158],{"id":157},"option-1-let-claude-code-do-it","Option 1: Let Claude Code do it",[15,160,161,162,164],{},"This is the prompt I gave Claude Code. It inspected my machine, found that ",[36,163,83],{}," wasn't arriving, added the IP fallback, and tested everything without dropping my session.",[166,167,173],"pre",{"className":168,"code":170,"language":171,"meta":172},[169],"language-text","I use Moshi (the Android SSH terminal app, free version) on my phone to SSH into\nthis Ubuntu computer and access Herdr.\n\nThe problem: When Moshi goes into the background, its SSH connection disconnects.\nWhen I return to Moshi and reconnect, I get a fresh shell instead of automatically\nreturning to my existing Herdr session.\n\nThe goal: Whenever I reconnect through Moshi, automatically launch Herdr and\nreattach to my existing session. I want this to work with Moshi Free, without\nupgrading to Pro. Normal SSH connections from other clients should remain unaffected.\n\nPlease do the following:\n\n1. Inspect my Ubuntu environment, determine whether I'm using Bash or Zsh, and check\n   how Herdr is installed and how its session management works.\n2. Investigate how Moshi identifies its SSH connections to the remote shell. Check\n   whether \"MOSHI_CLIENT\" is available, how it is transmitted, and whether it\n   requires an option enabled in the Moshi Android app. Don't assume the variable exists.\n3. Check Herdr's actual CLI commands and determine the safest way to reattach to an\n   existing session rather than creating a new one.\n4. Configure the appropriate shell startup file (\"~\u002F.bashrc\", \"~\u002F.zshrc\", or\n   equivalent) to automatically launch or reattach to Herdr when an interactive SSH\n   session originates from Moshi.\n5. Make the detection reliable. Prefer \"MOSHI_CLIENT\" if supported, and don't assume\n   every SSH connection is from Moshi.\n6. Prevent recursion, duplicate session creation, and accidental launches during\n   non-interactive SSH commands, SCP, or SFTP.\n7. Preserve all my existing shell configuration. Back up files before making changes\n   and make the modification easy to reverse.\n8. Test the configuration as thoroughly as possible without disconnecting my current\n   session.\n9. Explain any settings I must enable manually in the Moshi Android app.\n\nImportant: My existing Herdr session must survive SSH disconnections. The objective\nis to reattach to that same workspace automatically when Moshi reconnects, not\nrestart Herdr or Claude Code.\n\nPlease implement the solution, not just provide instructions. If Moshi cannot be\nreliably identified from the server, explain the limitation and propose the simplest\nalternative, such as a dedicated SSH command or connection profile. Don't alter\nglobal SSH server settings unless absolutely necessary, and ask before making\npotentially disruptive changes.\n\nAt the end, summarize what you changed and how I can test it by switching away from\nMoshi and reconnecting.\n","text","",[36,174,170],{"__ignoreMap":172},[15,176,177],{},"Run it from a Moshi session if you can. Claude can then read the environment of your live phone shell and see exactly what Moshi sends.",[10,179,181],{"id":180},"option-2-do-it-yourself","Option 2: Do it yourself",[15,183,184,185,188,189,192,193,196],{},"This assumes Zsh. Run ",[36,186,187],{},"echo $SHELL"," to check. For Bash, use the prompt above, or rebuild the hook with ",[36,190,191],{},"PROMPT_COMMAND"," in place of ",[36,194,195],{},"precmd",".",[198,199,201],"h3",{"id":200},"_1-find-your-phones-ip","1. Find your phone's IP",[15,203,204],{},"Connect from Moshi and run:",[166,206,210],{"className":207,"code":208,"language":209,"meta":172,"style":172},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","echo ${SSH_CONNECTION%% *}\n","bash",[36,211,212],{"__ignoreMap":172},[213,214,217,221,225,229,233,236],"span",{"class":215,"line":216},"line",1,[213,218,220],{"class":219},"sptTA","echo",[213,222,224],{"class":223},"sP7_E"," ${",[213,226,228],{"class":227},"su5hD","SSH_CONNECTION",[213,230,232],{"class":231},"smGrS","%%",[213,234,235],{"class":231}," *",[213,237,238],{"class":223},"}\n",[15,240,241,242,245,246,196],{},"That prints the IP the phone connects from. With Tailscale it starts with ",[36,243,244],{},"100.",". You can also find it in ",[36,247,248],{},"tailscale status",[198,250,252],{"id":251},"_2-back-up-your-zshrc","2. Back up your .zshrc",[166,254,256],{"className":207,"code":255,"language":209,"meta":172,"style":172},"cp -p ~\u002F.zshrc ~\u002F.zshrc.bak-pre-moshi-herdr\n",[36,257,258],{"__ignoreMap":172},[213,259,260,264,268,272],{"class":215,"line":216},[213,261,263],{"class":262},"sbgvK","cp",[213,265,267],{"class":266},"stzsN"," -p",[213,269,271],{"class":270},"s_sjI"," ~\u002F.zshrc",[213,273,274],{"class":270}," ~\u002F.zshrc.bak-pre-moshi-herdr\n",[198,276,278],{"id":277},"_3-create-the-hook","3. Create the hook",[15,280,281,282,285],{},"Replace ",[36,283,284],{},"100.x.y.z"," with your phone's IP, then paste the whole block:",[166,287,289],{"className":207,"code":288,"language":209,"meta":172,"style":172},"mkdir -p ~\u002F.config\u002Fzsh\ncat > ~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh \u003C\u003C'EOF'\n# moshi-herdr: reattach to the persistent Herdr session when an\n# interactive SSH login comes from Moshi on the phone.\n#\n# Detection, in order:\n#   1. MOSHI_CLIENT=1 (Moshi app: Settings > \"MOSHI_CLIENT env\" toggle).\n#   2. Fallback: the SSH client IP is in MOSHI_HERDR_FALLBACK_IPS.\n#      Empty the array to rely on MOSHI_CLIENT only.\n#\n# Disable for now:  touch ~\u002F.config\u002Fmoshi-herdr.disabled\n# Remove:           delete the \"moshi-herdr\" line in ~\u002F.zshrc\n\ntypeset -ga MOSHI_HERDR_FALLBACK_IPS=(\n  100.x.y.z   # phone (Tailscale)\n)\n: ${MOSHI_HERDR_BIN:=herdr}   # override only for tests\n\n# Only SSH logins with a terminal, outside Herdr, need the hook.\n# Local shells, Herdr panes, `ssh host cmd`, scp and sftp stop here.\nif [[ -o interactive && -n $SSH_TTY && -z $HERDR_ENV && -z $_MOSHI_HERDR_DONE ]]; then\n  typeset -gi _moshi_herdr_prompts=0\n\n  _moshi_herdr_precmd() {\n    # Check the first 3 prompts, in case Moshi exports MOSHI_CLIENT\n    # after login instead of sending it with the connection.\n    if (( ++_moshi_herdr_prompts > 3 )); then\n      add-zsh-hook -d precmd _moshi_herdr_precmd\n      return\n    fi\n\n    [[ -t 0 && -t 1 ]] || return\n    [[ -e ~\u002F.config\u002Fmoshi-herdr.disabled ]] && return\n    command -v $MOSHI_HERDR_BIN >\u002Fdev\u002Fnull || return\n\n    local via ip=${SSH_CONNECTION%% *}\n    if [[ $MOSHI_CLIENT == 1 ]]; then\n      via=MOSHI_CLIENT\n    elif (( ${MOSHI_HERDR_FALLBACK_IPS[(Ie)$ip]} )); then\n      via=\"client IP $ip\"\n    else\n      return\n    fi\n\n    # Run once per login. After you detach from Herdr, you get this shell.\n    add-zsh-hook -d precmd _moshi_herdr_precmd\n    export _MOSHI_HERDR_DONE=1\n\n    if $MOSHI_HERDR_BIN status 2>\u002Fdev\u002Fnull | grep -q 'status: running'; then\n      print -P \"%F{cyan}moshi-herdr:%f attaching to the running Herdr session ($via)\"\n    else\n      print -P \"%F{yellow}moshi-herdr:%f no Herdr server is running; starting Herdr ($via)\"\n    fi\n    # `herdr` attaches to the persistent default session if it runs,\n    # and starts it only if it does not.\n    $MOSHI_HERDR_BIN\n  }\n\n  autoload -Uz add-zsh-hook\n  add-zsh-hook precmd _moshi_herdr_precmd\nfi\nEOF\n",[36,290,291,301,320,326,332,338,344,350,356,362,367,373,379,386,392,398,404,410,415,421,427,433,439,444,450,456,462,468,474,480,486,491,497,503,509,514,520,526,532,538,544,550,555,560,565,571,577,583,588,594,600,605,611,616,622,628,634,640,645,651,657,663],{"__ignoreMap":172},[213,292,293,296,298],{"class":215,"line":216},[213,294,295],{"class":262},"mkdir",[213,297,267],{"class":266},[213,299,300],{"class":270}," ~\u002F.config\u002Fzsh\n",[213,302,304,307,310,313,316],{"class":215,"line":303},2,[213,305,306],{"class":262},"cat",[213,308,309],{"class":231}," >",[213,311,312],{"class":270}," ~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh",[213,314,315],{"class":231}," \u003C\u003C",[213,317,319],{"class":318},"sjJ54","'EOF'\n",[213,321,323],{"class":215,"line":322},3,[213,324,325],{"class":270},"# moshi-herdr: reattach to the persistent Herdr session when an\n",[213,327,329],{"class":215,"line":328},4,[213,330,331],{"class":270},"# interactive SSH login comes from Moshi on the phone.\n",[213,333,335],{"class":215,"line":334},5,[213,336,337],{"class":270},"#\n",[213,339,341],{"class":215,"line":340},6,[213,342,343],{"class":270},"# Detection, in order:\n",[213,345,347],{"class":215,"line":346},7,[213,348,349],{"class":270},"#   1. MOSHI_CLIENT=1 (Moshi app: Settings > \"MOSHI_CLIENT env\" toggle).\n",[213,351,353],{"class":215,"line":352},8,[213,354,355],{"class":270},"#   2. Fallback: the SSH client IP is in MOSHI_HERDR_FALLBACK_IPS.\n",[213,357,359],{"class":215,"line":358},9,[213,360,361],{"class":270},"#      Empty the array to rely on MOSHI_CLIENT only.\n",[213,363,365],{"class":215,"line":364},10,[213,366,337],{"class":270},[213,368,370],{"class":215,"line":369},11,[213,371,372],{"class":270},"# Disable for now:  touch ~\u002F.config\u002Fmoshi-herdr.disabled\n",[213,374,376],{"class":215,"line":375},12,[213,377,378],{"class":270},"# Remove:           delete the \"moshi-herdr\" line in ~\u002F.zshrc\n",[213,380,382],{"class":215,"line":381},13,[213,383,385],{"emptyLinePlaceholder":384},true,"\n",[213,387,389],{"class":215,"line":388},14,[213,390,391],{"class":270},"typeset -ga MOSHI_HERDR_FALLBACK_IPS=(\n",[213,393,395],{"class":215,"line":394},15,[213,396,397],{"class":270},"  100.x.y.z   # phone (Tailscale)\n",[213,399,401],{"class":215,"line":400},16,[213,402,403],{"class":270},")\n",[213,405,407],{"class":215,"line":406},17,[213,408,409],{"class":270},": ${MOSHI_HERDR_BIN:=herdr}   # override only for tests\n",[213,411,413],{"class":215,"line":412},18,[213,414,385],{"emptyLinePlaceholder":384},[213,416,418],{"class":215,"line":417},19,[213,419,420],{"class":270},"# Only SSH logins with a terminal, outside Herdr, need the hook.\n",[213,422,424],{"class":215,"line":423},20,[213,425,426],{"class":270},"# Local shells, Herdr panes, `ssh host cmd`, scp and sftp stop here.\n",[213,428,430],{"class":215,"line":429},21,[213,431,432],{"class":270},"if [[ -o interactive && -n $SSH_TTY && -z $HERDR_ENV && -z $_MOSHI_HERDR_DONE ]]; then\n",[213,434,436],{"class":215,"line":435},22,[213,437,438],{"class":270},"  typeset -gi _moshi_herdr_prompts=0\n",[213,440,442],{"class":215,"line":441},23,[213,443,385],{"emptyLinePlaceholder":384},[213,445,447],{"class":215,"line":446},24,[213,448,449],{"class":270},"  _moshi_herdr_precmd() {\n",[213,451,453],{"class":215,"line":452},25,[213,454,455],{"class":270},"    # Check the first 3 prompts, in case Moshi exports MOSHI_CLIENT\n",[213,457,459],{"class":215,"line":458},26,[213,460,461],{"class":270},"    # after login instead of sending it with the connection.\n",[213,463,465],{"class":215,"line":464},27,[213,466,467],{"class":270},"    if (( ++_moshi_herdr_prompts > 3 )); then\n",[213,469,471],{"class":215,"line":470},28,[213,472,473],{"class":270},"      add-zsh-hook -d precmd _moshi_herdr_precmd\n",[213,475,477],{"class":215,"line":476},29,[213,478,479],{"class":270},"      return\n",[213,481,483],{"class":215,"line":482},30,[213,484,485],{"class":270},"    fi\n",[213,487,489],{"class":215,"line":488},31,[213,490,385],{"emptyLinePlaceholder":384},[213,492,494],{"class":215,"line":493},32,[213,495,496],{"class":270},"    [[ -t 0 && -t 1 ]] || return\n",[213,498,500],{"class":215,"line":499},33,[213,501,502],{"class":270},"    [[ -e ~\u002F.config\u002Fmoshi-herdr.disabled ]] && return\n",[213,504,506],{"class":215,"line":505},34,[213,507,508],{"class":270},"    command -v $MOSHI_HERDR_BIN >\u002Fdev\u002Fnull || return\n",[213,510,512],{"class":215,"line":511},35,[213,513,385],{"emptyLinePlaceholder":384},[213,515,517],{"class":215,"line":516},36,[213,518,519],{"class":270},"    local via ip=${SSH_CONNECTION%% *}\n",[213,521,523],{"class":215,"line":522},37,[213,524,525],{"class":270},"    if [[ $MOSHI_CLIENT == 1 ]]; then\n",[213,527,529],{"class":215,"line":528},38,[213,530,531],{"class":270},"      via=MOSHI_CLIENT\n",[213,533,535],{"class":215,"line":534},39,[213,536,537],{"class":270},"    elif (( ${MOSHI_HERDR_FALLBACK_IPS[(Ie)$ip]} )); then\n",[213,539,541],{"class":215,"line":540},40,[213,542,543],{"class":270},"      via=\"client IP $ip\"\n",[213,545,547],{"class":215,"line":546},41,[213,548,549],{"class":270},"    else\n",[213,551,553],{"class":215,"line":552},42,[213,554,479],{"class":270},[213,556,558],{"class":215,"line":557},43,[213,559,485],{"class":270},[213,561,563],{"class":215,"line":562},44,[213,564,385],{"emptyLinePlaceholder":384},[213,566,568],{"class":215,"line":567},45,[213,569,570],{"class":270},"    # Run once per login. After you detach from Herdr, you get this shell.\n",[213,572,574],{"class":215,"line":573},46,[213,575,576],{"class":270},"    add-zsh-hook -d precmd _moshi_herdr_precmd\n",[213,578,580],{"class":215,"line":579},47,[213,581,582],{"class":270},"    export _MOSHI_HERDR_DONE=1\n",[213,584,586],{"class":215,"line":585},48,[213,587,385],{"emptyLinePlaceholder":384},[213,589,591],{"class":215,"line":590},49,[213,592,593],{"class":270},"    if $MOSHI_HERDR_BIN status 2>\u002Fdev\u002Fnull | grep -q 'status: running'; then\n",[213,595,597],{"class":215,"line":596},50,[213,598,599],{"class":270},"      print -P \"%F{cyan}moshi-herdr:%f attaching to the running Herdr session ($via)\"\n",[213,601,603],{"class":215,"line":602},51,[213,604,549],{"class":270},[213,606,608],{"class":215,"line":607},52,[213,609,610],{"class":270},"      print -P \"%F{yellow}moshi-herdr:%f no Herdr server is running; starting Herdr ($via)\"\n",[213,612,614],{"class":215,"line":613},53,[213,615,485],{"class":270},[213,617,619],{"class":215,"line":618},54,[213,620,621],{"class":270},"    # `herdr` attaches to the persistent default session if it runs,\n",[213,623,625],{"class":215,"line":624},55,[213,626,627],{"class":270},"    # and starts it only if it does not.\n",[213,629,631],{"class":215,"line":630},56,[213,632,633],{"class":270},"    $MOSHI_HERDR_BIN\n",[213,635,637],{"class":215,"line":636},57,[213,638,639],{"class":270},"  }\n",[213,641,643],{"class":215,"line":642},58,[213,644,385],{"emptyLinePlaceholder":384},[213,646,648],{"class":215,"line":647},59,[213,649,650],{"class":270},"  autoload -Uz add-zsh-hook\n",[213,652,654],{"class":215,"line":653},60,[213,655,656],{"class":270},"  add-zsh-hook precmd _moshi_herdr_precmd\n",[213,658,660],{"class":215,"line":659},61,[213,661,662],{"class":270},"fi\n",[213,664,666],{"class":215,"line":665},62,[213,667,668],{"class":318},"EOF\n",[198,670,672],{"id":671},"_4-load-it-from-zshrc","4. Load it from .zshrc",[166,674,676],{"className":207,"code":675,"language":209,"meta":172,"style":172},"printf '\\n# moshi-herdr: reattach Herdr on Moshi SSH logins (remove this line to disable)\\n[[ -r ~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh ]] && source ~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh\\n' >> ~\u002F.zshrc\nzsh -n ~\u002F.zshrc && zsh -n ~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh && echo \"syntax OK\"\n",[36,677,678,698],{"__ignoreMap":172},[213,679,680,683,686,689,692,695],{"class":215,"line":216},[213,681,682],{"class":219},"printf",[213,684,685],{"class":318}," '",[213,687,688],{"class":270},"\\n# moshi-herdr: reattach Herdr on Moshi SSH logins (remove this line to disable)\\n[[ -r ~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh ]] && source ~\u002F.config\u002Fzsh\u002Fmoshi-herdr.zsh\\n",[213,690,691],{"class":318},"'",[213,693,694],{"class":231}," >>",[213,696,697],{"class":270}," ~\u002F.zshrc\n",[213,699,700,703,706,708,711,714,716,718,720,723,726,729],{"class":215,"line":303},[213,701,702],{"class":262},"zsh",[213,704,705],{"class":266}," -n",[213,707,271],{"class":270},[213,709,710],{"class":223}," &&",[213,712,713],{"class":262}," zsh",[213,715,705],{"class":266},[213,717,312],{"class":270},[213,719,710],{"class":223},[213,721,722],{"class":219}," echo",[213,724,725],{"class":318}," \"",[213,727,728],{"class":270},"syntax OK",[213,730,731],{"class":318},"\"\n",[198,733,735],{"id":734},"_5-optional-turn-on-moshi_client","5. Optional: turn on MOSHI_CLIENT",[15,737,738,739,743,744,747,748,751,752,755,756,759],{},"In Moshi, open ",[740,741,742],"strong",{},"Settings"," and turn on ",[740,745,746],{},"MOSHI_CLIENT env",". If the variable reaches your shell, the attach message says ",[36,749,750],{},"(MOSHI_CLIENT)"," instead of ",[36,753,754],{},"(client IP ...)",". Once you see that, you can empty ",[36,757,758],{},"MOSHI_HERDR_FALLBACK_IPS"," and rely on the variable alone.",[10,761,763],{"id":762},"testing-it","Testing it",[122,765,766,773,776,779,782],{},[125,767,768,769,772],{},"Open Moshi and connect. You should land in Herdr with a ",[36,770,771],{},"moshi-herdr: attaching..."," line just before it.",[125,774,775],{},"Switch to another app long enough for the connection to drop.",[125,777,778],{},"Go back to Moshi and reconnect. You should be in the same Herdr workspace, with Claude Code still running.",[125,780,781],{},"From a laptop or another SSH client, connect normally. You should get a plain shell.",[125,783,784,785,788,789,792],{},"Run ",[36,786,787],{},"scp"," or ",[36,790,791],{},"sftp"," against the machine. Both should work as before.",[10,794,796],{"id":795},"turning-it-off","Turning it off",[15,798,799,800,803,804,807,808,810,811,814],{},"To pause it, run ",[36,801,802],{},"touch ~\u002F.config\u002Fmoshi-herdr.disabled",", and delete that file to turn it back on. To remove it, delete the two ",[36,805,806],{},"moshi-herdr"," lines at the end of ",[36,809,119],{}," or restore ",[36,812,813],{},"~\u002F.zshrc.bak-pre-moshi-herdr",". Nothing outside your home folder changes, so there is nothing else to undo.",[816,817,818],"style",{},"html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .stzsN, html code.shiki .stzsN{--shiki-light:#91B859;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":172,"searchDepth":322,"depth":322,"links":820},[821,822,823,824,825,826,833,834],{"id":12,"depth":303,"text":13},{"id":45,"depth":303,"text":46},{"id":65,"depth":303,"text":66},{"id":108,"depth":303,"text":109},{"id":157,"depth":303,"text":158},{"id":180,"depth":303,"text":181,"children":827},[828,829,830,831,832],{"id":200,"depth":322,"text":201},{"id":251,"depth":322,"text":252},{"id":277,"depth":322,"text":278},{"id":671,"depth":322,"text":672},{"id":734,"depth":322,"text":735},{"id":762,"depth":303,"text":763},{"id":795,"depth":303,"text":796},"How I made Moshi Free on Android reattach to my existing Herdr session after every SSH reconnect, using a Zsh startup hook, with a copy-paste prompt for Claude Code and the manual shell commands.","md",false,"article",{},null,"\u002Fwriting\u002Fmoshi-herdr-auto-reattach","2026-11-23",[],{"title":5,"description":835},"writing\u002Fmoshi-herdr-auto-reattach","A small Zsh hook that puts my phone straight back into my running Herdr session every time Moshi reconnects over SSH.",[848,849,850,851],"Herdr's server keeps running when SSH drops, so only the client needs to come back","Moshi's MOSHI_CLIENT variable is off by default, and a stock sshd drops it if it arrives as an SSH env request","A phone's Tailscale IP works as a fallback way to recognize Moshi logins","A precmd hook that runs once per login avoids recursion and leaves scp, sftp, and ssh commands alone",[24,30,853,854,855,856],"Zsh","SSH","Tailscale","Claude Code","j6y6PehqjlYOP4KdFg8Gjd4OKkimnWx8-G3kSIUX334",[],1795711313029]