Skip to content

Instantly share code, notes, and snippets.

@michaelneale
Created December 21, 2025 23:57
Show Gist options
  • Select an option

  • Save michaelneale/a130d241355e5fcce6ef90468bc6cc1c to your computer and use it in GitHub Desktop.

Select an option

Save michaelneale/a130d241355e5fcce6ef90468bc6cc1c to your computer and use it in GitHub Desktop.
Script to launch goosed agent with automatic tunnel setup for remote access
#!/bin/bash
# goosed-tunnel-setup.sh
# Script to launch goosed agent with automatic tunnel setup
#
# This creates a publicly accessible URL for your local goosed agent
# using a Cloudflare Worker proxy.
#
# Usage:
# ./goosed-tunnel-setup.sh
# GOOSE_PORT=8080 ./goosed-tunnel-setup.sh
# GOOSE_SERVER__SECRET_KEY=mysecret ./goosed-tunnel-setup.sh
#
# The tunnel URL will be displayed in the logs:
# Public URL: https://cloudflare-tunnel-proxy.michael-neale.workers.dev/tunnel/<agent_id>
set -e
# Configuration (override with environment variables)
GOOSE_PORT=${GOOSE_PORT:-3000}
GOOSE_HOST=${GOOSE_HOST:-127.0.0.1}
GOOSE_SERVER_SECRET=${GOOSE_SERVER__SECRET_KEY:-$(openssl rand -hex 32)}
echo "=== Goosed Tunnel Setup ==="
echo ""
# Step 1: Configure tunnel_auto_start in goose config
echo "Configuring tunnel auto-start..."
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/goose"
CONFIG_FILE="$CONFIG_DIR/config.yaml"
mkdir -p "$CONFIG_DIR"
# Set tunnel_auto_start to true in config.yaml
if [ -f "$CONFIG_FILE" ]; then
if grep -q "tunnel_auto_start:" "$CONFIG_FILE"; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's/tunnel_auto_start:.*/tunnel_auto_start: true/' "$CONFIG_FILE"
else
sed -i 's/tunnel_auto_start:.*/tunnel_auto_start: true/' "$CONFIG_FILE"
fi
else
echo "tunnel_auto_start: true" >> "$CONFIG_FILE"
fi
else
echo "tunnel_auto_start: true" > "$CONFIG_FILE"
fi
echo "tunnel_auto_start enabled in $CONFIG_FILE"
# Step 2: Set environment variables
export GOOSE_SERVER__SECRET_KEY="$GOOSE_SERVER_SECRET"
export GOOSE_PORT="$GOOSE_PORT"
export GOOSE_HOST="$GOOSE_HOST"
echo ""
echo "Server Configuration:"
echo " Host: $GOOSE_HOST"
echo " Port: $GOOSE_PORT"
echo " Secret: ${GOOSE_SERVER_SECRET:0:8}... (truncated)"
echo ""
# Step 3: Find and launch goosed
echo "Looking for goosed binary..."
GOOSED_BIN=""
if command -v goosed &> /dev/null; then
GOOSED_BIN="goosed"
elif [ -x "./target/release/goosed" ]; then
GOOSED_BIN="./target/release/goosed"
elif [ -x "./target/debug/goosed" ]; then
GOOSED_BIN="./target/debug/goosed"
else
echo ""
echo "Error: goosed binary not found!"
echo ""
echo "To install goosed, either:"
echo " 1. Build from source: cargo build --release -p goose-server"
echo " 2. Install via cargo: cargo install goose-server"
echo " 3. Download from: https://github.com/block/goose/releases"
echo ""
exit 1
fi
echo "Found goosed at: $GOOSED_BIN"
echo ""
echo "=== Starting Server ==="
echo ""
echo "The tunnel will auto-start. Watch for:"
echo " Public URL: https://..."
echo ""
echo "To access your agent remotely, use the public URL with the secret header:"
echo " curl <public-url>/status -H 'X-Secret-Key: <your-secret>'"
echo ""
echo "---"
echo ""
exec "$GOOSED_BIN" agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment