Engineering Notes

Engineering Notes

Thoughts and Ideas on AI by Muthukrishnan

The Complete Claude Code Best Practices Guide

06 Aug 2025

A Comprehensive Manual Compiled from Developer Experiences and Community Knowledge

Table of Contents

  1. Introduction
  2. Quick Start & Setup
  3. Configuration Mastery
  4. Core Workflows & Patterns
  5. Advanced Techniques
  6. Team Workflows
  7. Testing & Quality Assurance
  8. Security & Production Practices
  9. Cost Optimization
  10. Multi-Claude Workflows
  11. MCP Integration
  12. Troubleshooting & Tips
  13. Community Resources

Introduction

Claude Code represents a paradigm shift in software development - it’s not just a coding assistant, but a general-purpose AI agent that happens to excel at code. This guide consolidates insights from Anthropic’s internal teams, community developers, and real-world production usage to help you master Claude Code.

Key Principles


Quick Start & Setup

Installation & Authentication

# Install Claude Code
npx @anthropics/claude

# Navigate to your project and start Claude
cd your-project
npx @anthropics/claude

Essential First Steps

  1. Run /init command in any existing project to generate CLAUDE.md
  2. Set up permissions with /permissions for tools you trust
  3. Install GitHub CLI (gh) for GitHub integration
  4. Configure your shell with /terminal-setup for better UX

Key Shortcuts

IDE Integration Shortcuts

Special Commands


Configuration Mastery

CLAUDE.md Files - Your AI’s Memory

CLAUDE.md is Claude’s persistent memory. Think of it as onboarding documentation for a new team member.

Location Priority

  1. Current directory: CLAUDE.md (shared) or CLAUDE.local.md (gitignored)
  2. Parent directories: For monorepos
  3. Child directories: Pulled on-demand
  4. Global: ~/.claude/CLAUDE.md (applies to all sessions)

Essential CLAUDE.md Structure

# Project: [Project Name]

## Quick Commands
- `npm run build`: Build the project
- `npm run test`: Run tests
- `npm run lint`: Run linting
- `npm run typecheck`: Type checking

## Code Style & Standards
- Use ES modules (import/export), not CommonJS
- Destructure imports when possible
- Always run tests after code changes
- Prefer single test files over full suites for performance
- Use TypeScript strict mode

## Architecture & Key Files
- Core logic: `src/services/main_service.py`
- API routes: `src/api/routes/`
- Database models: `src/models/`
- Tests: `tests/` (mirrors src structure)

## Workflow Rules
- Branch naming: `feature/description` or `fix/description`
- Always create feature branches from `develop`
- Run linter before commits
- Write tests for new functionality

## Project-Specific Guidelines
- Never uncomment test blocks without explicit instruction
- Reuse existing DAO functions instead of creating redundant ones
- Check existing patterns before implementing new solutions
- IMPORTANT: Always validate input parameters for API endpoints
- YOU MUST: Run type checking after making changes

Advanced CLAUDE.md Techniques

Permission Management

Strategic Permission Setup

# Allow safe operations
/permissions add Edit
/permissions add "Bash(git commit:*)"
/permissions add "Bash(git push:*)"

# Allow specific MCP tools
/permissions add mcp__puppeteer__puppeteer_navigate

Team Permissions

Share permissions via .claude/settings.json:

{
  "allowedTools": [
    "Edit",
    "Bash(git commit:*)",
    "mcp__github__*"
  ]
}

Core Workflows & Patterns

1. The Explore → Plan → Code → Commit Pattern

This is the most versatile and effective workflow:

**Phase 1: Explore**
"Read the authentication module and related test files. Don't write any code yet - just explore and understand the current implementation."

**Phase 2: Plan** 
"Think harder about how to add OAuth support. Create a detailed plan considering:
- Integration with existing auth flow
- Database schema changes needed
- Testing strategy
- Security considerations"

**Phase 3: Code**
"Now implement the OAuth feature according to your plan. Verify each component works as you build it."

**Phase 4: Commit**
"Run all tests, fix any issues, and commit with a descriptive message following our conventional commit format."

Why This Works

2. Test-Driven Development (TDD) with Claude

TDD becomes incredibly powerful with Claude:

**Step 1: Write Tests First**
"Write comprehensive tests for the user authentication feature. Cover:
- Valid login scenarios
- Invalid credentials
- Session management
- Edge cases like expired tokens

Be explicit that this is TDD - don't create mock implementations."

**Step 2: Verify Test Failures**
"Run the tests and confirm they fail as expected. Don't write any implementation code yet."

**Step 3: Implement to Pass Tests**
"Now write the minimum code needed to make all tests pass. Don't modify the tests."

**Step 4: Iterate Until Green**
"Keep iterating - run tests, fix issues, repeat until all tests pass."

3. Visual Development Workflow

For UI work, use Claude’s visual capabilities:

**Setup Visual Feedback**
"Set up Puppeteer MCP server so you can take screenshots of our React app."

**Implement with Visual Targets**
"Here's the design mock [drag/drop image]. Implement this component, take a screenshot of the result, and iterate until it matches the design."

**Progressive Refinement**
"The layout is close but spacing is off. Take another screenshot and adjust the CSS until the spacing matches the design exactly."

4. The “Safe YOLO” Approach

For repetitive tasks in secure environments:

# Run with specific allowed tools (safer approach)
claude --allowedTools "Edit,Bash(eslint:*)" "Fix all ESLint errors in the src/ directory"

⚠️ Warning: Use --allowedTools to grant specific permissions. Only use --dangerously-skip-permissions in secure, isolated environments.

Use Cases:


Advanced Techniques

Extended Thinking Triggers

Claude has different thinking levels you can activate:

Subagent Orchestration

Let Claude manage specialized subagents:

"Use subagents to investigate this performance issue:
1. Have one subagent analyze the database queries
2. Have another examine the frontend bundle size
3. Have a third review the caching strategy
Then synthesize their findings into recommendations."

Context Management

Smart Context Clearing

Context Priming

Load relevant context systematically:

"Before we start, read these files to understand the context:
- @src/auth/auth_service.py
- @tests/auth/test_auth.py  
- @docs/auth_requirements.md

Then let me know when you understand the current authentication architecture."

File and Data Handling

Multiple Input Methods


Team Workflows

Shared CLAUDE.md Strategy

Create a hierarchical CLAUDE.md system:

project-root/
├── CLAUDE.md                 # Global project rules
├── frontend/CLAUDE.md        # Frontend-specific guidelines  
├── backend/CLAUDE.md         # Backend-specific patterns
└── docs/CLAUDE.md           # Documentation standards

Custom Slash Commands for Teams

Create team-specific workflows in .claude/commands/:

/project:fix-github-issue.md

Please analyze and fix GitHub issue: $ARGUMENTS

Follow our team process:
1. Use `gh issue view` to get issue details
2. Create feature branch: `git checkout -b fix/issue-$ARGUMENTS`
3. Search codebase for relevant files
4. Implement fix following our coding standards
5. Write/update tests to verify the fix
6. Run full test suite and linting
7. Commit with format: `fix: resolve issue #$ARGUMENTS - [description]`
8. Push and create PR with our template

/project:code-review.md

Perform comprehensive code review of recent changes:

1. **Standards Compliance**
   - Check TypeScript/React conventions
   - Verify proper error handling
   - Ensure accessibility standards

2. **Quality Assurance**  
   - Review test coverage
   - Check for security vulnerabilities
   - Validate performance implications

3. **Documentation**
   - Confirm documentation is updated
   - Check for inline comments where needed

Use our established checklist and update CLAUDE.md with new patterns.

Prompt Plans for Complex Projects

Use structured prompt planning for large features:

spec.md - High-level specification

# Feature: Real-time Collaboration

## Requirements
- Multiple users can edit documents simultaneously
- Changes sync in real-time
- Conflict resolution for concurrent edits
- Offline support with sync on reconnect

## Technical Approach
- WebSocket connections for real-time updates
- Operational Transform for conflict resolution  
- Redux for state management
- IndexedDB for offline storage

prompt_plan.md - Implementation steps

# Implementation Plan

## Phase 1: Backend Infrastructure ✅
- [x] Set up WebSocket server
- [x] Implement basic message routing
- [x] Create user session management

## Phase 2: Real-time Sync (IN PROGRESS)
- [ ] Implement operational transform algorithm
- [ ] Add conflict resolution logic  
- [ ] Create client-side WebSocket handler

## Phase 3: Offline Support
- [ ] Add IndexedDB persistence
- [ ] Implement sync queue
- [ ] Handle reconnection scenarios

## Phase 4: Testing & Polish
- [ ] Write comprehensive test suite
- [ ] Add error handling and edge cases
- [ ] Performance optimization

Testing & Quality Assurance

Test-First Development Pattern

"We're implementing TDD. First, write comprehensive tests for the shopping cart feature:
- Add items to cart
- Remove items from cart  
- Update quantities
- Calculate totals with tax
- Handle discount codes
- Manage cart persistence

Don't implement any actual cart logic yet - just the test cases."

Automated Code Review Setup

Use GitHub Actions with Claude Code:

# In Claude Code terminal
/install-github-app

Then customize the review prompt in claude-code-review.yml:

direct_prompt: |
  Review this PR focusing on:
  - Security vulnerabilities and input validation
  - Logic errors and edge cases  
  - Performance implications
  - Code maintainability
  
  Be concise - only report significant issues, not style preferences.

Quality Gates with Pre-commit Hooks

Set up comprehensive quality checks:

# .pre-commit-config.yaml  
repos:
  - repo: local
    hooks:
      - id: tests
        name: Run test suite
        entry: npm test
        language: system
      - id: typecheck  
        name: TypeScript check
        entry: npm run typecheck
        language: system
      - id: lint
        name: ESLint check
        entry: npm run lint
        language: system

Testing Strategies by Language

Python Projects

"Set up pytest with these fixtures and test patterns:
- Database fixtures with rollback
- API client fixtures  
- Mock external services
- Coverage reporting with minimum 80% threshold"

JavaScript/TypeScript Projects

"Configure Jest with:
- Component testing with React Testing Library
- Integration tests for API endpoints
- E2E tests with Playwright
- Visual regression tests for UI components"

Security & Production Practices

Secure Development Workflow

Code Security Reviews

Create a security-focused CLAUDE.md section:

## Security Requirements

### Input Validation
- ALWAYS validate and sanitize user input
- Use parameterized queries for database operations
- Implement proper authentication checks

### Sensitive Data Handling  
- Never log sensitive data (passwords, tokens, PII)
- Use environment variables for secrets
- Implement proper session management

### Security Testing
- Run dependency vulnerability scans
- Test for common OWASP vulnerabilities
- Validate API authentication and authorization

Security-First Prompts

"Review this authentication endpoint as a security expert. Focus on:
1. Input validation and sanitization
2. SQL injection vulnerabilities  
3. Authentication bypass scenarios
4. Session management security
5. Rate limiting and brute force protection

Identify any security risks and provide specific fixes."

Production Deployment Patterns

Infrastructure as Code

"Create Terraform configuration for:
- Auto-scaling web servers
- RDS database with backups
- Redis cache cluster
- Load balancer with SSL
- CloudWatch monitoring

Follow security best practices for network isolation and access control."

CI/CD Pipeline Setup

"Set up GitHub Actions workflow that:
1. Runs security scans on dependencies
2. Executes full test suite
3. Builds production artifacts
4. Deploys to staging environment
5. Runs smoke tests
6. Promotes to production with approval gate
7. Sends Slack notifications for status updates"

Handling Sensitive Code

Never share:

Best practices:


Cost Optimization

Token Management Strategies

Efficient Context Usage

Resource Management for Teams

Usage Monitoring

Monitor usage through Claude’s built-in tracking and third-party tools:

# Check current session usage
/usage

# View conversation statistics
/stats

Workflow Optimization

Batch Operations

"Process these 15 similar API endpoints in batch:
1. Add input validation
2. Update error handling  
3. Add logging
4. Update tests
5. Generate documentation

Work through them systematically, committing after each group of 3."

Parallel Processing

Run multiple Claude instances for independent tasks:

# Terminal 1: Frontend work
cd frontend && claude

# Terminal 2: Backend API  
cd backend && claude

# Terminal 3: Testing
cd tests && claude

Multi-Claude Workflows

Git Worktrees for Parallel Development

# Create worktrees for parallel work
git worktree add ../project-feature-a -b feature-a
git worktree add ../project-feature-b -b feature-b  
git worktree add ../project-bugfix -b bugfix

# Start Claude in each
cd ../project-feature-a && claude
# (repeat in separate terminals)

Review and Implementation Pattern

Terminal 1: Implementation

"Implement the new payment processing feature according to the spec in @docs/payment-spec.md"

Terminal 2: Review

"Review the payment processing code that was just implemented. Focus on:
- Security vulnerabilities
- Error handling completeness  
- Test coverage
- Code maintainability"

Terminal 3: Integration

"Integrate the reviewed payment code with feedback from the reviewer. Address all security concerns and add missing tests."

Specialized Agent Coordination

Use different Claude instances for specialized roles:

# Architecture Agent
"Act as a senior architect. Design the microservice structure for our e-commerce platform."

# Security Agent  
"Act as a security expert. Review the authentication system for vulnerabilities."

# Performance Agent
"Act as a performance engineer. Optimize the database queries and caching strategy."

MCP Integration

Essential MCP Servers

GitHub Integration

claude mcp install @modelcontextprotocol/server-github

Web Search & Research

claude mcp install @modelcontextprotocol/server-brave-search

Browser Automation

claude mcp install @modelcontextprotocol/server-puppeteer

Database Access

claude mcp install @modelcontextprotocol/server-postgresql

Advanced MCP Workflows

Documentation Generation

"Use the GitHub MCP server to:
1. Fetch all README files from our repositories
2. Analyze common documentation patterns
3. Generate comprehensive docs for our new microservice
4. Create standardized README template for future projects"

Automated Testing

"Use Puppeteer MCP server to:
1. Navigate to our staging environment
2. Test the complete user registration flow
3. Take screenshots at each step
4. Generate automated test report with visual validation"

Custom MCP Server Development

For team-specific needs:

// Custom MCP server for internal APIs
const server = new McpServer({
  name: 'company-internal-api',
  version: '1.0.0'
});

server.addTool({
  name: 'query_user_analytics',
  description: 'Query our internal user analytics API',
  inputSchema: {
    type: 'object',
    properties: {
      metric: { type: 'string' },
      timeRange: { type: 'string' }
    }
  }
});

Troubleshooting & Tips

Common Issues & Solutions

Context Window Management

Problem: Claude loses track in long conversations Solution:

"Before continuing, create a summary of our current progress and save it to progress.md. Then use /compact to optimize context."

Permission Errors

Problem: Constant permission prompts Solution:

# Add commonly used tools to allowlist
/permissions add Edit
/permissions add "Bash(git:*)"
/permissions add "Bash(npm:*)"

Code Quality Issues

Problem: Claude generates working but low-quality code Solution: Improve CLAUDE.md with specific examples:

## Code Quality Standards

❌ Bad: Direct database queries in controllers
```python
def get_user(user_id):
    return db.execute("SELECT * FROM users WHERE id = %s", user_id)

✅ Good: Use repository pattern

def get_user(user_id):
    return UserRepository.find_by_id(user_id)

### Performance Optimization

#### Faster Feedback Loops
- Use subagents for parallel investigation
- Batch similar operations together  
- Keep conversations focused on single objectives
- Use `/clear` between unrelated tasks

#### Effective Prompting
```markdown
# Instead of vague requests
"Make the code better"

# Be specific about improvements  
"Refactor the authentication middleware to:
1. Extract validation logic into separate functions
2. Add proper error handling with specific error messages
3. Improve type safety with TypeScript
4. Add unit tests covering edge cases"

Debugging Strategies

Stack Trace Analysis

"Analyze this stack trace and production logs. Trace the control flow through our codebase and identify:
1. Root cause of the error
2. Contributing factors  
3. Specific fix needed
4. Prevention strategies for similar issues"

Performance Investigation

"Use subagents to investigate this performance issue:
1. Database Agent: Analyze slow queries and indexing
2. Frontend Agent: Check bundle size and render performance  
3. Network Agent: Review API response times and caching
Synthesize findings with specific optimization recommendations."

Community Resources

Official Resources

Community Collections

Awesome Claude Code Repository

Specialized Agent Collections

Tools & Utilities

Learning Resources

Video Guides & Tutorials

Blog Posts & Articles

Community Forums

Contributing to the Community

Sharing Best Practices

Open Source Contributions


Conclusion

Claude Code represents a fundamental shift in how we approach software development. It’s not just about generating code faster - it’s about operating at a higher level of abstraction, focusing on what we want to build rather than the mechanics of building it.

The most successful Claude Code users treat it as an intelligent collaborator rather than a magic black box. They:

As AI continues to evolve, the developers who learn to orchestrate these tools effectively will have significant competitive advantages. Start with the basics in this guide, experiment with advanced patterns, and most importantly - share your discoveries with the community.

The future of software development is collaborative intelligence between humans and AI. Claude Code gives us a powerful platform to explore that future today.


This guide is a living document compiled from community contributions. For the latest updates and community discussions, join the Claude Code community on GitHub and Discord.