mcpField
S
setperms

setperms

github.com/0xdarkmatterAgent 工作流7851 次安装2 周前更新
代码仓库

关于 setperms

用于初始化 Claude Code 项目级权限和 dev-shell-tools 命令行偏好的技能,也会防止本地设置被提交到 Git。

主要功能

  1. 01生成 Claude Code 本地权限
  2. 02添加现代 CLI 工具偏好规则
  3. 03覆盖前检查现有文件
  4. 04将本地设置排除在 Git 外
  5. 05提供权限和规则配置选项

适用场景

  1. 01在项目中配置 Claude Code
  2. 02应用偏好的开发命令行工具
  3. 03选择精简或扩展权限
  4. 04防止本地设置推送到远程仓库

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/0xdarkmatter/claude-mods --skill setperms

安装后在 Claude Code 中输入/setperms确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/
.gitkeep
references/
.gitkeep
scripts/
.gitkeep

详细介绍

/setperms

使用现代 dev-shell-tools 初始化 Claude Code,打造舒适的开发体验。

功能说明

安装完整的开发环境配置:

  1. 权限(.claude/settings.local.json)——预先批准的 CLI 工具
  2. 规则(.claude/rules/cli-tools.md)——优先使用现代工具的说明

来自 dev-shell-tools 的工具:

核心工具:

  • Git:完整的 git 访问权限、lazygit、gh(GitHub CLI)、delta、difft
  • 文件操作:ls、mkdir、cat、wc、tree、eza、bat、chmod
  • 搜索:rg(ripgrep)、fd、fzf、ast-grep/sg
  • 导航:zoxide/z、broot/br
  • 数据处理:jq、yq、sd、xargs
  • 分析:tokei、procs、hyperfine、dust

开发工具:

  • 包管理器:npm、npx、node、pnpm、yarn、bun、python、uv、pip、cargo、go、brew
  • 构建工具:just、make、bash、rustc
  • 网络:curl、http(httpie)、firecrawl、markitdown
  • 容器:docker、docker-compose
  • 归档:tar、zip、unzip
  • 测试:pytest
  • 数据:sort、uniq、cut、tr、xargs、tee、head、tail、diff
  • 文档:tldr
  • Windows:powershell

AI CLI 工具:

  • gemini:Google Gemini CLI(2M 上下文)
  • claude:Anthropic Claude CLI
  • codex:OpenAI Codex CLI
  • perplexity:Perplexity CLI(网页搜索)

执行流程

/setperms
    |
    +-- Check for existing .claude/ files
    |     +-- If exists: Ask to overwrite or skip
    |     +-- If not: Proceed
    |
    +-- Create .claude directory
    +-- Create .claude/rules directory
    |
    +-- Write settings.local.json (permissions)
    +-- Ensure .gitignore excludes settings.local.json (secret-safety)
    +-- Write rules/cli-tools.md (tool preferences)

说明

第 1 步:检查现有设置
ls -la .claude/settings.local.json 2>/dev/null
ls -la .claude/rules/cli-tools.md 2>/dev/null

如果文件已存在,询问用户:

  • 覆盖:完全替换
  • 跳过:保留现有文件,不做任何操作
第 2 步:创建目录
mkdir -p .claude/rules
第 3 步:写入权限文件

写入 .claude/settings.local.json:

{
  "permissions": {
    "allow": [
      "Bash(git:*)",
      "Bash(ls:*)",
      "Bash(mkdir:*)",
      "Bash(cat:*)",
      "Bash(wc:*)",
      "Bash(tree:*)",
      "Bash(curl:*)",
      "Bash(rg:*)",
      "Bash(fd:*)",
      "Bash(fzf:*)",
      "Bash(z:*)",
      "Bash(zoxide:*)",
      "Bash(br:*)",
      "Bash(broot:*)",
      "Bash(ast-grep:*)",
      "Bash(sg:*)",
      "Bash(bat:*)",
      "Bash(eza:*)",
      "Bash(delta:*)",
      "Bash(difft:*)",
      "Bash(jq:*)",
      "Bash(yq:*)",
      "Bash(sd:*)",
      "Bash(lazygit:*)",
      "Bash(gh:*)",
      "Bash(tokei:*)",
      "Bash(uv:*)",
      "Bash(just:*)",
      "Bash(http:*)",
      "Bash(procs:*)",
      "Bash(hyperfine:*)",
      "Bash(npm:*)",
      "Bash(npx:*)",
      "Bash(node:*)",
      "Bash(pnpm:*)",
      "Bash(yarn:*)",
      "Bash(bun:*)",
      "Bash(python:*)",
      "Bash(pip:*)",
      "Bash(cargo:*)",
      "Bash(go:*)",
      "Bash(rustc:*)",
      "Bash(pytest:*)",
      "Bash(make:*)",
      "Bash(docker:*)",
      "Bash(docker-compose:*)",
      "Bash(powershell -Command:*)",
      "Bash(powershell.exe:*)",
      "Bash(bash:*)",
      "Bash(chmod:*)",
      "Bash(sort:*)",
      "Bash(uniq:*)",
      "Bash(cut:*)",
      "Bash(tr:*)",
      "Bash(xargs:*)",
      "Bash(tee:*)",
      "Bash(head:*)",
      "Bash(tail:*)",
      "Bash(diff:*)",
      "Bash(tar:*)",
      "Bash(zip:*)",
      "Bash(unzip:*)",
      "Bash(command -v:*)",
      "Bash(brew:*)",
      "Bash(tldr:*)",
      "Bash(dust:*)",
      "Bash(btm:*)",
      "Bash(bottom:*)",
      "Bash(markitdown:*)",
      "Bash(firecrawl:*)",
      "Bash(gemini:*)",
      "Bash(claude:*)",
      "Bash(codex:*)",
      "Bash(perplexity:*)"
    ],
    "deny": [],
    "ask": [
      "Bash(git reset --hard:*)",
      "Bash(git checkout -- :*)",
      "Bash(git clean -f:*)",
      "Bash(git stash drop:*)",
      "Bash(git stash clear:*)",
      "Bash(git restore --worktree:*)",
      "Bash(git push --force:*)",
      "Bash(git push -f:*)",
      "Bash(git push origin --force:*)",
      "Bash(git push origin -f:*)",
      "Bash(git branch -D:*)"
    ]
  },
  "hooks": {}
}
第 3b 步:避免将 settings.local.json 提交到 git(必须)

settings.local.json 是用户专属文件,其中经常会在权限规则中累积敏感信息 (例如写入 Bash(...) 允许条目的 API 密钥、自定义命令中的令牌)。绝不能将它推送到远程仓库。完成前,请确保仓库根目录的 .gitignore 已将其排除:

# Add the rule only if it's not already present
grep -qxF '.claude/settings.local.json' .gitignore 2>/dev/null \
  || printf '\n# Local settings (user-specific; may contain API keys)\n.claude/settings.local.json\n' >> .gitignore

# If it was already tracked from a prior commit, stop tracking it (keeps the file)
git ls-files --error-unmatch .claude/settings.local.json >/dev/null 2>&1 \
  && git rm --cached .claude/settings.local.json

如果项目没有 git 仓库,则静默跳过。这与 git-ops 的推送安全检查相辅相成;该检查也会拒绝任何新增 .claude/settings.local.json 的推送——通过纵深防御,避免泄露的密钥再次出现。

第 4 步:写入规则文件

写入 .claude/rules/cli-tools.md:

# CLI Tool Preferences (dev-shell-tools)

ALWAYS prefer modern CLI tools over traditional alternatives.

## File Search & Navigation

| Instead of | Use | Why |
|------------|-----|-----|
| `find` | `fd` | 5x faster, respects .gitignore |
| `grep` | `rg` (ripgrep) | 10x faster, respects .gitignore |
| `ls` | `eza` | Git status, tree view |
| `cat` | `bat` | Syntax highlighting |
| `cd` + manual | `z`/`zoxide` | Frecent directories |
| `tree` | `eza --tree` | Interactive |

## Data Processing

| Instead of | Use |
|------------|-----|
| `sed` | `sd` |
| Manual JSON | `jq` |
| Manual YAML | `yq` |

## Git Operations

| Instead of | Use |
|------------|-----|
| `git diff` | `delta` or `difft` |
| Manual git | `lazygit` |
| GitHub web | `gh` |

## Code Analysis

- Line counts: `tokei`
- AST search: `ast-grep` / `sg`
- Benchmarks: `hyperfine`
- Disk usage: `dust`

## System Monitoring

| Instead of | Use |
|------------|-----|
| `du -h` | `dust` |
| `top`/`htop` | `btm` (bottom) |

## Documentation

| Instead of | Use |
|------------|-----|
| `man <cmd>` | `tldr <cmd>` |

## Python

| Instead of | Use |
|------------|-----|
| `pip` | `uv` |
| `python -m venv` | `uv venv` |

## Task Running

Prefer `just` over Makefiles.

## Web Fetching

| Priority | Tool | When to Use |
|----------|------|-------------|
| 1 | `WebFetch` | First attempt - fast, built-in |
| 2 | `r.jina.ai/URL` | JS-rendered pages, cleaner extraction |
| 3 | `firecrawl <url>` | Anti-bot bypass, blocked sites |

## AI CLI Tools

For multi-model analysis:

| Tool | Model | Best For |
|------|-------|----------|
| `gemini` | Gemini 2.5 | 2M context, large codebases |
| `claude` | Claude | Coding, analysis |
| `codex` | OpenAI | Deep reasoning |
| `perplexity` | Perplexity | Web search, current info |

## Git Safety

Destructive commands require confirmation (in "ask" list):

| Command | Risk | Safe Alternative |
|---------|------|------------------|
| `git reset --hard` | Loses uncommitted changes | `git stash` first |
| `git checkout -- <file>` | Discards file changes | `git stash` or `git diff` first |
| `git clean -fd` | Deletes untracked files | `git clean -n` (dry run) first |
| `git stash drop` | Permanently deletes stash | Check `git stash list` first |
| `git push --force` | Overwrites remote history | `git push --force-with-lease` |
| `git branch -D` | Deletes unmerged branch | `git branch -d` (safe delete) |

**Before destructive operations:**
1. Check status: `git status`
2. Check for uncommitted changes: `git diff`
3. Consider stashing: `git stash`
4. Use dry-run flags when available

Reference: https://github.com/0xDarkMatter/dev-shell-tools
第 5 步:确认

向用户报告:

Initialized Claude Code with dev-shell-tools:

Created:
  .claude/settings.local.json  (74 tool permissions, 11 guardrails)
  .claude/rules/cli-tools.md   (modern tool preferences)

Claude will now:
  - Auto-approve dev-shell-tools commands
  - Prefer fd over find, rg over grep, bat over cat, etc.
  - Use AI CLIs for multi-model analysis
  - Ask before destructive git commands (reset --hard, push --force, etc.)

To customize: edit files in .claude/
To add to git: git add .claude/

选项

标志效果
--force不询问,直接覆盖现有文件
--perms-only仅安装权限,跳过规则
--rules-only仅安装规则,跳过权限
--minimal最小权限(仅 git、ls、cat、mkdir)
--full添加云和容器工具(docker、kubectl、terraform 等)
--no-guardrails跳过 git 安全防护措施(“ask”列表留空)
完整模板(--full)

添加到权限中:

"Bash(podman:*)",
"Bash(kubectl:*)",
"Bash(helm:*)",
"Bash(terraform:*)",
"Bash(pulumi:*)",
"Bash(aws:*)",
"Bash(gcloud:*)",
"Bash(az:*)",
"Bash(wrangler:*)",
"Bash(flyctl:*)",
"Bash(railway:*)"

注意事项

  • 权限仅限于当前项目(不会影响其他项目)
  • 规则会指导 Claude 优先使用现代工具
  • ~/.claude/ 中的全局设置仍然适用
  • 更改会在下次使用工具时生效(无需重启)
  • 工具来源:https://github.com/0xDarkMatter/dev-shell-tools

评论

支持 Markdown