secondsky/claude-skills / plugins/claude-code-bash-patterns/skills/claude-code-bash-patterns
claude-code-bash-patterns
FlaggedClaude Code Bash tool patterns with hooks, automation, git workflows. Use for PreToolUse hooks, command chaining, CLI orchestration, custom commands, or encountering bash permissions, command failures, security guards, hook configurations.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.4 KB |
| references/cli-tool-integration.md | markdown | 4.8 KB |
| references/git-workflows.md | markdown | 9.7 KB |
| references/hooks-examples.md | markdown | 6.7 KB |
| references/security-best-practices.md | markdown | 4.1 KB |
| references/troubleshooting-guide.md | markdown | 8.4 KB |
| scripts/bash-audit-logger.shexecutable | script | 4.7 KB |
| scripts/dangerous-command-guard.pyexecutable | script | 6.4 KB |
| scripts/package-manager-enforcer.shexecutable | script | 2.3 KB |
| templates/.envrc.example | other | 5.7 KB |
| templates/custom-command-template.md | markdown | 5.1 KB |
| templates/dangerous-commands.json | config | 2.9 KB |
| templates/github-workflow.yml | config | 3.1 KB |
| templates/settings.json | config | 3.1 KB |
scripts/package-manager-enforcer.sh
View on GitHub#!/bin/bash
#
# Package Manager Enforcer - PreToolUse Hook for Claude Code
#
# Enforces consistent package manager usage based on lockfile.
# Prevents mixing npm/pnpm/yarn in the same project.
#
# Usage:
# Configure as PreToolUse hook in ~/.claude/settings.json:
#
# {
# "hooks": {
# "PreToolUse": [
# {
# "matcher": "Bash",
# "hooks": [
# {
# "type": "command",
# "command": "~/.claude/hooks/package-manager-enforcer.sh"
# }
# ]
# }
# ]
# }
# }
#
# Input:
# Reads JSON from stdin (Claude Code PreToolUse payload shape):
# {"tool_input": {"command": "...", ...}, ...}
# Previously this hook read $CLAUDE_TOOL_INPUT (env var) — that was wrong;
# Claude Code sends the payload on stdin, not via env. With the wrong
# source, COMMAND was always empty and the block logic never fired.
#
# Exit Codes:
# 0 = Allow execution
# 2 = Block with custom error message
# Parse command from stdin (Claude Code PreToolUse JSON payload)
INPUT=$(cat)
COMMAND=$(printf '%s' "$INPUT" | jq -r '.tool_input.command // ""')
# Detect package manager from lockfile
DETECTED_PM=""
if [ -f "pnpm-lock.yaml" ]; then
DETECTED_PM="pnpm"
elif [ -f "yarn.lock" ]; then
DETECTED_PM="yarn"
elif [ -f "package-lock.json" ]; then
DETECTED_PM="npm"
else
# No lockfile detected, allow any package manager
exit 0
fi
# Check if command uses a different package manager
if printf '%s' "$COMMAND" | grep -qE '^(npm|pnpm|yarn)[[:space:]]+'; then
# Extract package manager from command
USED_PM=$(printf '%s' "$COMMAND" | grep -oE '^(npm|pnpm|yarn)' | head -n1)
# Check if it matches detected package manager
if [ "$USED_PM" != "$DETECTED_PM" ]; then
ERROR_MSG="BLOCKED: Package manager mismatch
Detected lockfile: ${DETECTED_PM}-lock.yaml / ${DETECTED_PM}.lock / package-lock.json
Command uses: ${USED_PM}
This project uses ${DETECTED_PM}. Please use '${DETECTED_PM}' instead of '${USED_PM}'.
Examples:
${DETECTED_PM} install
${DETECTED_PM} add <package>
${DETECTED_PM} run <script>
If you want to switch package managers:
1. Delete the old lockfile
2. Run '${USED_PM} install' to create new lockfile
3. Commit the new lockfile
"
echo "$ERROR_MSG" >&2
exit 2
fi
fi
# Allow execution
exit 0
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 467k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 467k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 467k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 193k | Updated | Claude CodeCodex | Verified | Install |