/jleechan-skills:systemdfrom jleechan-skills
Defines standards for creating, installing, and managing background systemd user-mode units and timers on Linux. Covers wrapper scripts, environment files, and clean reinstallation.
Ships in jleechan-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Linux sibling of /launchd (macOS-only). Defines the canonical standards
for creating, installing, and managing background systemd user-mode
units + timers on Linux. User mode is the right scope for hermes and other
operator jobs because it needs no root, runs in the user's session, and persists
across logout/reboot when loginctl enable-linger is on.
Cross-platform note: a job that must run on BOTH macOS and Linux ships paired plist + unit templates in its owning repo (for example
daemon/launchd/ai.example.<job>.plist.templatebesidedaemon/systemd/ai.example.daemon.service.template). Pick whichever host matches the operator's machine; do not introduce a third abstraction layer.
GH_TOKEN),
or custom PATH entries inside the unit's [Service] block as inline
Environment=KEY=value lines. Units are static, hard to update, and leak
credentials in version control.systemd-wrapper.sh)
using /bin/bash, and secrets come from EnvironmentFile= pointing at
a config file with 0600 perms outside the repo (e.g.
~/.config/systemd/user/<service>-env.conf).HOME=%h,
PATH=/usr/bin:/bin) but anything credential-bearing goes through the
wrapper + EnvironmentFile=.The wrapper script MUST source the user's interactive profile
(~/.bash_profile or ~/.bashrc) to inherit all aliases, custom exports,
and PATH updates — the same way launchd-wrapper.sh does on macOS.
set +u / set -u to prevent aborts from
unbound optional variables in strict-mode bashrcs.if [[ -f ~/.bash_profile ]]; then
set +u
source ~/.bash_profile 2>/dev/null || true
set -u
fi
GH_TOKEN) at runtime via system commands (e.g. gh auth token) when
EnvironmentFile= is empty or the token is missing./bin/systemctl,
/usr/bin/loginctl, /usr/bin/id).UnsetEnvironment=GITHUB_TOKEN GH_TOKEN in the unit so the
existing host auth can win over stale inherited tokens. A wrapper that
sources shell profiles must also unset those variables afterward, before
resolving gh auth token; otherwise the profile can reintroduce the stale
value. Use existing valid host auth; do not initiate login merely from one
failed status probe.systemctl --user disable --now <unit> before
re-enabling, to prevent duplicate timers / "Unit already exists" errors.systemctl --user daemon-reload
before enable --now. This is the Linux equivalent of launchd's
bootout + bootstrap./bin/systemctl --user disable --now "$UNIT_NAME" 2>/dev/null || true
/bin/systemctl --user daemon-reload
/bin/systemctl --user enable --now "$UNIT_NAME"
systemctl --user reload for unit
registration changes. daemon-reload is the right call.Every systemd job wrapper script should match the launchd-wrapper standard so a script that runs under one scheduler runs identically under the other:
#!/usr/bin/env bash
# systemd-wrapper.sh — bridge script for systemd user units.
#
# systemd --user services run with a minimal PATH (/usr/bin:/bin) and no
# sourced shell init. Typical tick + audit scripts depend on
# homebrew/conda tooling (br, gh, sqlite3, python3, callpath, jq) and on
# the user's git/SSH configuration. This wrapper sources the user's
# interactive login environment (with set +u / -u guards around the source
# so a strict-mode bashrc doesn't break us) before exec'ing the target
# script.
#
# Usage: systemd-wrapper.sh /absolute/path/to/target.sh [args...]
#
# Conventions:
# - First arg is the absolute path of the script to run.
# - All subsequent args are forwarded.
# - Exit code is the target script's exit code.
set -e
if [ "$#" -lt 1 ]; then
echo "Usage: $0 /absolute/path/to/target.sh [args...]" >&2
exit 64
fi
TARGET="$1"
shift
if [ ! -x "$TARGET" ]; then
echo "[systemd-wrapper] target not executable: $TARGET" >&2
exit 66
fi
# 1. Source user profile with nounset temporarily disabled.
if [[ -f ~/.bash_profile ]]; then
set +u
source ~/.bash_profile 2>/dev/null || true
set -u
elif [[ -f ~/.bashrc ]]; then
set +u
source ~/.bashrc 2>/dev/null || true
set -u
fi
# Profiles may re-export stale GitHub tokens after the unit cleared them.
unset GITHUB_TOKEN GH_TOKEN
# 2. Prepend explicit directories to PATH defensively before credential lookup.
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:/usr/local/bin:${PATH:-/usr/bin:/bin:/usr/sbin:/sbin}"
# 3. Dynamic credential resolution fallbacks.
if [[ -z "${GH_TOKEN:-}" ]]; then
GH_TOKEN="$(gh auth token 2>/dev/null || true)"
fi
export GH_TOKEN
# 4. Forward to the actual target.
exec "$TARGET" "$@"
Why this exists in addition to bash_profile sourcing: bash_profile may not exist on a fresh Linux box (
bashis not the default login shell on many distros). The explicitPATH=line +gh auth tokenfallback makes the wrapper work even with zero user customization. The launchd-wrapper pattern intentionally leaves bash_profile sourcing to launchd-wrapper.sh on macOS; on Linux we do it in the same wrapper because the default shell init files are less predictable.
Keep the unit minimal. It should only declare runtime type, working directory, the wrapper script, and logging targets — never inline secrets:
[Unit]
Description=<owning-repo> <job-name>
Documentation=https://github.com/<owner>/<owning-repo>
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
WorkingDirectory=@REPO@
ExecStart=/bin/bash @HOME@/.local/libexec/systemd-wrapper.sh @REPO@/<worker-relative-path>
# Strip shell-exported GitHub tokens so keyring auth wins (PR #206).
UnsetEnvironment=GITHUB_TOKEN GH_TOKEN
# Pulls in service-specific credentials from the file at 0600; the leading
# `-` makes the file optional — unit starts even if it doesn't exist yet.
EnvironmentFile=-@HOME@/.config/systemd/user/<service>-env.conf
# Cap runtime so a stuck process can't pin the unit forever.
TimeoutStartSec=600
# Do NOT set Restart= for Type=oneshot timers — the timer fires it again
# on its own cadence. Restart=on-failure would re-run inside the same
# OnCalendar slot, violating the launchd ThrottleInterval contract that
# the macOS twin plist already documents.
# Log destination defaults to @HOME@/.local/state/<service>/logs/<job>.log.
# If using a customized XDG_STATE_HOME, ensure the unit log path matches step 3.
StandardOutput=append:@HOME@/.local/state/<service>/logs/<job>.log
StandardError=append:@HOME@/.local/state/<service>/logs/<job>.err.log
[Install]
WantedBy=default.target
For long-running services (not timer-fired oneshots), use a template
such as daemon/systemd/ai.example.daemon.service.template:
[Service]
Type=notify
NotifyAccess=main
WorkingDirectory=@REPO@
ExecStart=@REPO@/daemon/target/release/daemon
Restart=on-failure
RestartSec=10s
WatchdogSec=7200s
KillSignal=SIGINT
TimeoutStopSec=30s
Environment=HOME=@HOME@
Environment=PATH=@HOME@/.local/bin:@HOME@/.cargo/bin:/usr/bin:/bin
StandardOutput=append:@HOME@/.local/state/<service>/logs/rust-daemon.out.log
StandardError=append:@HOME@/.local/state/<service>/logs/rust-daemon.err.log
systemd timers are separate from the service they fire (vs launchd's
single-plist model). The timer unit declares cadence; the service unit
declares what runs. Wire them via Unit=<service-name>.service in the
timer:
[Unit]
Description=Schedule <job-name>.service daily at 03:00 local
# Mirrors the launchd plist `ai.example.<job>` cadence. 03:00 chosen
# because it's a maintenance window, not urgent.
[Timer]
# Daily at 03:00:00 local time. Use `*-*-* HH:MM:00` form for fixed times
# (`OnCalendar=daily` is shorthand for midnight `*-*-* 00:00:00` in the
# systemd manager's local timezone, which is not the intended 03:00 schedule).
OnCalendar=*-*-* 03:00:00
# Catch up missed runs (e.g. machine was asleep at fire time).
Persistent=true
Unit=<job-name>.service
# Randomized delay so multiple timers set to the same minute don't
# thunder-herd; defaults to 0 if unset.
RandomizedDelaySec=60
[Install]
WantedBy=timers.target
For sub-minute polling (Linux-only vs launchd's StartInterval=N):
[Timer]
OnBootSec=60
OnUnitActiveSec=60
# Don't use both — pick the cadence shape that matches the job.
StartCalendarInterval (launchd) ⇄ OnCalendar (systemd) cheat-sheet:
| launchd | systemd |
|---|---|
<integer>240</integer> (StartInterval) | OnUnitActiveSec=240 |
<key>Hour</key><integer>3</integer> | OnCalendar=*-*-* 03:00:00 |
<key>Minute</key><integer>0</integer> | (folded into OnCalendar) |
<key>Weekday</key><integer>1</integer> | OnCalendar=Mon *-*-* 00:00:00 |
<key>ThrottleInterval</key><integer>60</integer> | (use Restart= policy on the service instead) |
<key>KeepAlive</key><true/> | WantedBy=default.target + Restart=always |
<key>RunAtLoad</key><true/> | [Install] WantedBy=default.target |
<worker-relative-path> to its path from the repository root.systemd-wrapper.sh) to
~/.local/libexec/systemd-wrapper.sh and chmod 0755 it.mkdir -p "$HOME/.local/state/<service>/logs" (or your configured state directory if customized).@HOME@ / @REPO@
placeholders (not hardcoded paths), targeting @HOME@/.local/state/<service>/logs/...
(matching the step 3 directory), commit them under
daemon/systemd/<unit>.service.template and
daemon/systemd/<unit>.timer.template./launchd step 4).loginctl enable-linger $USER (one-time; idempotent).@HOME@ and @REPO@,
write to ~/.config/systemd/user/<unit>, systemctl --user daemon-reload,
then enable --now (timer only — enable --now on the service alone does not
start the cadence). Verify with systemctl --user list-timers --no-pager | grep <job>.Why step 5 is mandatory on Linux: macOS launchd starts agents on demand regardless of session state. systemd --user services stop when the user logs out unless
linger=yesis set for the user. Without linger, a daily timer that fires at 03:00 will simply never fire on a headless box where no one is logged in at 03:00.
| Pattern | Precedent | Notes |
|---|---|---|
| Daily 03:00 audit timer | <repo>/daemon/systemd/<daily-audit>.{timer,service}.template | Best template for a G10–G13 audit timer |
| Sub-minute polling | ~/.config/systemd/user/<job>.{timer,service} | OnUnitActiveSec=60s for a 60s sweep |
| Long-running daemon | daemon/systemd/ai.example.daemon.service.template | Type=notify + WatchdogSec=7200 — the right shape when the job isn't timer-fired |
| Installer | daemon/systemd/install-systemd-user.sh | --dry-run, --render-only, --uninstall flags; expands @HOME@/@REPO@; verifies linger |
| Wrapper | daemon/launchd/launchd-wrapper.sh | Linux twin lives at ~/.local/libexec/systemd-wrapper.sh |
--user: systemctl enable foo.service without --user
tries to write to /etc/systemd/system/ and fails on a non-root shell.
Always systemctl --user for hermes and other operator jobs.daemon-reload: editing a unit file and re-enabling
without daemon-reload keeps the old unit in effect. Always reload
between edits.Type=oneshot + Restart=on-failure: triggers re-run inside the
same OnCalendar slot, breaking the cadence contract. Either pick
Type=simple + Restart= (long-running) or Type=oneshot + Restart=no
(timer-fired).OnCalendar=daily: midnight in the local timezone unless a timezone is
specified. Use *-*-* 03:00:00 for 03:00 local or an explicit timezone when
required, and verify with systemd-analyze calendar on the target host.
See systemd.time.--user services inherit the user's
~/.config/environment.d/*.conf on some distros but not others. The
wrapper script's explicit export PATH=... line is the only
cross-distro guarantee.loginctl show-user $USER -p Linger --value and expect yes.# Linger on?
loginctl show-user "$USER" -p Linger --value # must print "yes"
# Timer registered + next-fire time correct?
systemctl --user list-timers --no-pager | grep <job>
# Last run succeeded?
systemctl --user status <job>.service --no-pager
# Manual fire (debug only)
systemctl --user start <job>.service
journalctl --user -u <job>.service -n 50
# Wrapper is sourcing profile correctly? (avoid raw bash -x which could echo tokens)
~/.local/libexec/systemd-wrapper.sh /usr/bin/printenv PATH
/launchd — macOS twin; same tenets, different schedulerdaemon/systemd/install-systemd-user.sh — the owning repo's installer;
pair it with sibling templates when adding new units (e.g.
ai.example.<job>.{service,timer}.template)~/.claude/CLAUDE.md "Credentials and authentication" — never store
tokens in .env; EnvironmentFile= pointing at 0600 files outside the
repo is the Linux equivalentWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Claude Code refuses to install this plugin
.claude-plugin/plugin.json: commands: Invalid input, agents.0: Invalid string: must start with "./", agents.0: Invalid string: must end with ".md", skills.0: Invalid string: must start with "./"
.claude-plugin/plugin.json: commands: Invalid input, agents.0: Invalid string: must start with "./", agents.0: Invalid string: must end with ".md", skills.0: Invalid string: must start with "./"
Checked against Claude Code 2.1.332's install rules. The listing below is what the repository ships; Claude Code cannot install it as published.
242 skills in this plugin
/4layer/4layer - Four-Layer Minimal Repro Testing Protocol/ablationUse when diagnosing a bug in LLM/model behavior, or any stochastic system, where the cause is disputed or theorized rather than measured. Slash commands `/ablation` and `/abal`. Enforces the rule that you manipulate the REAL captured input and replay it through the REAL production path, one variable at a time, with a verbatim control arm run first to establish the base rate. Trigger phrases include "ablation", "ablate", "what actually causes", "is X the trigger", "prove the root cause", "A/B the payload", "does removing X fix it", "why does the model do this", "test the hypothesis", "root cause is disputed"./accept-adapt-reject