ClaudeCode (CC) 實(shí)踐參考

Skills and Commands

  • Skills: ~/.claude/skills - broader workflow definitions
  • Commands: ~/.claude/commands - quick executable prompts
# Example skill structure
~/.claude/skills/
  pmx-guidelines.md      # Project-specific patterns
  coding-standards.md    # Language best practices
  tdd-workflow/          # Multi-file skill with README.md
  security-review/       # Checklist-based skill  

Hooks

hook types:

  1. PreToolUse - Before a tool executes (validation, reminders)
  2. PostToolUse - After a tool finishes (formatting, feedback loops)
  3. UserPromptSubmit - When you send a message
  4. Stop - When Claude finishes responding
  5. PreCompact - Before context compaction
  6. Notification - Permission requests

使用 hookify 插件輔助編寫 hooks, 通過  /hookify觸發(fā)

Subagents

需要為每個(gè)子代理配置 tools, MCPs, permissions

# Example subagent structure
~/.claude/agents/
  planner.md           # Feature implementation planning
  architect.md         # System design decisions
  tdd-guide.md         # Test-driven development
  code-reviewer.md     # Quality/security review
  security-reviewer.md # Vulnerability analysis
  build-error-resolver.md
  e2e-runner.md
  refactor-cleaner.md

Rules and Memory

兩個(gè)實(shí)現(xiàn)途徑

  • 單文件 CLAUDE.md
  • 子目錄
~/.claude/rules/
  security.md      # No hardcoded secrets, validate inputs
  coding-style.md  # Immutability, file organization
  testing.md       # TDD workflow, 80% coverage
  git-workflow.md  # Commit format, PR process
  agents.md        # When to delegate to subagents
  performance.md   # Model selection, context management

MCPs ( Model Context Protocol)

Rule of thumb: 關(guān)掉不用的 mcp, 可有效減少token, 盡量保持在 10個(gè)以下

Plugins

plugin 是 skill, mcp, hook 的組合,只是方便批量安裝

比如:

# Add a marketplace
claude plugin marketplace add https://github.com/mixedbread-ai/mgrep

# Open Claude, run /plugins, find new marketplace, install from there
  • LSP 插件,方便代碼定位
# Enabled plugins example
typescript-lsp@claude-plugins-official  # TypeScript intelligence
pyright-lsp@claude-plugins-official     # Python type checking
hookify@claude-plugins-official         # Create hooks conversationally
mgrep@Mixedbread-Grep                   # Better search than ripgrep

Tips and Tricks

熱鍵:

  • Ctrl+U - Delete entire line (faster than backspace spam) // C-A, C-K 等價(jià)
  • ! - Quick bash command prefix // 在 code 中執(zhí)行本地 shell ,這個(gè)比較有用
  • @ - Search for files
  • / - Initiate slash commands
  • Shift+Enter - Multi-line input
  • Tab - Toggle thinking display
  • Esc Esc - Interrupt Claude / restore code
  • /fork 貌似查看運(yùn)行中工作流的消息?

  • Git Worktrees

    • git worktree add ../feature-branch feature-branch
      # Now run separate Claude instances in each worktree
      
  • tmux 方便觀察日志

    • tmux new -s dev
      # Claude runs commands here, you can detach and reattach
      tmux attach -t dev
      
  • mgrep 支持本地和網(wǎng)絡(luò)的查詢插件,通過 /mgrep 調(diào)用。

    • mgrep "function handleSubmit"  # Local search
      mgrep --web "Next.js 15 app router changes"  # Web search
      
  • 有用的命令行

    • /rewind - Go back to a previous state
    • /statusline - Customize with branch, context %, todos
    • /checkpoints - File-level undo points
    • /compact - Manually trigger context compaction

My Setup (作者的配置)

Plugins

ralph-wiggum@claude-code-plugins       # Loop automation
frontend-design@claude-code-plugins    # UI/UX patterns
commit-commands@claude-code-plugins    # Git workflow
security-guidance@claude-code-plugins  # Security checks
pr-review-toolkit@claude-code-plugins  # PR automation
typescript-lsp@claude-plugins-official # TS intelligence
hookify@claude-plugins-official        # Hook creation
code-simplifier@claude-plugins-official
feature-dev@claude-code-plugins
explanatory-output-style@claude-code-plugins
code-review@claude-code-plugins
context7@claude-plugins-official       # Live documentation
pyright-lsp@claude-plugins-official    # Python types
mgrep@Mixedbread-Grep                  # Better search

MCP Servers

{
  "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"] },
  "firecrawl": { "command": "npx", "args": ["-y", "firecrawl-mcp"] },
  "supabase": {
    "command": "npx",
    "args": ["-y", "@supabase/mcp-server-supabase@latest", "--project-ref=YOUR_REF"]
  },
  "memory": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] },
  "sequential-thinking": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
  },
  "vercel": { "type": "http", "url": "https://mcp.vercel.com" },
  "railway": { "command": "npx", "args": ["-y", "@railway/mcp-server"] },
  "cloudflare-docs": { "type": "http", "url": "https://docs.mcp.cloudflare.com/mcp" },
  "cloudflare-workers-bindings": {
    "type": "http",
    "url": "https://bindings.mcp.cloudflare.com/mcp"
  },
  "cloudflare-workers-builds": { "type": "http", "url": "https://builds.mcp.cloudflare.com/mcp" },
  "cloudflare-observability": {
    "type": "http",
    "url": "https://observability.mcp.cloudflare.com/mcp"
  },
  "clickhouse": { "type": "http", "url": "https://mcp.clickhouse.cloud/mcp" },
  "AbletonMCP": { "command": "uvx", "args": ["ableton-mcp"] },
  "magic": { "command": "npx", "args": ["-y", "@magicuidesign/mcp@latest"] }
}

Disabled per project (context window management)

# In ~/.claude.json under projects.[path].disabledMcpServers
disabledMcpServers: [
  "playwright",
  "cloudflare-workers-builds",
  "cloudflare-workers-bindings",
  "cloudflare-observability",
  "cloudflare-docs",
  "clickhouse",
  "AbletonMCP",
  "context7",
  "magic"
]

Key Hooks

{
  "PreToolUse": [
    // tmux reminder for long-running commands
    { "matcher": "npm|pnpm|yarn|cargo|pytest", "hooks": ["tmux reminder"] },
    // Block unnecessary .md file creation
    { "matcher": "Write && .md file", "hooks": ["block unless README/CLAUDE"] },
    // Review before git push
    { "matcher": "git push", "hooks": ["open editor for review"] }
  ],
  "PostToolUse": [
    // Auto-format JS/TS with Prettier
    { "matcher": "Edit && .ts/.tsx/.js/.jsx", "hooks": ["prettier --write"] },
    // TypeScript check after edits
    { "matcher": "Edit && .ts/.tsx", "hooks": ["tsc --noEmit"] },
    // Warn about console.log
    { "matcher": "Edit", "hooks": ["grep console.log warning"] }
  ],
  "Stop": [
    // Audit for console.logs before session ends
    { "matcher": "*", "hooks": ["check modified files for console.log"] }
  ]
}

Custom Status Line

Shows user, directory, git branch with dirty indicator, context remaining %, model, time, and todo count:

Rules Structure

~/.claude/rules/
  security.md      # Mandatory security checks
  coding-style.md  # Immutability, file size limits
  testing.md       # TDD, 80% coverage
  git-workflow.md  # Conventional commits
  agents.md        # Subagent delegation rules
  patterns.md      # API response formats
  performance.md   # Model selection (Haiku vs Sonnet vs Opus)
  hooks.md         # Hook documentation

Subagents

~/.claude/agents/
  planner.md           # Break down features
  architect.md         # System design
  tdd-guide.md         # Write tests first
  code-reviewer.md     # Quality review
  security-reviewer.md # Vulnerability scan
  build-error-resolver.md
  e2e-runner.md        # Playwright tests
  refactor-cleaner.md  # Dead code removal
  doc-updater.md       # Keep docs synced

Key Takeaways

  1. Don't overcomplicate - treat configuration like fine-tuning, not architecture
  2. Context window is precious - disable unused MCPs and plugins
  3. Parallel execution - fork conversations, use git worktrees
  4. Automate the repetitive - hooks for formatting, linting, reminders
  5. Scope your subagents - limited tools = focused execution
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容