From d555e59d8f4c0a49a8c0f736d92b2faefef90ade Mon Sep 17 00:00:00 2001 From: Deploy Bot Date: Sun, 1 Mar 2026 11:01:33 -0500 Subject: [PATCH] feat: launchd daemon option for persistent proxy Replaces nohup/disown with a macOS LaunchAgent that provides: - Auto-start on login (RunAtLoad) - Auto-restart on crash (KeepAlive) - Singleton by design (launchd manages one instance) Install: cp launchd/com.copilot.proxy.plist ~/Library/LaunchAgents/ Load: launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.copilot.proxy.plist Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- claude-copilot | 10 +++++----- launchd/com.copilot.proxy.plist | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 launchd/com.copilot.proxy.plist diff --git a/claude-copilot b/claude-copilot index 84892ba..f40058c 100755 --- a/claude-copilot +++ b/claude-copilot @@ -17,12 +17,12 @@ CLAUDE_CONFIG_ALT="$CLAUDE_CONFIG_DIR/.claude.json" export ANTHROPIC_BASE_URL="http://localhost:$PROXY_PORT" export ANTHROPIC_API_KEY="$API_KEY" -# --- Start proxy as a proper daemon (survives shell exit) --- +# --- Ensure proxy is running via launchd (singleton, auto-restart, survives logout) --- if ! curl -s "http://localhost:$PROXY_PORT/health" >/dev/null 2>&1; then echo "Starting copilot-proxy on port $PROXY_PORT..." - # Start detached: nohup + background + disown survives shell exit - nohup node "$SCRIPT_DIR/proxy.mjs" > /tmp/copilot-proxy.log 2>&1 & - disown $! 2>/dev/null + # Load the launchd agent if not already loaded + launchctl bootstrap "gui/$(id -u)" "$HOME/Library/LaunchAgents/com.copilot.proxy.plist" 2>/dev/null \ + || launchctl kickstart -k "gui/$(id -u)/com.copilot.proxy" 2>/dev/null for i in $(seq 1 10); do curl -s "http://localhost:$PROXY_PORT/health" >/dev/null 2>&1 && break sleep 0.5 @@ -31,7 +31,7 @@ if ! curl -s "http://localhost:$PROXY_PORT/health" >/dev/null 2>&1; then echo "❌ Proxy failed to start. Check /tmp/copilot-proxy.log" exit 1 fi - echo "✅ Proxy running" + echo "✅ Proxy running (launchd managed)" fi # --- Seed onboarding bypass so interactive mode skips the wizard --- diff --git a/launchd/com.copilot.proxy.plist b/launchd/com.copilot.proxy.plist new file mode 100644 index 0000000..34c1c97 --- /dev/null +++ b/launchd/com.copilot.proxy.plist @@ -0,0 +1,32 @@ + + + + + Label + com.copilot.proxy + ProgramArguments + + /opt/homebrew/bin/node + /Users/timothy.schwarz/copilot-mcp-proxy/proxy.mjs + + WorkingDirectory + /Users/timothy.schwarz/copilot-mcp-proxy + KeepAlive + + RunAtLoad + + StandardOutPath + /tmp/copilot-proxy.log + StandardErrorPath + /tmp/copilot-proxy.log + EnvironmentVariables + + PATH + /opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin + HOME + /Users/timothy.schwarz + + ThrottleInterval + 5 + +