agentleFS
uwuclxdyuwuclxdy/agenticat/skills/clean-shell/SKILL.md

clean-shell

Skill7 starsChanged 18 days agoMITView on GitHub

Defensive Bash and POSIX shell rules: strict-mode flags, traps, idempotent mutation, ShellCheck discipline, bats tests.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every mktemp gets an EXIT trap right after creation.

    line 28
  2. Very specific:

    Never echo a generated secret.

    line 30
  3. Very specific:

    Every # shellcheck disable= carries a same-line reason comment.

    line 32

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Clean Shell

Shell-specific conventions for writing, hardening, reviewing, and testing scripts. The core rules below always apply. Load the one reference file matching the task; don't load them all.

Task touchesFile
Scripts that run as root or mutate live systems: deploy/apply, firewall/sshd/sudoers edits, systemd oneshot+timer units, ssh remote-exec, rollback, cleanup traps, idempotency, parsing input a foreign process controls (/proc, argv, filenames), checking a path stays under a directoryreferences/defensive.md
.shellcheckrc, # shellcheck disable= directives, severity floors, exit codes, CI gatingreferences/shellcheck.md
Bats tests: .bats files, run, setup/teardown, PATH-stub mocking, parallel jobsreferences/bats.md

Core Rules

  • Pick set flags by intent and comment the reason next to them: set -euo pipefail for orchestration where any failure aborts; drop -e when steps may fail without aborting; set -u alone for long-running loops. A thin wrapper sets no flags and ends with exec.
  • Quote every expansion ("$var", "${arr[@]}", "$(cmd)"); -- end-of-options guard before untrusted operands.
  • Under pipefail, never pipe a writer into a consumer that exits early (grep -q, awk … exit, head, sed -n …q): the writer takes SIGPIPE and the test or assignment reads failed, intermittently (measured 1 in ~5000 for a 4-line list). Feed it a here-string (grep -Fxq -- "$x" <<<"$list"); a runtime row needs the list larger than a pipe buffer.
  • Validate input at the boundary into a checked value ("${1:?msg}", a case guard *[!0123456789]*|'', since a locale's [0-9] can match other digits); no call site re-tests a raw string. Arithmetic executes text it evaluates (a[$(cmd)] runs cmd): $(( )), (( )), let, [[ -eq/-lt/... ]], an indexed-array subscript, a ${s:off:len} offset, and any assignment to a declare -i/local -i variable; anything reaching one gets, in order: the guard; a leading-zero strip (octal in sh and bash: 08 errors, 010 is 8) with v=${v#"${v%%[!0]*}"}; v=${v:-0}; a digit count (at most 18) before any arithmetic, 10# included (19+ digits can overflow silently, comparisons too); the domain's range check. references/defensive.md holds the code for the first three steps and the 19-digit case.
  • Text another process controls is untrusted input even when a local file carries it (/proc/*/comm, /proc/*/cmdline, filenames); strip every delimiter you later split on.
  • Whether a path is or lies under a directory is a question of identity, never of strings: make $dir absolute ($PWD/$dir), then in a subshell cd -P into the path (CDPATH='', ./ before a relative path), walk cd -P .. up to /, and test [ . -ef "$dir" ] at each step, the start included. Never capture $(pwd -P): it strips a trailing newline from the name. //, /./, .. and a symlink each spell the same directory differently, and a lexical dirname walk over .. visits directories the path never enters. references/defensive.md holds the code, the non-directory cases and the race.
  • Every mktemp gets an EXIT trap right after creation. Traps are best-effort: SIGKILL, OOM-kill, and power loss skip them.
  • Anything that mutates system state is check-then-act idempotent; add flock where concurrent runs are possible.
  • Never echo a generated secret; set -x tracing and ps//proc/*/cmdline argv leak it too.
  • a refusal or hint that prints paths or commands for the user to copy is shell input: print each path printf %q-quoted behind # , keep only the commands meant to run unprefixed, and test the whole block pasted into bash -i and zsh -f -i (zsh's interactive_comments is off, so a bare # a > b still truncates b).
  • Every # shellcheck disable= carries a same-line reason comment.
  • Non-trivial scripts get bats tests covering the error paths, not just the happy path.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.