Run Mihomo Persistently on macOS | Generated by AI

Home 2026.02

Question: How to add a service in macOS to keep mihomo-darwin-amd64-v1-alpha-3035ae8 running always?

Answer:

To make mihomo (Clash Meta core) run automatically as a background service on macOS and keep restarting if it crashes, use launchd (macOS’s built-in service manager).

The recommended way is to create a LaunchDaemon (system-wide service that runs as root — usually needed for TUN mode / enhanced-mode / system proxy features).

Step-by-step guide

  1. Prepare the binary and config
    • Rename your binary to mihomo for simplicity (optional but cleaner):
      mv mihomo-darwin-amd64-v1-alpha-3035ae8 mihomo
      chmod +x mihomo
      
    • Move it to a standard location:
      sudo mkdir -p /usr/local/bin
      sudo mv mihomo /usr/local/bin/mihomo
      
    • Put your config file in a good place, for example:
      mkdir -p ~/.config/mihomo
      mv config.yaml ~/.config/mihomo/config.yaml
      

      (You can also use /etc/mihomo/config.yaml or /usr/local/etc/mihomo/config.yaml)

  2. Create the plist file

    Create this file with sudo (because LaunchDaemons must be in a system directory):

    sudo nano /Library/LaunchDaemons/com.metacubex.mihomo.plist
    

    Paste the following content (adjust paths if needed):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.metacubex.mihomo</string>
    
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/mihomo</string>
            <string>-d</string>
            <string>/Users/yourusername/.config/mihomo</string>
            <!-- Optional: add more flags if needed, e.g. -->
            <!-- <string>--log-level</string> -->
            <!-- <string>info</string> -->
        </array>
    
        <key>RunAtLoad</key>
        <true/>
    
        <key>KeepAlive</key>
        <true/>
    
        <key>StandardOutPath</key>
        <string>/var/log/mihomo.log</string>
    
        <key>StandardErrorPath</key>
        <string>/var/log/mihomo.log</string>
    
        <!-- Optional: lower priority if you want -->
        <!-- <key>Nice</key> -->
        <!-- <integer>10</integer> -->
    
        <!-- Optional: only start after network is up -->
        <!-- <key>WatchPaths</key> -->
        <!-- <array> -->
        <!--     <string>/Library/Preferences/SystemConfiguration</string> -->
        <!-- </array> -->
    </dict>
    </plist>
    

    Important notes:

    • Replace /Users/yourusername/.config/mihomo with your actual config directory
    • -d tells mihomo where the config folder is (it looks for config.yaml inside)
    • KeepAlive makes launchd restart mihomo automatically if it dies
  3. Check syntax

    sudo plutil -lint /Library/LaunchDaemons/com.metacubex.mihomo.plist
    

    Should say: /Library/LaunchDaemons/com.metacubex.mihomo.plist: OK

  4. Load and start the service

    sudo launchctl load -w /Library/LaunchDaemons/com.metacubex.mihomo.plist
    

    The -w makes it start automatically on every boot.

  5. Check status

    sudo launchctl list | grep mihomo
    

    Or see logs:

    tail -f /var/log/mihomo.log
    
  6. Stop / unload (if needed)

    sudo launchctl unload /Library/LaunchDaemons/com.metacubex.mihomo.plist
    

    Or temporarily stop without unloading:

    sudo launchctl stop com.metacubex.mihomo
    

Alternative: simpler user-level service (LaunchAgent)

If you don’t need TUN mode or root privileges:

But for most mihomo use cases (especially TUN / full system proxy), use LaunchDaemon + root.

Tips

This setup will keep mihomo running always, even after reboot or crash.

References:


Back Donate