bashrc 配置安全加固
bashrc
~/.bashrc 的安全包装器和设置编辑手册——在不破坏基础 claude 行为的前提下,加固 Claude/claude CLI 包装器和模型路由的协议。斜杠命令:/bashrc。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 6
- Forks
- 0
01 前言 Front Matter
- name
- bashrc
- scope
- user
- description
- Safe wrapper and settings editing playbook for ~/.bashrc — hardening protocol for editing Claude/claude CLI wrappers and model routing without breaking base claude behavior. Slash command: /bashrc.
03 SKILL.md 正文
Bashrc Maintenance
Purpose
Provide a hardening playbook for editing ~/.bashrc safely, especially around
Claude/claude wrappers and model routing.
Problem pattern from recent failures
What broke
claudem()was fixed, but plainclaudestill came from~/.claude/settings.jsonforcing MiniMax.- Config was changed in one place (
~/.bashrc) without checking all active config layers (~/.claude/settings.json, aliases, shell env exports). - A debug command was executed with ungrouped
|redirections, creating misleading...: command not foundnoise.
Why it happened
- Missing precedence check across configuration layers.
- No explicit pre-change checklist.
- No final validation proving wrapper and base command use different env stacks.
Second failure: proxy-binary PATH guards go stale silently (2026-09-09)
~/.bashrchadif [ -x "$NVM_DIR/versions/node/v22.22.0/bin/codex" ]; then path_prepend_once ...; fiintended to expose that nvm bin dir onPATH. The dir also heldcodex-auth(an unrelated npm package, the account switcher behind theca/csw/cstatusaliases), which rode along on the same prepend.- When the
codexCLI's real install moved to a Claude plugin cache path (a bash function wrappingcommand codex), the guard's target file stopped existing. The guard silently stopped firing —codexdidn't need it anymore, butcodex-authdid, and lost its onlyPATHentry point with zero error output. - Same stale-proxy pattern existed on a second machine (jeff-ubuntu), working only
by luck because
codexstill happened to exist under nvm there. - Root cause: the guard tested a different tool's existence as a cheap proxy for "is this directory worth adding to PATH," instead of testing the tool it was actually meant to protect.
Before editing — history checks
- Run
/history "bashrc minimax minimax_M3 claude settings.json" --recent 14to confirm recent context. - Run
/ms "claude ANTHROPIC_BASE_URL MINIMAX_API_KEY"to check if there is prior recovery notes. - If either output shows unresolved confusion, pause and resolve before editing.
Safe edit protocol (required)
- Read current values first
sed -n '1,220p' ~/.bashrc
cat ~/.claude/settings.json
cat ~/.claude/commands/claude* 2>/dev/null
- Decide the intended ownership of each variable
~/.claude/settings.json: global baseline forclaude.~/.bashrc: explicit shell aliases/functions (forclaudem,claudee, etc.).- Never mix responsibilities.
- Make only scoped edits
- If changing
claudebehavior, update~/.claude/settings.jsononly. - If adding/switching a wrapper (for example
claudem), keep it in~/.bashrcand avoid touching baseclaude.
- Validate with a clean check matrix before ending
env | rg 'ANTHROPIC_BASE_URL|ANTHROPIC_MODEL|MINIMAX_API_KEY|ANTHROPIC_AUTH_TOKEN'
declare -f claude claudem || true
bash -lc "source ~/.bashrc >/dev/null 2>&1; declare -f claude; declare -f claudem"
- Smoke test both entry points in a fresh shell
bash -lc "source ~/.bashrc >/dev/null 2>&1; claude --help >/tmp/claude_help.txt; head -n 2 /tmp/claude_help.txt"
bash -lc "source ~/.bashrc >/dev/null 2>&1; claudem --version"
- Verify command outputs match intent
claudeshould reflect default Anthropic settings from settings file (or explicit--modeloverride).claudemshould showMiniMax-*env in function output.
Template for wrapper edits (copy this pattern)
claudem() {
ANTHROPIC_BASE_URL="https://api.minimax.io/anthropic" \
ANTHROPIC_AUTH_TOKEN="$MINIMAX_API_KEY" \
ANTHROPIC_MODEL="MiniMax-M3" \
ANTHROPIC_SMALL_FAST_MODEL="MiniMax-M3" \
claude --dangerously-skip-permissions --teammate-mode=tmux "$@"
}
Anti-patterns
- Editing only
.bashrcand assuming it controls all Claude behavior. - Adding raw
ANTHROPIC_*values to one layer without checking the other. - Running shell greps with unescaped pipes in one-liners.
- Relying on output from
tmux/shell without checking command exit codes and source context. - Gating a
PATH-prepend ([ -x path/to/bin/<X> ]) on a different binary's existence as a proxy for "is this directory good." Test the tool actually being protected (or test the directory itself), never a stand-in command that happens to share the samebin/— if the stand-in's install location ever moves, every other tool riding on that guard silently loses itsPATHentry with no error.
Preventing stale proxy guards
- When installing, moving, or reinstalling any CLI tool, grep both
~/.bashrcand~/.zshrcfor-x .*bin/<toolname>conditionals — anywhere that tool's name appears as an existence-check target, not just where it's the tool being installed. If the guard's target file no longer matches reality, fix or remove the guard, and check whether any other alias/binary was piggy-backing on that samepath_prepend_oncecall. - After any such edit, resolve every alias defined near the touched region in a
real interactive shell —
bash -i -c 'alias <name>; command -v <target>'— not justbash -lc(aliases don't expand in non-interactive shells even with-l, which can mask a real break as a false pass).
Post-change acceptance checklist
~/.bashrcchanged only for wrapper function(s) unless explicitly asked to touch~/.claude/settings.json.- Baseline
claudepath and wrapperclaudempath are distinguishable. - Environment stack for each entry point is documented in commit notes.
- Fresh shell smoke tests pass.
- Every
[ -x path/to/bin/<X> ]PATH guard touched (or newly adjacent to an edit) tests the tool it's actually meant to protect, not a proxy binary that could move. - If multiple machines share this pattern (e.g. Mac + jeff-ubuntu), the same check was re-verified on each — a guard working on one machine "by luck" is not proof it's correct on another.
Record change summary
In the final note include:
- files changed,
- expected model path per command,
- exact validation commands + results.
If invoked without edit intent, treat this as a checklist and stop before mutating files.
04 同仓库更多 Skills
disk-reclaim-playbook
Use Disk Magician to diagnose disk growth or qualify cleanup on macOS or Linux.
claudea-bench
Compare `claudea` and normal `claude` on a fair split of comparable work by default; use `--strict` for duplicate runs of the exact same task.
pr
Alias for the canonical pr-lifecycle PR workflow skill (/pr-workflow, /prw).
whisper
OpenAI's general-purpose speech recognition model. Supports 99 languages, transcription, translation to English, and language identification. Six model sizes from tiny (39M params) to large (1550M params). Use for speech-to-text, podcast transcription, or multilingual audio processing. Best for robust, multilingual ASR.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
pr-report
This skill should be used when the user asks for a PR report, PR audit, PR delta analysis, /pr-report, or wants per-PR summary with delta files/lines. Generates a structured report for one or more open PRs covering purpose, files changed, +/− line counts, /code-standards + /thermo review findings, /ponytail simplification opportunities, file-overlap combination candidates, and /green status per pr-green-definition. Output: machine-readable JSONL + human-readable markdown. Read-only by default; can apply simplifications if user opts in.