TheDecipherist/claude-code-mastery

The complete guide to Claude Code: CLAUDE.md, hooks, skills, MCP servers, and commands

License:MITLanguage:Shell1098
ai-agentsanthropicClaudeclaude-codeclaude-mdcoding-assistantdeveloper-toolsllmmcp-servers

Deep Analysis

完整的Claude Code最佳实践指南,涵盖全局配置、MCP集成、钩子强制执行、技能模块化和基于研究的工作流优化

Highly Recommended

Core Features

全局CLAUDE.md

定义一次所有项目自动继承的安全策略

MCP服务器集成

扩展Claude外部工具集成能力

自定义命令

/new-project、/security-check、/pre-commit自动化

钩子强制执行

PreToolUse、PostToolUse、Stop钩子比建议更有效

技能模块化

commit-messages和security-audit可复用知识包

单一用途聊天

基于研究证明混合主题导致39%性能下降

Technical Implementation

Architecture:分层Claude Code扩展架构:配置层、hooks强制层、skills模块层、commands命令层
Execution Flow:
配置全局CLAUDE.md

定义安全策略和项目规范

安装钩子脚本

block-secrets.py等复制到~/.claude/hooks/

配置settings.json

注册钩子指定触发条件

安装技能模块

复制技能到~/.claude/skills/

单一用途聊天

遵循一任务一聊天原则

Key Components:
钩子机制确定性规则强制执行
全局继承系统规则一致性传播
Context工程基于Anthropic最佳实践优化性能
Highlights
  • 钩子vs建议对比证明确定性执行必要性
  • 基于研究的39%性能数据支持单一用途聊天
  • 完整安全框架:block-secrets、block-dangerous-commands
  • 现成的CLAUDE.md、settings.json模板开箱即用
Use Cases
  • 团队通过全局配置统一编码标准
  • 防止Claude误操作敏感文件
  • 编辑后自动运行格式化工具
  • 新项目快速初始化
Limitations
  • 面向有CLI经验用户
  • 钩子脚本需手动维护
  • 跨平台兼容性需考虑
Tech Stack
Shell脚本Python 3.8+Claude Code CLIMCPjq

Claude Code Mastery

The complete guide to maximizing Claude Code: Global CLAUDE.md, MCP Servers, Commands, Hooks, Skills, and Why Single-Purpose Chats Matter.

🌐 Read the Guide on Our Website ← Best reading experience

TL;DR: Your global ~/.claude/CLAUDE.md is a security gatekeeper AND project scaffolding blueprint. MCP servers extend Claude's capabilities. Custom commands automate workflows. Hooks enforce rules deterministically (where CLAUDE.md can fail). Skills package reusable expertise. And research shows mixing topics in a single chat causes 39% performance degradation.


📚 Table of Contents


🚀 Quick Start

# Clone this repo
git clone https://github.com/TheDecipherist/claude-code-mastery.git
cd claude-code-mastery

# Copy hooks to your Claude config
mkdir -p ~/.claude/hooks
cp hooks/* ~/.claude/hooks/
chmod +x ~/.claude/hooks/*.sh

# Copy the settings template (review and customize first!)
cp templates/settings.json ~/.claude/settings.json

# Copy skills
mkdir -p ~/.claude/skills
cp -r skills/* ~/.claude/skills/

📖 The Guide

📱 Read on Website (recommended) | 📄 View GUIDE.md

What's Covered

Part Topic Key Takeaway
1 Global CLAUDE.md as Security Gatekeeper Define once, inherit everywhere
2 Project Scaffolding Rules Every project follows same structure
3 MCP Servers External tool integrations
4 Context7 Live documentation access
5 Custom Commands Workflow automation
6 Single-Purpose Chats 39% degradation from topic mixing
7 Skills & Hooks Enforcement over suggestion

📁 Repository Contents

claude-code-mastery/
├── GUIDE.md                    # The complete guide
├── templates/
│   ├── global-claude.md        # ~/.claude/CLAUDE.md template
│   ├── project-claude.md       # ./CLAUDE.md starter
│   ├── settings.json           # Hook configuration template
│   └── .gitignore              # Recommended .gitignore
├── hooks/
│   ├── block-secrets.py        # PreToolUse: Block .env access
│   ├── block-dangerous-commands.sh  # PreToolUse: Block rm -rf, etc.
│   ├── end-of-turn.sh          # Stop: Quality gates
│   ├── after-edit.sh           # PostToolUse: Run formatters
│   └── notify.sh               # Notification: Desktop alerts
├── skills/
│   ├── commit-messages/        # Generate conventional commits
│   │   └── SKILL.md
│   └── security-audit/         # Security vulnerability checks
│       └── SKILL.md
└── commands/
    ├── new-project.md          # /new-project scaffold
    ├── security-check.md       # /security-check audit
    └── pre-commit.md           # /pre-commit quality gates

🔧 Installation

Prerequisites

  • Claude Code installed
  • Python 3.8+ (for Python hooks)
  • jq (for JSON parsing in shell hooks)

Step-by-Step

1. Install Hooks

# Create hooks directory
mkdir -p ~/.claude/hooks

# Copy hook scripts
cp hooks/block-secrets.py ~/.claude/hooks/
cp hooks/block-dangerous-commands.sh ~/.claude/hooks/
cp hooks/end-of-turn.sh ~/.claude/hooks/

# Make shell scripts executable
chmod +x ~/.claude/hooks/*.sh

2. Configure Settings

# If you don't have settings.json yet
cp templates/settings.json ~/.claude/settings.json

# If you already have settings.json, merge the hooks section manually

3. Install Skills

# Create skills directory
mkdir -p ~/.claude/skills

# Copy skills
cp -r skills/* ~/.claude/skills/

4. Set Up Global CLAUDE.md

# Copy template
cp templates/global-claude.md ~/.claude/CLAUDE.md

# Customize with your details
$EDITOR ~/.claude/CLAUDE.md

5. Verify Installation

# Start Claude Code
claude

# Check hooks are loaded
/hooks

# Check skills are loaded
/skills

🔒 Why Hooks Matter

CLAUDE.md rules are suggestions. Hooks are enforcement.

CLAUDE.md saying "don't edit .env"
  → Parsed by LLM
  → Weighed against other context
  → Maybe followed

PreToolUse hook blocking .env edits
  → Always runs
  → Returns exit code 2
  → Operation blocked. Period.

Real-world example from a community member:

"My PreToolUse hook blocks Claude from accessing secrets (.env files) a few times per week. Claude does not respect CLAUDE.md rules very rigorously."

Hook Exit Codes

Code Meaning
0 Success, allow operation
1 Error (shown to user only)
2 Block operation, feed stderr to Claude

🧠 Why Single-Purpose Chats

Research consistently shows topic mixing destroys accuracy:

Study Finding
Multi-turn conversations 39% performance drop when mixing topics
Context rot Recall decreases as context grows
Context pollution 2% early misalignment → 40% failure rate

Golden Rule: One Task, One Chat


🤝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add your hooks, skills, or improvements
  4. Submit a PR with description

Ideas for Contributions

  • [ ] More language-specific hooks (Go, Rust, Ruby)
  • [ ] Additional skills (code review, documentation, testing)
  • [ ] Framework-specific scaffolding templates
  • [ ] MCP server configuration examples

📚 Sources

Official Documentation

Research

Community


📄 License

MIT License - See LICENSE


Built with ❤️ by TheDecipherist and the Claude Code community

Highly Recommended
agents

wshobson/agents

wshobson

Intelligent automation and multi-agent orchestration for Claude Code

The most comprehensive Claude Code plugin ecosystem, covering full-stack development scenarios with a three-tier model strategy balancing performance and cost.

25.6k2.8k3 days ago
Highly Recommended
awesome-claude-skills

ComposioHQ/awesome-claude-skills

ComposioHQ

A curated list of awesome Claude Skills, resources, and tools for customizing Claude AI workflows

The most comprehensive Claude Skills resource list; connect-apps is a killer feature.

19.9k2.0k3 days ago
Recommended
oh-my-opencode

code-yeongyu/oh-my-opencode

code-yeongyu

The Best Agent Harness. Meet Sisyphus: The Batteries-Included Agent that codes like you.

Powerful multi-agent coding tool, but note OAuth limitations.

17.5k1.2k3 days ago
Highly Recommended
ui-ux-pro-max-skill

nextlevelbuilder/ui-ux-pro-max-skill

nextlevelbuilder

An AI SKILL that provide design intelligence for building professional UI/UX multiple platforms

Essential for designers; comprehensive UI/UX knowledge base.

15.3k1.5k3 days ago
Recommended
claude-mem

thedotmack/claude-mem

thedotmack

A Claude Code plugin that automatically captures everything Claude does during your coding sessions, compresses it with AI (using Claude's agent-sdk), and injects relevant context back into future sessions.

A practical solution for Claude's memory issues.

14.0k9143 days ago
Highly Recommended
planning-with-files

OthmanAdi/planning-with-files

OthmanAdi

Claude Code skill implementing Manus-style persistent markdown planning — the workflow pattern behind the $2B acquisition.

Context engineering best practices; an open-source implementation of Manus mode.

9.3k8113 days ago