I Gave My Mac mini a Discord Account. Then I Had to Teach It When to Stop.

Next to my client work there is a constant stream of my own projects: this website, internal tools, skills, research, and a steady stream of small things in between. For the last few months I have been moving as much of that as possible onto AI agents, because the alternative is a 70 hour week that never gets shorter.

The setup below is what I ended up with. It works, it is not complicated, and the hardest part turned out to be something I did not expect: teaching the system when a task is done.

TL;DR: A headless Mac mini runs Claude Code sessions in tmux. A Discord bot starts them for me while I am out. I continue the work later in the Claude Code app. The missing piece was closing sessions again, and the only signal that survives the trip from the app back to the machine is the session title.

The situation this solves

Here is my actual day. I leave a meeting, walk to the car, and I have five minutes and one hand free. In those five minutes I know exactly what should happen next on three different projects of my own.

Until recently, those five minutes were worth nothing. I would write myself a note and do the work at night.

What I wanted instead: talk into my phone, have a real agent session start on a machine at home that has my own project folders, my MCP connections and all my context, and then pick that session up when I sit down at my desk.

The architecture, in short

Four pieces, nothing exotic.

1. A Mac mini as an always-on agent server. No screen, no keyboard, running 24/7. I reach it over Tailscale and SSH. It is the cheapest always-on machine that runs macOS, and macOS matters here because my whole toolchain is on it.

2. tmux for everything long running. Every agent session lives in a tmux window. This is not a stylistic choice, it is the official recommendation: if you want a Claude Code session to survive your SSH connection dropping, you run it inside tmux or screen. Sessions are grouped by project, so a window in the wordpress group and a window in the website group are visibly different things.

3. Syncthing for the project folders. My working directory for my own projects exists on my MacBook and on the mini, synced both ways. No cloud provider in the middle. That means the mini works on exactly the files I work on, and anything an agent writes there shows up on my laptop. What lives there is deliberately limited: my own projects, my own tools, my own content. Client work stays in the clients’ systems.

One rule I learned the hard way: machine state does not belong in a synced folder. Anything the mini needs to remember about itself lives in ~/.cache, not in the project directory. Otherwise you sync a machine-specific state file to a machine where it is wrong.

4. A chat gateway. I use Hermes Agent connected to a private Discord server. Discord because it has channels, and my channels mirror my project structure. From the channel a message arrives in, the bot knows which project group to start the session in.

The important design decision here: the gateway is a dispatcher, not a worker. When I ask it to do something project related, it does not try to solve it. It starts a Claude Code session for it. All the project knowledge lives in CLAUDE.md files, MCP connections and skills on the machine. Rebuilding that inside a chat bot would produce a worse copy of something that already exists.

What the flow looks like

I send a voice message in Discord. Roughly fifteen seconds later I get back a window name and a tappable link into the Claude Code app.

What happened in those fifteen seconds: a tmux window was created in the right project group, Claude Code started in the right folder, Remote Control was activated so I can drive the session from my phone, the session was renamed to my naming convention, and my task was handed over.

That last part sounds trivial and is not. Passing a multi paragraph, dictated instruction into a terminal is where I lost the most time. tmux send-keys treats a newline as Enter, so a long instruction gets submitted after the first paragraph and the rest arrives as follow up messages. The fix is to go through a tmux buffer instead:

printf '%s' "$TASK" | tmux load-buffer -b agent-task -
tmux paste-buffer -b agent-task -t "$TARGET"
sleep 2
tmux send-keys -t "$TARGET" Enter

One named buffer that gets overwritten, never deleted. Deleting tmux buffers while iTerm is attached in tmux integration mode tears down your connection, because iTerm keeps its own list of them.

The part nobody warns you about

Sessions do not end.

I start three sessions from my phone, work on them in the evening, finish, and go to bed. The next morning there are still three Claude processes and three tmux windows sitting there. Multiply by a few weeks and you get dozens of open sessions, some so old they have run out of context and started forgetting things.

So I went looking for the obvious answer: end the session in the app when I am done. And here is where it got interesting.

In the Claude Code desktop app there is no “end session”. There is archive and there is delete. I tested what those actually do:

Action in the appEffect on the Mac mini
ArchiveNothing. Process alive, tmux window open.
Rename to DONE - ...Arrives.
End sessionDoes not exist as a button. Typing /exit in the app works, see the update below.

The reason fits what Remote Control is: it forwards your input, not the management actions of the interface.

I got the first measurement wrong, by the way, and it is worth saying so. I checked the renamed session with claude agents --json, saw the old name, and concluded that renaming does not reach the machine either. It does. That command just reports a stale name. The new title is in two other places: the last custom-title entry in the session transcript, and the terminal title of the pane. I only noticed because I could see the new name in my terminal tab while the tool insisted otherwise.

Lesson, and I mean this generally: when a measurement says “the signal does not arrive”, look for a second source before you build an architecture on it. Especially when the user is looking at the opposite on their screen.

The solution: the title is the signal

I already renamed sessions to keep an overview. My convention is STATUS - SHORTCODE - description, so WIP - WEB - blog post legacy. When I am done, I set it to DONE - .... I did that long before any of this was automated, purely so I could find things.

That habit turned out to be the only human intent that survives the trip from the app back to the machine.

So a small watcher runs on the mini every five minutes. It does three things:

  1. Session gone? If a session I started from chat has disappeared, tell me in the conversation it came from, so the thread does not keep claiming something is running.
  2. Renamed to DONE? Ask me whether to close it.
  3. Untouched for seven days? Ask me whether to close it.

It never closes anything on its own. That is the single most important rule in the whole thing, and I would build it that way again: a session that vanishes takes a result with it that I may not have read yet.

The closing itself is a script, not a prompt. It renames the session to DONE, sends /exit, waits until the process is actually gone, then closes the tmux window. And instead of returning prose, it returns exit codes:

0  closed
4  protected, title is PAUSE or WAIT
5  session is still working or waiting for an answer
6  no open session for this conversation
7  several candidates, list is on stdout
8  Claude would not exit, window left open

That last design choice is the one I am most happy with. The chat gateway runs on a small free tier model. It should read a table, not interpret a sentence. Exit code 7 means “ask which one”, not “make a reasonable guess”. Sessions whose title starts with PAUSE or WAIT are protected, because I deliberately keep some sessions open for weeks.

I checked whether I was being naive

Before writing any of this down I went looking for the established way to do it, because parsing a title for a status word feels like the kind of thing that gets you a comment starting with “you know there’s a tool for that, right?”.

There isn’t. At least I could not find one.

Everything that exists shows runtime state: is the agent thinking, is it waiting for a permission, is it idle. The agent view does it, the desktop app does it with small coloured dots in the session list, and there is a whole family of tmux plugins that put coloured circles in front of window names. All useful. None of them can express “I, the human, consider this finished.”

There is no /done. No status field. No hook for it. The closest thing in the official docs is “auto-archive after PR merge or close”, which only works if your definition of finished is “the pull request got merged”. For website work, content and product management, that does not carry.

–> Runtime state is a machine fact. “Done” is a human judgement. Those are different things, and only one of them has tooling.

For what it is worth, the pattern itself has a decent precedent. The WIP app for GitHub parses pull request titles for the word “wip” and blocks the merge while it is there. You change state by editing a title. Hundreds of thousands of installs. So: not elegant, but not unprecedented either.

Update, August 2026: what the official docs say now

Before publishing I went back to the docs, because “there is no tool for that” is the kind of claim that ages badly. Status as of August 2026: hooks are the official way to get a signal out of a session. SessionEnd fires when the process terminates, Notification fires when a session waits for input or a permission, and the event list is long. None of them fires on /rename, none on archiving, and none means “the human is done”. The Remote Control docs confirm my table from the other side: if you end or archive a session from another device, the CLI shows a disconnect reason in its footer and “your local session keeps running”. The machine is told, it just has no way to hand that information to a script.

One thing I had underrated: /exit is on the list of commands that work from mobile and web. So there is an official way to end the process from my phone, and a SessionEnd hook would see it. It does not replace the watcher, because it leaves the tmux window behind and because archiving is still the gesture I reach for without thinking. But if all you want is the process gone, that is the supported path, and you do not need any of what follows.

The part where I do the thing you are not supposed to do

Let me be very clear about this, because someone will point it out otherwise.

The title I am reading lives in the session transcript file. And the official docs say, in plain words:

The entry format is internal to Claude Code and changes between versions, so scripts that parse these files directly can break on any release.

I read it anyway. Knowingly.

Not because I think the warning is wrong. It is correct, and one day it will bite me. I read it because it is the only place where the information exists. There is no API for it, no supported command, and the alternative is not “a cleaner solution”, the alternative is “no solution”.

That is a trade I am willing to make for something that saves me an hour a week. It is not a trade I would make in client code.

What makes it acceptable is that I built it to fail loudly and safely instead of quietly and wrongly:

  • If the format changes, the lookup finds nothing. It does not find something wrong, it finds nothing.
  • Then it falls back to the terminal title, which carries the same information through a different channel.
  • If that goes too, the seven day timer still catches every session eventually.
  • And I keep a note of which Claude Code version last produced a working read. If the version changes and the signal disappears in the same step, the system tells me why instead of just going quiet.

That last point is the one I would recommend to anyone building on an undocumented interface. Do not just handle the breakage. Predict it, write down what the breakage will look like, and have the system recognise its own symptom.

The failure mode you actually fear is not “it broke”. It is “it broke silently four weeks ago and I only notice now”.

Postscript: the update came the very next day

I got to test my own failure prediction much faster than expected.

The day after I wrote the section above, a Claude Code update landed. The tmux windows suddenly carried version numbers instead of session names, so one of the channels I read from had just changed behavior underneath me. Exactly the kind of shift I had predicted. And here is the honest part: my title reading kept working anyway. The primary source held, nothing failed, loudly or otherwise. The prediction was right about the risk and wrong about the timing.

But while checking whether I had just been lucky, I found something better. The same update had quietly fixed the original problem: claude agents --json, the official command whose stale output sent me down this entire title-parsing detour, now reports a rename from the app immediately. I verified it with a real rename; the new name showed up seconds later. The information I extract from an internal file that I am not supposed to parse is now sitting in a supported field.

So, rip out the workaround and rebuild on the official field?

Neither. The fragile path stays primary, because it works and the whole closing logic hangs off it. Behind it now runs a second watcher that reads the official field and does nothing as long as the first one does its job. They coordinate through a single shared dedupe file: whoever asks first blocks the other. The net only speaks up when the primary provably missed a case, or has been silent for twenty minutes. Then it asks the exact same question, worded identically, in the exact same Discord thread, and sends me one daily note that my main watcher is down. It also has its own canary, in case the official field ever goes stale again.

Tested the honest way: I unloaded the primary watcher, renamed a session from the app, and waited. The question arrived from the net. After reloading the primary, no double ask.

–> When the official API catches up with your workaround, do not replace, run both. The workaround has weeks of trust behind it, the official field has one successful test. Let them race, dedupe them against each other, and retire the old one when the telemetry says so, not when the changelog does.

Where each piece actually lives

This is the part I would have wanted to read somewhere, so here it is explicitly.

  • ~/bin/claude-session.sh on the mini starts a session and writes one line to ~/.cache/agent-sessions.tsv: which chat conversation it came from, the tmux target, the process ID, the session ID and the link. The conversation ID is not passed in by the model. The gateway exports the origin of every message into the environment of every shell command it runs, so the script reads it itself. A free tier model should never have to copy a nineteen digit ID correctly.
  • ~/bin/agent-report.sh on the mini is the watcher above, running from launchd every five minutes. No model involved, no tokens, just a process read.
  • ~/bin/agent-report-netz.sh is the safety net from the postscript, on its own five minute schedule. It reads the official field, shares the primary’s dedupe file, and stays silent unless the primary provably missed a case or stopped running.
  • The skill file in the gateway is essentially that exit code table plus the rule “never close unasked, never guess which session is meant”.
  • The gateway persona file got one new hard rule: do not rebuild this with tmux send-keys and kill-window. It looks like it worked and leaves the bookkeeping wrong.

That last one exists because it happened. Twice the bot closed a session by hand instead of calling the script, and the result looked perfectly fine from the outside.

Two things that cost me hours, in case they save you some

A running chat conversation does not know about changed skills. Restarting the gateway reloads them, but an open conversation keeps its old system prompt. Two test runs looked like the bot was ignoring a brand new skill. It was working from a system prompt built hours earlier. You have to start a fresh conversation as well.

Check that your watchdog actually fires. Mine had a quiet hours check for the window from 0 to 6. The condition was written for a range that wraps around midnight, and with a start hour of 0 it was true at every hour of the day. The script exited before sending, every single run, since the day it was written. Nobody noticed, because the log line is written before the check. The log filled up every five minutes and looked perfectly healthy.

A watchdog that only logs and never sends is indistinguishable from a working one. If you build one, log the decision (sent, suppressed, and why), not just the measurement.

What is still missing

The title is a workaround, and I know it. It is the only channel that happens to carry human intent back to the machine.

So, and I mean this as a genuine feature request: if archiving a session in the app produced any local signal that a script can read, none of this would be necessary. A hook, a marker in the session file, anything that reaches further than the footer of the terminal. Right now archiving is the natural “I am done here” gesture in the interface, and it is the one action that the machine cannot see.

Until then the title works, and it works well enough that I stopped thinking about it. Which is the actual goal.

FAQ

Why a Mac mini and not a Linux server?

Because my whole toolchain lives on macOS: the Claude Code desktop app, iTerm, the MCP connections, Playwright with a real browser. A Linux box would be cheaper and would have needed a second toolchain.

Why Discord and not Telegram or Slack?

Channels. My Discord channels mirror my project folders, and from the channel the gateway knows which tmux group and which folder a session belongs in. That saves a model having to guess which project I mean.

Does the watcher close sessions automatically?

No, never. It only asks. A session that disappears on its own takes a result with it that I may not have read yet. The seven day rule is a question too, not an action.

Is parsing the transcript file not reckless?

For a private tool that saves me an hour a week: no, as long as it fails loudly. I would not do it in client code. Since the last update claude agents --json carries the same information officially, and a second watcher reads exactly that field as a safety net.

Read next


If you are running a similar setup and solved this differently, I would genuinely like to know. Especially if you found a cleaner signal than the one I am parsing.

Transparency

This text was written with AI assistance. The content, experience, assessments and final editing are mine, Raimund Herms.

Scroll to Top
WordPress Cookie Plugin by Real Cookie Banner