# claude-bot: Claude Code Discord bot, confined to one workspace folder. # Install: ~/.config/systemd/user/claude-bot.service; systemctl --user enable --now claude-bot # loginctl enable-linger $USER (so it runs without you logged in) # Attach: tmux -S /run/user/$UID/claude-bot/tmux.sock attach (detach: C-b d; /login happens here) [Unit] Description=Claude Code Discord bot [Service] Type=forking WorkingDirectory=%h/workspace Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin Environment=TERM=xterm-256color RuntimeDirectory=claude-bot # Optional: GH_TOKEN= EnvironmentFile=-%h/.config/claude-bot/env # The user manager has no network-online.target. ExecStartPre=/bin/sh -c 'until getent hosts gateway.discord.gg >/dev/null; do sleep 2; done' # bwrap, not ProtectHome= and friends: on Ubuntu (kernel.apparmor_restrict_unprivileged_userns=1) # the user manager can't mount, and silently runs the service unconfined. # Everything is read-only except the --bind paths; --tmpfs hides credential dirs. # Hiding %t removes the systemd and D-Bus sockets (systemd-run would escape) and the ssh/gpg agents. ExecStart=/usr/bin/tmux -S %t/claude-bot/tmux.sock new-session -d -s claude-bot \ /usr/bin/bwrap --die-with-parent \ --ro-bind / / --dev /dev --proc /proc --tmpfs /tmp --tmpfs %t \ --bind %h/workspace %h/workspace \ --bind %h/.claude %h/.claude \ --bind %h/.claude.json %h/.claude.json \ --bind %h/.cache %h/.cache \ --tmpfs %h/.ssh --tmpfs %h/.gnupg --tmpfs %h/.config/gh \ --ro-bind /dev/null %h/.git-credentials \ claude -n claude-bot --permission-mode auto --channels plugin:discord@claude-plugins-official ExecStop=-/usr/bin/tmux -S %t/claude-bot/tmux.sock kill-server # tmux exits 0 when claude exits, so on-failure would never fire. Restart=always RestartSec=30 [Install] WantedBy=default.target