Originally published at https://asadulelah.com/learn/run-an-ai-assistant-24-7-on-a-cheap-vps
Put the assistant on a small Linux server, give it one chat front door (I use a Discord bot), run every scheduled job as a systemd timer, and wire an alert that messages you when anything fails or goes quiet. The server is the easy part. The part that decides whether it is still working in three weeks is the alerting, because a scheduled job and a working job are two different claims.
I am Asadulelah, a self-taught founder and AI systems builder from Kerala. My assistant, Ziggy, has lived on one VPS for months. This page is written by it, on a timer, from that server: the weekly job that publishes these lessons is one of the timers described below.
What my setup looks like
One VPS: 4 vCPU, 16 GB of RAM, Ubuntu. On it:
- A Discord bot (
ziggy-bot, a systemd service). Each message I send becomes a headlessclaude -prun on my Claude subscription, and the answer comes back to the same channel. - My notes vault (Markdown, synced to my PC with Syncthing), so the assistant on the server and the one on my desk read the same memory.
- About thirty user-level systemd timers: a daily brief, disk care, a nightly rebuild kit, a usage guard, a weekly publishing loop, plus client jobs.
- An alert script that DMs me on Discord when a service fails, and a watchdog for the failures that don't look like failures.
- A free offsite box (Oracle Cloud's Always Free tier) that used to take the nightly backup.
No Kubernetes, no queue service, no dashboard I have to open. Discord is the interface, systemd is the scheduler, and the vault is the memory.
The steps
1. Pick a box with headroom, not the cheapest one
The assistant itself is light. What eats the machine is everything it does: a headless Chrome for browser work, builds, video renders, a database restore for a client. I started on 16 GB of RAM and it has still hit out-of-memory kills: in October one script loaded sixteen spreadsheets in a single process, climbed to about 8 GB, and the kernel killed the bot's running job twice.
So size for the heaviest thing you'll run, and cap the bot. My bot service runs with MemoryHigh=4G and MemoryMax=5G, so a runaway job dies alone instead of taking the box with it. For one-off heavy scripts, run them under ulimit -v or one file per process.
2. Make chat the front door, one conversation per channel
I wanted to reach the assistant from my phone without building an app. A Discord bot does that for free. The rule that made it useful: each channel is its own conversation. The bot keys sessions by channel ID, so my money channel remembers money and my infra channel remembers servers. Each prompt also carries the channel's name and topic, so it stays on that area.
Two upgrades came from my own complaints:
- Parallel jobs. At first the bot had one worker, and every channel queued behind every other one. Now it has six job slots, and a message in a busy channel starts at once as a branch of that channel's session (
claude --resume <session> --fork-session), so it keeps the channel's memory without blocking. - Idle limits instead of a wall clock. A fixed 20-minute timeout killed long builds. Now a job dies only after 20 minutes with no output, with a hard cap of 6 hours.
A daily sweep moves channels idle for 30 days into an archive category, read-only. Nothing is deleted automatically.
3. Run it on the subscription, not an API key
Every job is claude -p logged in to my Max subscription. If ANTHROPIC_API_KEY is set anywhere in the service's environment, Claude Code bills that key per token instead. On a box that runs jobs all night, that is how you wake up to a bill. My launch scripts never set it, and the worker launcher refuses to run if it is set.
The subscription has its own limit, so a guard timer reads the usage meter and background jobs stop at a fixed line: 80% of the 5-hour window, 90% of the week. The last slice is kept for talking to the assistant myself. The lesson on running parallel agents covers that gate in detail.
4. Turn every routine into a timer with a prompt file
Anything the assistant should do without being asked becomes a systemd user timer that drops a prompt into the bot. My daily brief is the clearest example:
~/.config/systemd/user/ziggy-morning-brief.timer # 1:30 pm Asia/Kolkata, Persistent=true -> morning_brief.sh copies .claude/briefs/morning.md -> into the bot's push folder as <channel id>--brief.msg -> the bot hands it to that channel's session The session posts the brief, sets reminder DMs for any calls that day, nudges the channels that have something due, then DMs me that the brief is up.
What I like about this shape: changing a routine means editing a Markdown file, not code. When I moved to a night schedule, the brief moved from 7:30 am to 1:30 pm by changing one line in the timer. Persistent=true means a run missed while the box was down fires when it comes back.
One gotcha: systemctl --user restart on a Persistent timer fired the brief immediately. To pick up a changed schedule, daemon-reload is enough.
To make the user timers survive logout, enable lingering once: loginctl enable-linger <user>.
5. Alert on crashes, from outside the thing that crashed
In July my nightly maintenance job died because the subscription lapsed. It failed about 70 times over 12 days and nothing told me. I found out only because I happened to ask.
The fix has two layers. Layer one catches crashes. A tiny stdlib-only Python script, ziggy-alert.py, sends me a Discord DM through the REST API. It does not depend on the bot process, so it still works when the bot is the thing that died. systemd calls it through a template unit:
# /etc/systemd/system/ziggy-alert@.service [Service] Type=oneshot ExecStart=/usr/bin/python3 /opt/ziggy-bot/ziggy-alert.py %i # /etc/systemd/system/ziggy-bot.service.d/10-alert.conf [Unit] OnFailure=ziggy-alert@%n.service Every always-on service gets that two-line drop-in. When I built it, I proved it worked with a throwaway unit that fails on purpose. An alert you have never seen fire is a guess.
6. Alert on silence too, because "exited 0" is not "worked"
OnFailure only fires on a non-zero exit. It misses a job that exits cleanly having done nothing, and a timer that stops firing. So layer two is a daily watchdog that reads the job's own state file (last_run_at) and DMs me if it is older than 24 hours. I tested that branch by forging a 12-day-old state file.
Then a third gap showed up. On 2 November the systemd user manager, the thing that runs every user timer, including the alerts, exited cleanly. Everything was silently down for about two hours. Now a root-level timer checks it every 5 minutes, restarts it and DMs me. The symptom to recognise: systemctl --user says "Failed to connect to user scope bus".
The lesson I keep relearning: the watcher has to live outside the thing it watches.
7. Throttle the alerts before they flood you
On 1 December a small web service lost its node_modules folder and crash-looped every five seconds. It had Restart=always, and every crash fired OnFailure. I got more than 500 DMs.
Now the alert script keeps a timestamp per unit and sends at most one DM per unit every six hours. Any service with Restart=always plus an alert needs that throttle. The underlying fix was one npm ci, and the alert did its job: I knew within minutes. It just should have said so once.
8. Never restart the bot from inside the bot
This one cost me silent replies more than once. The assistant's claude -p process runs inside the bot service's cgroup. So when the assistant runs systemctl restart ziggy-bot to apply its own fix, systemd kills every process in that cgroup, including the one writing the answer. I get silence.
The fix is to schedule the restart detached, in its own unit, after the reply has landed:
systemd-run --user --on-active=45 --unit=bot-restart ~/work/restart.sh The script waits until the bot reports no active job, sends SIGTERM to the main PID (Restart=always brings it back), checks health, and rolls back to the backup copy of the code if the bot doesn't come up. Any service whose cgroup holds the running session gets the same treatment.
9. Let the box clean its own disk
Small servers die of full disks, not of load. A disk-care timer runs every six hours:
- Always: Docker dangling volumes and build cache, npm/uv/pip caches,
/tmpfiles older than three days. - Above 85% full: build folders (
node_modules,.next,target) in idle projects that no process, unit or container is using. - Never: source code, data, virtual environments, named volumes, or anything belonging to a client.
It logs folder sizes over time, so when the disk climbs I can see what grew instead of guessing. Big cold folders I don't need on the server get copied to my PC, checksum-verified, and removed from the server only when the checksums match.
10. Back up a rebuild kit, not the whole disk
I used to push a nightly backup of everything to the free offsite box. It kept failing: the remote disk filled, a database dump broke when its container was stopped, and once a weekly backup filled the disk mid-copy. For four weeks in the autumn not one run succeeded.
So I changed the question from "how do I copy everything?" to "what would I need to rebuild this box on a new one?" A nightly timer now builds a rebuild kit: system config (/etc, /opt, crontabs, web roots), database dumps, Docker volumes, the bot's state, and an inventory file. Code is on GitHub and the notes sync to my PC, so neither needs to be in the kit. It is a fraction of the size and actually finishes.
One honest caveat: the restore steps are written down but I have not rehearsed them on a fresh box yet. A backup you have never restored is a hope, and that rehearsal is next on my list.
Mistakes I made
- I trusted that a timer existing meant the job was running. Twelve silent days.
- I put the alerting inside the same user manager it was meant to watch.
- I wired
OnFailureto a crash-looping service with no throttle, and got 500+ messages. - I let the assistant restart the bot it was running inside.
- I tried to back up everything instead of what a rebuild needs.
What I'd do next
If you are starting today: one VPS, one chat bot, one alert script with OnFailure, and one timer. Add the staleness watchdog when you add your first scheduled job, not after its first silent failure. Keep the prompts for routines in Markdown files so you can change behaviour without touching code. For me, the next step is rehearsing the rebuild on a scratch server, so "I can move this box in an afternoon" stops being a claim and becomes a tested fact.
Originally published at https://asadulelah.com/learn/run-an-ai-assistant-24-7-on-a-cheap-vps. More from me at https://asadulelah.com. This piece was drafted with my AI assistant, Ziggy, from the notes it keeps on how my setup actually runs.

