Skip to content

Ancienttwo/claude-code-best-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code Best Practices

Production-ready patterns for Claude Code CLI and Agent SDK

License: MIT

English | 简体中文

Target Users

User Type Start Here
🚀 New to Claude Code CLI? Quick Start - Get productive in 3 steps
🔧 Building with Agent SDK? Advanced Architecture - Production patterns

Quick Start (Claude Code CLI)

Get a complete Claude Code configuration in 3 steps:

# 1. Copy starter kit to your Claude config
cp -r ~/.claude/skills/claude-code-best-practices/assets/starter-kit/* ~/.claude/

# 2. Copy project CLAUDE.md template to your project
cp ~/.claude/skills/claude-code-best-practices/assets/examples/CLAUDE.md ./CLAUDE.md

# 3. Customize for your stack (edit CLAUDE.md, remove unused configs)

That's it! You now have agents, rules, commands, hooks, and contexts ready to use.


For Agent SDK Developers

Building production agents? Check out Advanced Architecture Patterns for battle-tested patterns including:

  • Source/MCP Integration - Clean server configuration building
  • Credential Manager - Multi-backend secret storage
  • Permission Mode System - Safe/ask/allow-all levels
  • Headless Execution - Non-interactive automation
  • Session-Scoped Tools - UI-integrated tool patterns

What's Included

Starter Kit (assets/starter-kit/)

Type Count Included
Agents 9 planner, architect, code-reviewer, tdd-guide, security-reviewer, build-error-resolver, e2e-runner, refactor-cleaner, doc-updater
Rules 8 security, coding-style, agents, git-workflow, hooks, patterns, performance, testing
Commands 10 /plan, /tdd, /code-review, /build-fix, /e2e, /learn, /refactor-clean, /test-coverage, /update-codemaps, /update-docs
Hooks 3 hooks.json, memory-persistence/, strategic-compact/
Contexts 3 dev, research, review
Skills 8 backend-patterns, frontend-patterns, coding-standards, clickhouse-io, project-guidelines-example, lsp-integration, tdd-workflow/, security-review/

Advanced Architecture (Agent SDK)

Production patterns from Craft Agents:

Pattern Purpose
SourceServerBuilder Build MCP/API server configs from sources
Dynamic API Tool Factory Single flexible tool per API with auto-auth
CredentialManager Multi-backend secret storage with priority resolution
Permission Mode System Session-scoped safe/ask/allow-all permissions
Headless Runner Non-interactive execution for CI/automation
Session-Scoped Tools Tools with UI callbacks and execution pause

Key Patterns

1. Agent-First Delegation

Complex tasks go to specialized agents, not the main session:

User: Implement user authentication
Claude: I'll use the planner agent to create an implementation plan first.
[Delegates to planner agent with focused context]

2. Context Window Management

The 200k Problem: Your 200k context window can shrink to 70k with too many MCPs/tools.

Rules:

  • Keep under 10 MCPs enabled per project
  • Under 80 tools active total
  • Use disabledMcpServers in project .claude.json
  • Compact strategically at logical breakpoints

3. TDD Workflow

Tests before implementation via /tdd command:

  1. Define interfaces first
  2. Write failing tests (RED)
  3. Implement minimal code (GREEN)
  4. Refactor (IMPROVE)
  5. Verify coverage

4. Hook Automation

Automate quality checks:

  • Block dev servers outside tmux
  • Warn about console.log statements
  • Auto-format after edits
  • TypeScript check after .ts edits

Project Structure

claude-code-best-practices/
├── SKILL.md                    # Main skill definition
├── README.md                   # This file
├── README_CN.md                # Chinese documentation
├── CONTRIBUTING.md             # Contribution guide
├── LICENSE                     # MIT License
├── assets/
│   ├── starter-kit/            # Ready-to-use configs
│   │   ├── agents/             # 9 specialized agents
│   │   ├── rules/              # 8 guardrail rules
│   │   ├── commands/           # 10 slash commands
│   │   ├── hooks/              # Hook configurations
│   │   ├── contexts/           # Mode contexts
│   │   └── skills/             # Domain knowledge
│   ├── templates/              # Config file templates
│   ├── examples/               # Example configurations
│   └── mcp-servers.json        # MCP server configs
└── references/                 # Deep-dive documentation
    ├── config-types.md         # Config type details
    ├── context-management.md   # Context window strategies
    ├── advanced-architecture.md # Agent SDK patterns
    ├── all-configs.md          # Full config catalog
    └── plugins.md              # Plugin ecosystem

Documentation

Document Description
Config Types Deep dive on each config type with full examples
Context Management MCP limits, tool management, compaction strategies
Advanced Architecture Production patterns from Craft Agents
All Configs Catalog Full catalog of all available configs
Plugins Plugin ecosystem and installation guide

Credits & Acknowledgments

This project builds upon the work of:

  • everything-claude-code by @affaanmustafa - Core configuration patterns and starter kit structure. Anthropic hackathon winner.

  • Craft Agents by Luki Labs - Advanced architecture patterns for Agent SDK. An open-source Agent-native desktop app built entirely with AI assistance.

  • Personal Experience - Additional patterns, optimizations, and documentation from real-world Claude Code usage.


Contributing

Contributions are welcome! Please read our Contributing Guide for details on:

  • Adding new agents, rules, commands, or hooks
  • Updating documentation (English + Chinese)
  • Pull request process and style guidelines

License

This project is licensed under the MIT License - see the LICENSE file for details.


Related Resources

Built-in Skills (Recommended)

  • feature-dev - Guided feature development with codebase understanding
  • code-simplifier - Simplify and refine code for clarity and maintainability

Third-Party Skills (Marketplace)

Use /marketplace to install these recommended skills:

Vercel Skills:

  • frontend-design - Production-grade frontend interfaces with high design quality
  • react-best-practices - React and Next.js performance optimization guidelines
  • agent-browser - Automate browser interactions for web testing and data extraction

Anthropic Skills:

  • ralph-loop - Agentic coding loops for iterative development
  • hookify - Hook management and automation utilities

Official Resources

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages