Skip to content

Instantly share code, notes, and snippets.

@stefanmunz
Last active October 1, 2025 13:44
Show Gist options
  • Save stefanmunz/0a076d567c591deec34723866198c755 to your computer and use it in GitHub Desktop.
Save stefanmunz/0a076d567c591deec34723866198c755 to your computer and use it in GitHub Desktop.
Custom Slash Command: Deep Clean TreeOS Production Data
#!/bin/bash
# TreeOS Production Mode Deep Cleanup Script (Non-interactive)
# Removes ALL production data including shared folders, Podman containers and images
set -e
# Check if running as root (required for /opt operations)
if [ "$EUID" -ne 0 ]; then
echo "This script must be run with sudo to clean /opt/ontree"
exit 1
fi
echo "TreeOS Production Mode DEEP Cleanup"
echo "===================================="
echo ""
echo "Removing ALL TreeOS data including:"
echo " - Application configurations (/opt/ontree/apps/)"
echo " - Shared data (/opt/ontree/shared/)"
echo " - Ollama models (/opt/ontree/shared/ollama/)"
echo " - Log files (/opt/ontree/logs/)"
echo " - Database (/opt/ontree/ontree.db)"
echo " - TreeOS binary (/opt/ontree/treeos)"
echo " - All Podman containers starting with 'ontree-'"
echo " - All associated Podman images"
echo ""
echo "Starting deep cleanup..."
# Stop TreeOS service if running
if command -v launchctl &> /dev/null; then
# macOS
launchctl unload /Library/LaunchDaemons/com.ontree.treeos.plist 2>/dev/null || true
echo "✓ Stopped TreeOS service (macOS)"
elif command -v systemctl &> /dev/null; then
# Linux with systemd
systemctl stop treeos.service 2>/dev/null || true
echo "✓ Stopped TreeOS service (systemd)"
fi
# Check if Podman is available
if command -v podman &> /dev/null; then
echo ""
echo "Cleaning up Podman containers and images..."
# Stop and remove all containers starting with 'ontree-'
echo "Stopping ontree-* containers..."
CONTAINERS=$(podman ps -a --format "{{.Names}}" | grep "^ontree-" || true)
if [ ! -z "$CONTAINERS" ]; then
echo "$CONTAINERS" | while read container; do
echo " - Stopping and removing container: $container"
podman stop "$container" 2>/dev/null || true
podman rm -f "$container" 2>/dev/null || true
done
echo "✓ Removed all ontree-* containers"
else
echo " No ontree-* containers found"
fi
# Get all images used by ontree-* containers before removing them
# This includes getting images from container inspect
echo ""
echo "Collecting images used by ontree-* containers..."
IMAGES_TO_REMOVE=""
# First, get images from any remaining container configs
CONTAINER_IMAGES=$(podman ps -a --format "{{.Image}}" --filter "name=^ontree-" 2>/dev/null | sort -u || true)
if [ ! -z "$CONTAINER_IMAGES" ]; then
IMAGES_TO_REMOVE="$CONTAINER_IMAGES"
fi
# Also check for images that might be tagged with ontree prefix
TAGGED_IMAGES=$(podman images --format "{{.Repository}}:{{.Tag}}" | grep -i "ontree" || true)
if [ ! -z "$TAGGED_IMAGES" ]; then
if [ ! -z "$IMAGES_TO_REMOVE" ]; then
IMAGES_TO_REMOVE="$IMAGES_TO_REMOVE"$'\n'"$TAGGED_IMAGES"
else
IMAGES_TO_REMOVE="$TAGGED_IMAGES"
fi
fi
# Remove collected images
if [ ! -z "$IMAGES_TO_REMOVE" ]; then
echo "Removing associated images..."
echo "$IMAGES_TO_REMOVE" | sort -u | while read image; do
if [ ! -z "$image" ]; then
echo " - Removing image: $image"
podman rmi -f "$image" 2>/dev/null || true
fi
done
echo "✓ Removed associated images"
else
echo " No associated images found"
fi
# Prune any dangling images to ensure complete cleanup
echo ""
echo "Pruning dangling images and build cache..."
podman image prune -af 2>/dev/null || true
echo "✓ Pruned dangling images"
# Clear build cache if available (Podman 3.0+)
podman system prune -af --volumes 2>/dev/null || true
echo "✓ Cleared Podman system cache"
else
echo ""
echo "ℹ Podman not found - skipping container cleanup"
fi
# Complete removal of /opt/ontree directory
echo ""
echo "Removing /opt/ontree directory..."
if [ -d "/opt/ontree" ]; then
rm -rf /opt/ontree
echo "✓ Removed entire /opt/ontree directory"
else
echo "ℹ /opt/ontree directory does not exist"
fi
echo ""
echo "Deep cleanup complete!"
echo "TreeOS has been completely removed from the system."
echo "All Podman containers and images have been cleaned."
echo ""
echo "To reinstall TreeOS:"
echo " 1. Download the latest release"
echo " 2. Run the setup script"
echo ""
echo "Note: Container images will be re-downloaded on next use."
description argument-hint
Deep clean ALL TreeOS production data (including shared folders)

Deep Clean ALL TreeOS Production Data

⚠️ CRITICAL CONFIRMATION REQUIRED

This command will PERMANENTLY DELETE ALL TreeOS production data including:

TreeOS Files and Data:

  • /opt/ontree/apps/ directory (application configurations)
  • /opt/ontree/shared/ directory (ALL shared data)
  • /opt/ontree/shared/ollama/ directory (ALL Ollama models)
  • /opt/ontree/logs/ directory (log files)
  • /opt/ontree/ontree.db and related SQLite files (database)
  • /opt/ontree/treeos binary

Podman Containers and Images:

  • ALL containers starting with ontree- will be stopped and removed
  • ALL associated container images will be deleted
  • Container images will need to be re-downloaded for testing scenarios
  • Podman build cache and dangling images will be pruned

This is a COMPLETE removal of TreeOS and will require full reinstallation!

To confirm this destructive operation, please type "yes" when prompted in Claude Code.

If the user confirms with "yes", proceed with deep cleanup. Otherwise, abort the operation.

Cleanup Process

Step 1: Get User Confirmation

Ask the user to confirm by typing "yes" to proceed with COMPLETE deletion.

Step 2: Execute Deep Cleanup (only if confirmed)

If the user types "yes", execute the deep cleanup script with sudo:

!sudo ./.claude/commands/clean-production-deep-noconfirm.sh

Step 3: Report Results

After successful cleanup: !echo "TreeOS has been completely removed from the system, including all containers, images, shared data and Ollama models."

If the user doesn't confirm, respond: !echo "Deep cleanup cancelled. No data was deleted."

Reinstallation

After deep cleanup, TreeOS must be completely reinstalled:

  1. Download the latest release
  2. Run the setup script
  3. All container images will be re-downloaded on first use

CRITICAL REMINDERS:

  • ALWAYS get explicit "yes" confirmation from the user before executing deep cleanup
  • Use the non-interactive script .claude/commands/clean-production-deep-noconfirm.sh after confirmation
  • Script requires sudo privileges
  • This removes EVERYTHING - complete data loss
  • Container images will be re-downloaded (important for testing download scenarios)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment