bash-defensive-patterns

bash-defensive-patterns is a skill for Claude Code from martineserios/thebrana. It costs 36 tokens per session (480 once invoked), scanned A, original, MIT.

A set of defensive techniques for writing safer and more reliable Bash shell scripts. Bash is a command-line scripting language commonly used for automation and system tasks.

In plain words
What is it for?
Use it when writing production automation, continuous-integration pipelines, deployment scripts, system utilities, or reusable shell libraries. It covers strict mode, quoting, validation, error handling, logging, and portability.
Why use it?
It helps avoid problems such as unsafe variable handling, hidden command failures, invalid input, and platform differences. The guidance is intended for scripts that need predictable error handling.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: names the AskUserQuestion tool.

Part of the brana plugin — 56 skills, 4 commands, 14 agents, 13 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/martineserios/thebrana/bash-defensive-patterns
Any agent
npx skills add martineserios/thebrana --skill bash-defensive-patterns
Clone the repo
git clone --depth 1 https://github.com/martineserios/thebrana

Made for: Claude Code.

Or install brana, the plugin that ships this one along with the rest of its 56 skills, 4 commands, 14 agents, 13 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for bash-defensive-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/martineserios/thebrana/bash-defensive-patterns.svg)](https://agentmods.dev/skills/martineserios/thebrana/bash-defensive-patterns)
Your own site
<a href="https://agentmods.dev/skills/martineserios/thebrana/bash-defensive-patterns"><img src="https://agentmods.dev/badge/skills/martineserios/thebrana/bash-defensive-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 36 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 480 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00036 $0.00480
Opus 5 $0.00018 $0.00240
Sonnet 5 $0.00007 $0.00096
Haiku 4.5 $0.00004 $0.00048

Measured 6d ago against content hash f82f5c9c7ecf, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

bash-defensive-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

system/skills/bash-defensive-patterns/SKILL.md · 48 lines

What it actually says

Bash Defensive Patterns

Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.

When to Use This Skill

  • Writing production automation scripts
  • Building CI/CD pipeline scripts
  • Creating system administration utilities
  • Developing error-resilient deployment automation
  • Writing scripts that must handle edge cases safely
  • Building maintainable shell script libraries
  • Implementing comprehensive logging and monitoring
  • Creating scripts that must work across different platforms

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices Summary

  1. Always use strict mode - set -Eeuo pipefail
  2. Quote all variables - "$variable" prevents word splitting
  3. Use [[]] conditionals - More robust than [ ]
  4. Implement error trapping - Catch and handle errors gracefully
  5. Validate all inputs - Check file existence, permissions, formats
  6. Use functions for reusability - Prefix with meaningful names
  7. Implement structured logging - Include timestamps and levels
  8. Support dry-run mode - Allow users to preview changes
  9. Handle temporary files safely - Use mktemp, cleanup with trap
  10. Design for idempotency - Scripts should be safe to rerun
  11. Document requirements - List dependencies and minimum versions
  12. Test error paths - Ensure error handling works correctly
  13. Use command -v - Safer than which for checking executables
  14. Prefer printf over echo - More predictable across systems
Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 48 lines · 36 tokens per session scan A f82f5c9c7ecf

Subscribe to this mod's changes

bash-defensive-patterns is a skill published in the GitHub repository martineserios/thebrana (3 stars, last pushed yesterday), licensed MIT. It adds 36 tokens to every session and 480 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

shell-scripting

Use this skill when writing bash or zsh scripts, parsing arguments, handling errors, or automating CLI workflows. Triggers on bash scripting, shell scripts, argument parsing, process substitution, here documents, signal trapping, exit codes, and any task requiring portable shell script development.

alibaba/anolisa · 60 tokens

bash-scripting

Use when writing or hardening a shell script that must survive another machine — a CI step, install script, cron job, git hook, devcontainer entrypoint: strict-mode leaks, quoting/word-splitting, arrays, trap cleanup, bash-vs-POSIX portability, ShellCheck findings. NOT CI workflow structure, runners, caching or matrix…

ericrisco/rsc-harness · 82 tokens

bash-scripting-safe

Write safe, robust Bash scripts — set -euo pipefail, quoting, word splitting, error handling, idempotency, and common data-loss gotchas.

vikasudasi/skill-vault · 38 tokens

shell-scripting

Skill "shell-scripting" from chaterm/terminal-skills, covering shell 脚本编写, 概述, 基础语法, 脚本结构 and 脚本描述.

chaterm/terminal-skills · 13 tokens

shell-bash

Shell scripting and Bash programming patterns.

miles990/claude-software-skills · 10 tokens

api-design

API contract design for REST and GraphQL, covering resource shape, URL and header versioning with deprecation windows, RFC 9457 Problem Details error handling, and OpenAPI specs. Use when specifying the wire contract an endpoint exposes, choosing a versioning scheme, or standardizing error response bodies across…

yonatangross/orchestkit · 76 tokens