/ci-build:cron-block-generation-gotchasfrom ci-build
Guide for writing or debugging code that programmatically generates cron blocks (crontab entries). Use when: (1) a cron job runs fine by hand but silently never fires from cron, (2) writing an `enable`/`install`-style command that appends entries to a user's crontab, (3) cron jobs referring to paths under `~/Documents/...` or `~/Library/...` that contain spaces, (4) cron jobs invoking tools installed to `~/.local/bin`, `~/.cargo/bin`, `~/go/bin`, or a uv/pipx/npm user-install dir, (5) debugging "works in my shell, broken from cron" with no error output. Covers the two interacting gotchas — unquoted-space shell splitting and cron's stripped $PATH — plus how to reproduce cron's environment locally with `env -i` and how to generate a correct block with `shlex.quote()` and `shutil.which()`.
Ships in ci-build. 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.
A tool's "install maintenance cron jobs" command writes entries into the user's
crontab, reports success, and crontab -l shows the block — but nothing
actually runs on schedule. No error email arrives. A "status" check that greps
for the job keywords reports enabled. The job works when you run the
command by hand in your shell.
Two orthogonal cron gotchas commonly combine to produce this silent failure:
cd /Users/me/Obsidian Vault/wiki && kb index — the shell hands cd two arguments (/Users/me/Obsidian and
Vault/wiki); cd uses only the first; it fails with No such file or directory; the &&-chain short-circuits; kb never runs.$PATH. cron invokes commands via /bin/sh -c with
PATH=/usr/bin:/bin (or similar minimal default — not your login shell's
PATH). Tools installed to ~/.local/bin, ~/.cargo/bin, ~/go/bin,
~/.local/share/uv/tools/*/bin, or Homebrew's /opt/homebrew/bin are
invisible.Both failures are silent by default because cron's only feedback channel is
local mail (/var/mail/$USER) that most users never read.
Use this skill when any of these are true:
crontab -l shows the entry/usr/bin, /bin, /sbin)/bin/sh: cd: /Users/…/Obsidian: No such file or directory in /var/mail/$USER or log stream --predicate 'process == "cron"'.Rule 1: Shell-quote every path you interpolate.
Don't wrap in f-string double quotes — use the language's shell-quoting primitive. In Python:
import shlex
quoted_root = shlex.quote(root) # handles spaces, apostrophes, $, `, etc.
cron_line = f"0 2 * * * cd {quoted_root} && kb index --incremental"
Wrong: f"cd \"{root}\" && ..." — breaks on paths containing " or $.
Rule 2: Detect the tool's install dir and put it in the block.
Don't assume ~/.local/bin — the tool might be installed via Homebrew, pipx,
uv, a venv, or a vendored path. Detect at install-time:
import shutil
from pathlib import Path
bin_dir = str(Path(shutil.which("my-tool") or "").parent) or "/usr/local/bin"
cron_path = f"{bin_dir}:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin"
block = f"""# My-tool maintenance
PATH={cron_path}
0 2 * * * cd {quoted_root} && my-tool index
"""
In crontab syntax, a line of the form VAR=value (no spaces around =, must
appear before the schedule entries it applies to) sets the environment for
subsequent entries. This is cron-specific — it is NOT shell syntax.
Rule 3: Make the block's removal logic tolerate the format evolution.
If you ever add the PATH= line later (or change the schedule format), your
disable/uninstall code must recognize BOTH the legacy and new forms, or
upgraded users end up with orphaned lines. Recognize # HEADER, then strip
every subsequent line that starts with 0, *, PATH=, or is blank,
stopping at the first line that doesn't match.
Step 1: Reproduce cron's environment in your terminal.
env -i HOME="$HOME" PATH="/usr/bin:/bin" bash -c '<your cron command line>'
env -i wipes every inherited env var. Re-inject only HOME and the minimal
PATH cron uses. If your command succeeds here, it'll succeed in cron. If it
fails, you see the real error directly.
Step 2: Test cron's quoting independently from cron's PATH.
Write the literal crontab command line to a file, then run it:
cat > /tmp/crontest.sh <<'EOF'
cd /path/with spaces/here && pwd
EOF
bash /tmp/crontest.sh
# → bash: cd: /path/with: No such file or directory ← the quoting bug
Step 3: Find the actual error when cron runs the job.
grep CRON /var/log/syslog (or journalctl -u cron)log stream --predicate 'process == "cron"' (live) or
log show --predicate 'process == "cron"' --last 1hcat /var/mail/$USER — cron emails command output (stdout+stderr)
to the job owner by defaultStep 4: Check whether the status/health check actually runs the job.
Many tools' status commands only grep the crontab for job keywords, so they
report enabled even when the job is broken. A real health check runs the
command in cron's reduced environment (Step 1).
After applying the fix, verify all three of:
Command works under cron's reduced env (proves the command line):
env -i HOME="$HOME" PATH="/usr/bin:/bin" bash -c '<your cron command>'
Should exit 0 and produce the expected output.
Crontab round-trips byte-identical (proves cron doesn't mangle the block):
crontab -l > /tmp/before && crontab /tmp/before && diff <(crontab -l) /tmp/before
Should produce no output.
Sentinel test (proves the cron daemon actually runs it, including
FDA/TCC on macOS). This is the only test that catches silent FDA-denied
failures, because the daemon swallows stderr to /var/mail/$USER by
default and many macs have mail delivery disabled:
SENTINEL="<path inside FDA-gated dir, e.g. ~/Documents/foo/.cron_test>"
rm -f "$SENTINEL"
( crontab -l; echo "* * * * * date > '$SENTINEL'" ) | crontab -
# wait past the next minute boundary (60-90s)
sleep 80
[ -f "$SENTINEL" ] && echo "WORKS: $(cat "$SENTINEL")" || echo "BROKEN"
# clean up
crontab -l | grep -v "$SENTINEL" | crontab -
rm -f "$SENTINEL"
If SENTINEL appears with a timestamp matching the next minute
boundary, the daemon works end-to-end. If missing, FDA is the most
likely culprit on macOS (check System Settings → Privacy & Security →
Full Disk Access for /usr/sbin/cron).
The env -i test (1) and sentinel test (3) are complementary — (1)
isolates command problems (quoting, PATH), (3) isolates daemon
problems (FDA, launchd state, crontab parse errors). Run both when
debugging.
Bad cron block (what a naive generator emits):
# Wiki maintenance
0 2 * * * cd /Users/me/Obsidian Vault/wiki && kb index
Failure mode under cron:
cd gets two args, uses /Users/me/Obsidian, failskb at ~/.local/bin/kb is not on PATHkb never indexes; the wiki
silently goes stale for monthsGood cron block:
# Wiki maintenance
PATH=/Users/me/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin
0 2 * * * cd '/Users/me/Obsidian Vault/wiki' && kb index
Why it works:
cd receives a single quoted argument; the space is literal, the path
resolves, the && proceedsPATH= line (cron-syntax env var) prepends the install dir, so kb
resolves without a full pathkb install, re-running the generator picks up
the new location via shutil.which()Python generator (the fix pattern, condensed):
import shlex, shutil
from pathlib import Path
def cron_block(root: str, header: str, jobs: list[str]) -> str:
quoted = shlex.quote(root)
kb_path = shutil.which("kb")
bin_dir = str(Path(kb_path).parent) if kb_path else ""
path_dirs = [d for d in [bin_dir,
"/usr/local/bin",
"/opt/homebrew/bin",
"/usr/bin", "/bin"] if d]
lines = [header, "PATH=" + ":".join(path_dirs)]
for tmpl in jobs: # jobs contain "{root}" placeholders
lines.append(tmpl.format(root=quoted))
return "\n".join(lines)
macOS Full Disk Access: On macOS, cron and crontab require FDA to
access ~/Documents, ~/Desktop, and iCloud-synced folders. Even a
perfectly-quoted, PATH-corrected block will fail if cron (binary at
/usr/sbin/cron) isn't in System Settings → Privacy → Full Disk Access.
Symptom: Operation not permitted in log show --predicate 'process == "cron"' --last 8h.
crontab ≠ cron — FDA is per-binary. Users who ran kb maintenance enable (or any crontab -e/crontab -l) may see crontab already listed
in FDA because the CLI got auto-prompted when it tried to read user files.
That grant applies to /usr/bin/crontab (the editor), not to
/usr/sbin/cron (the daemon that actually runs jobs at the scheduled
times). You need both entries in the FDA list for scheduled jobs under
~/Documents etc. to execute. If only crontab is listed, the schedule
installs fine but never fires.
How to add /usr/sbin/cron to FDA (cannot be fully automated — Apple
requires GUI consent for TCC grants; tccutil only has reset, not add):
open "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"
— deep-link straight to the FDA pane/usr/sbin is hidden in Finder by default/usr/sbin/cron, Enter, Open — a "cron" row appears with the toggle onlog show --predicate 'process == "cron"' --last 1h --style compact for a
clean invocation (no permission-denied errors)Same procedure applies to any system binary needing FDA (launchd agents
running non-app binaries, custom schedulers, dtrace tools). The ⌘⇧G
trick is the key — without it the file picker won't let you select
anything under /usr/, /System/, /private/, etc.
Prefer absolute binary paths when portability matters more than
discoverability. Embedding /Users/me/.local/bin/kb in the cron line
avoids the PATH question entirely but breaks if the binary is reinstalled
elsewhere. The PATH= approach is more resilient.
launchd is macOS-native and bypasses both gotchas (plist fields are
XML strings, no shell splitting; EnvironmentVariables dict sets PATH
directly). For macOS-only tools, consider launchd over cron.
The status check anti-pattern: if your tool has a status subcommand
that only greps the crontab, document that it doesn't prove the job runs —
or make it actually dry-run the command in a cron-like env.
shlex.quote() returns single-quoted output on POSIX shells. Paths
with embedded ' become 'part1'"'"'part2' — ugly but POSIX-safe. Don't
"clean up" this output.
shlex.quote() — shell-safe quotingshutil.which() — cross-platform binary discovery~/DocumentsWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub cajias/claude-skills --plugin ci-build5 skills in this plugin
/copilot-cli-github-actionsRun GitHub Copilot CLI headlessly inside GitHub Actions (Claude/GPT models
billed via Copilot instead of a metered provider API key). Use when:
(1) building a workflow or composite action that calls `copilot -p` in CI;
(2) deciding between GITHUB_TOKEN and a PAT for Copilot CLI auth in Actions;
(3) Copilot CLI in CI fails auth confusingly even though GITHUB_TOKEN is
present in the env; (4) the CLI hangs or exits without acting because tool
permissions were not pre-approved (missing --allow-tool/--no-ask-user);
(5) choosing the flag/env var to select a Claude model in Copilot CLI;
(6) installing a Claude Code plugin/skill marketplace into Copilot CLI
(copilot plugin marketplace add / plugin install).
/gfootball-docker-apple-siliconBuild and run Google Research Football (gfootball 2.10.2) in Docker on Apple Silicon
(macOS arm64) / Python 3.12, where native pip install fails. Use when: (1) `pip install
gfootball` fails with "Google Research Football compilation failed", (2)
"ModuleNotFoundError: No module named 'psutil'" during gfootball's C++ build,
(3) "ModuleNotFoundError: No module named 'six'" at gfootball import time,
(4) "ValueError: too many values to unpack (expected 2)" on env.reset(),
(5) CMake "Compatibility with CMake < 3.5 has been removed" during the build,
(6) the `cmake` pip package tries to git-clone CMake from github and fails.
Covers the full ubuntu:24.04 Dockerfile recipe + the gym/six runtime pins.
Other plugins' skills for the same job