bash-tool
FreeNo executable scriptsNot checkedRules for using the Bash tool in Claude Code. This skill should be used when running shell commands via the Bash tool, especially for multi-command tasks…
by booch★ 18 GitHub starsAbout this skill
Bash Tool Usage
Rules for using the Bash tool correctly within AI agents. NOTE: This was written for and tested with Claude Code; other agents may need to adapt.
Critical Rules
Never use stderr redirections
Never append 2>&1, 2>/dev/null, 2>file, or ANY 2> redirect to Bash tool commands.
- The Bash tool already captures both stdout and stderr — redirections are unnecessary
- Adding redirections breaks exact-match permission rules (e.g.,
brew upgradeis allowed butbrew upgrade 2>/dev/nullis not) - This causes
PreToolUse:Bash hook errorand forces a retry - Suppressing stderr hides information the agent should read and interpret
What to do instead: Run commands plainly. If they produce errors, read the error and respond to it. "Handle gracefully" means reading and explaining the error, not hiding it.
# WRONG — suppresses useful error info, breaks permissions
python3 --version 2>/dev/null
ls /tmp/maybe 2>/dev/null
brew update 2>&1
# RIGHT — run plainly, read the result, respond intelligently
python3 --version
ls /tmp/maybe
brew update
Red Flags — You Are About to Violate This Rule
If you're thinking any of these, STOP:
| Thought | Reality |
|---|---|
| "I want clean output" | The Bash tool separates stdout/stderr for you already |
| "Suppress errors silently" | Errors are information. Read them, don't hide them. |
| "Handle gracefully = no errors" | Handle gracefully = read error, explain what happened |
"2>/dev/null isn't 2>&1" |
ALL stderr redirections are prohibited, not just 2>&1 |
| "User won't want to see errors" | You filter what to show the user in your response, not in the shell |
| "The command might fail" | Let it fail. Read the error. Respond accordingly. |
Prefer dedicated tools over shell equivalents
Do not use the Bash tool when a dedicated tool exists:
| Instead of | Use |
|---|---|
cat, head, tail |
Read tool |
grep, rg |
Grep tool |
find, ls (for search) |
Glob tool |
sed, awk (for edits) |
Edit tool |
echo >, cat <<EOF > |
Write tool |
Exception: Shell equivalents are fine when they are part of a pipeline (e.g., command | grep pattern | head -5).
Use git -C instead of cd for subdirectory git operations
When running git commands in a subdirectory (submodules, worktrees, etc.), use git -C <path> instead of cd <path> && git .... Changing directories with cd persists across Bash tool calls and causes confusion in subsequent commands.
# WRONG — changes working directory for all future commands
cd claude/plugins/marketplaces/boochtek && git status
# RIGHT — working directory stays unchanged
git -C claude/plugins/marketplaces/boochtek status
Avoid login shells for git plumbing
Use bash -c instead of bash -lc for temporary-index or git-plumbing scripts unless a login shell is explicitly required. Login shells may source profile files and emit unrelated warnings or alter the environment.
Use jq and yq for data processing
Use jq for JSON and yq for YAML instead of writing one-off Python scripts.
# WRONG — unnecessary Python script for simple JSON extraction
python3 -c "import json; print(json.load(open('config.json'))['version'])"
# RIGHT — jq is simpler and more composable
jq '.version' config.json
# WRONG — Python for YAML manipulation
python3 -c "import yaml; d=yaml.safe_load(open('config.yaml')); print(d['name'])"
# RIGHT — yq handles YAML natively
yq '.name' config.yaml
Only fall back to Python when the transformation is too complex for jq/yq (e.g., multi-file joins with complex logic, or when a Python script already exists for the task).
Permission-aware command construction
Bash permissions use exact-match patterns. When constructing commands:
- Keep commands simple and matching established patterns
- Do not add unnecessary flags, pipes, or redirections that would change the match
- If a command is allowed as
Bash(brew upgrade), run exactlybrew upgrade
Shell Compatibility: Zsh vs Bash
The Bash tool runs commands through the user's configured shell, which may be
Zsh or Bash (the tool is named "Bash" but does not guarantee Bash). Check with
echo "$ZSH_VERSION" / echo "$BASH_VERSION" when in doubt. Don't assume Bash-only
semantics — prefer constructs that work the same in both shells, and watch for
the Zsh differences below.
Unquoted variables do NOT word-split in Zsh
In Bash, an unquoted $var splits on $IFS. In Zsh, it does not — the whole
value stays one word. A loop over a space-joined scalar then runs once with the
entire string instead of once per item, usually surfacing as a "No such file or
directory" error containing every item at once.
# FRAGILE — works in Bash, breaks in Zsh (one iteration, whole string as $f)
files="a.sh b.sh c.sh"
for f in $files; do shellcheck "$f"; done
# PORTABLE — list items inline; identical
Install bash-tool in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the bash-tool skill do?
Rules for using the Bash tool in Claude Code. This skill should be used when running shell commands via the Bash tool, especially for multi-command tasks, brew updates, build scripts, or any session involving significant shell usage. Use proactively before running Bash commands.
How do I install the bash-tool skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the bash-tool skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic