Claude Code CLAUDE.md Workshop Exercises
Overview
Hands-on exercises for learning CLAUDE.md best practices. Each exercise builds on previous concepts, progressing from basic to advanced patterns.
Workshop Structure
- Basic Setup Exercise (15 min)
- TypeScript Project Exercise (20 min)
- Team Collaboration Exercise (20 min)
- Advanced Patterns Exercise (25 min)
- Real World Scenario Exercise (30 min)
- Exercise Solutions (20 min)
Exercise 1 - Basic Setup
Time: 15 minutes
Objective
Create your first CLAUDE.md file for a simple Node.js project.
Starting Point
mkdir todo-cli
cd todo-cli
npm init -y
npm install typescript @types/node --save-devTask
Create a CLAUDE.md file that includes:
- Project description
- Available npm scripts
- Project structure
- Basic coding standards
Starter Template
# Project:
Purpose:
# Commands
-
-
-
# Structure
-
-
# Standards
-
- Success Criteria
- Claude understands project purpose
- Commands are concise and clear
- Structure helps navigation
- Standards are actionable
Discussion Points
- Why conciseness matters
- Token usage awareness
- Living documentation concept
Exercise 2 - TypeScript Project
Time: 20 minutes
Objective
Enhance CLAUDE.md for a TypeScript React project with testing.
Starting Point
npx create-vite@latest task-manager --template react-ts
cd task-manager
npm install
npm install -D vitest @testing-library/react @testing-library/jest-domTask
Create a comprehensive CLAUDE.md that includes:
- TypeScript configuration preferences
- React component patterns
- Testing requirements
- Import conventions
- State management approach
Requirements Checklist
Must include:
□ TypeScript strict mode rules
□ Component structure pattern
□ Test file naming convention
□ Import organization
□ At least one "bad example"Bonus Challenges
- Add a custom slash command idea
- Include performance considerations
- Add accessibility requirements
Expected Outcome Example
# Task Manager App
Stack: React 18, TypeScript 5.2, Vite, Zustand
# TypeScript
- strict: true
- No any types
- Explicit return types
- Interface > Type for objects
# Components
Structure:
- FC with explicit props
- Props interface above component
- Hooks at top
- Early returns for guards
❌ Bad:
export default function Button({onClick, children}: any) {...}
✅ Good:
interface ButtonProps {
onClick: () => void
children: React.ReactNode
}
export const Button: FC<ButtonProps> = ({ onClick, children }) => {...}
# Testing
- *.test.tsx adjacent to component
- Coverage target: 80%
- Test user behavior, not implementation
- Mock with MSW
# Imports
1. React/Next
2. Third-party libs
3. @/ aliases
4. Relative imports
5. Types last
# State
- Zustand for global
- useState for local
- React Query for serverExercise 3 - Team Collaboration
Time: 20 minutes
Objective
Set up CLAUDE.md files for team collaboration with personal preferences.
Scenario
You’re working on a team project with:
- Shared coding standards
- Different developer preferences
- CI/CD requirements
- Multiple environments
Task
Create three files:
CLAUDE.md- Team standards (git tracked)CLAUDE.local.md- Personal preferences (gitignored).claude/commands/review.md- Custom review command
Team Requirements
The team has agreed on:
- ESLint + Prettier
- Conventional commits
- PR requires 2 approvals
- 90% test coverage
- No console.logs in productionPersonal Preferences Examples
Choose your preferences:
- npm vs yarn vs pnpm
- 2 spaces vs 4 spaces vs tabs
- Single vs double quotes
- Semicolons vs no semicolons
- Testing: watch mode vs single runCustom Command Template
Create .claude/commands/review.md:
Review the code in $ARGUMENTS for:
1. TypeScript strict compliance
2. Test coverage
3. Performance implications
4. Security concerns
5. Accessibility requirements
Output format:
## ✅ Looks Good
-
## ⚠️ Suggestions
-
## ❌ Must Fix
- Advanced Challenge
Add import statements to modularize configuration:
# CLAUDE.md
@./docs/api-standards.md
@./docs/component-guidelines.md
@~/.claude/personal-shortcuts.mdExercise 4 - Advanced Patterns
Time: 25 minutes
Objective
Implement advanced CLAUDE.md patterns for a monorepo project.
Setup
mkdir acme-platform
cd acme-platform
npx create-turbo@latestMonorepo Structure
acme-platform/
├── apps/
│ ├── web/ # Next.js app
│ └── api/ # Express API
├── packages/
│ ├── ui/ # Shared components
│ ├── types/ # Shared TypeScript types
│ └── utils/ # Shared utilities
└── CLAUDE.md # Root configuration
Tasks
1. Root CLAUDE.md
Create hierarchical configuration:
# Monorepo: ACME Platform
Tool: Turborepo
Package manager: pnpm
# Global Commands
- install: pnpm install
- dev: turbo dev
- build: turbo build
- test: turbo test
# Architecture Rules
-
-
-
# Import package configs
@./packages/ui/CLAUDE.md
@./packages/types/CLAUDE.md
@./apps/web/CLAUDE.md
@./apps/api/CLAUDE.md2. Package-Specific CLAUDE.md
Create at least two package-specific files:
packages/ui/CLAUDE.md:
# Package: @acme/ui
Purpose: Shared React components
# Exports
- Components from src/index.ts
- Styles as CSS modules
- Types included
# Component Rules
-
- apps/web/CLAUDE.md:
# App: Web Frontend
Framework: Next.js 14 App Router
# Features
-
-
# Routes
-
- 3. Performance Optimization
Add context management:
# Performance
- Max context: 3 levels
- Exclude: node_modules, .next, dist
- Focus: Current package
# Smart Loading
When working on:
- UI: Load only @acme/ui
- API: Load only @acme/api
- Types: Load all packagesSuccess Metrics
- Each package has specific rules
- No duplicate information
- Clear command structure
- Performance considered
- Imports used effectively
Exercise 5 - Real World Scenario
Time: 30 minutes
Objective
Create a production-ready CLAUDE.md for an e-commerce platform.
Scenario
You’re building an e-commerce platform with:
- Next.js frontend
- Node.js/Express API
- PostgreSQL database
- Redis caching
- Stripe payments
- Real-time inventory updates
- Multi-language support
- SEO requirements
Requirements
Technical Stack
- TypeScript everywhere
- tRPC for type-safe API
- Prisma for database
- Bull for job queues
- Socket.io for real-time
Business Requirements
- PCI compliance for payments
- GDPR compliance for EU
- 99.9% uptime SLA
- <3s page load time
- Support 10k concurrent users
Your Task
Create a comprehensive CLAUDE.md that covers:
- Architecture Overview
- Development Workflow
- Security Requirements
- Performance Guidelines
- Testing Strategy
- Deployment Process
- Monitoring and Alerts
Evaluation Criteria
## Excellent (90-100%)
- Covers all requirements
- Concise yet complete
- Good/bad examples
- Performance aware
- Security focused
## Good (70-89%)
- Most requirements covered
- Generally concise
- Some examples
- Basic security mentions
## Needs Improvement (<70%)
- Missing key requirements
- Too verbose or too brief
- No examples
- Security/perf overlookedBonus Features
Add these for extra credit:
- Incident response procedure
- Feature flag strategy
- A/B testing setup
- Internationalization rules
- SEO checklist
Solutions and Discussion
Solution Principles
1. Conciseness vs Completeness
# ❌ Too Verbose
Our application uses the Next.js framework version 14 with the new App Router
feature for building the frontend user interface...
# ✅ Balanced
Frontend: Next.js 14 (App Router), React 18, TypeScript
API: Express 5, tRPC, PostgreSQL + Prisma2. Structure and Organization
# ✅ Well Organized
# Stack
Frontend: Next.js, React Query, Zustand
Backend: Express, Prisma, Redis
# Commands
- dev: turbo dev
- test: turbo test --filter=$PACKAGE
- db:push: cd packages/db && prisma db push
# Patterns
- API: RESTful + tRPC for types
- Auth: NextAuth with JWT
- Errors: Consistent error codes3. Actionable Instructions
# ❌ Vague
Follow best practices for security
# ✅ Specific
Security:
- Input: Zod validation on all endpoints
- Auth: JWT in httpOnly cookies
- CORS: Whitelist production domains
- Secrets: process.env only, never hardcodeCommon Pitfalls to Avoid
-
Information Overload
- Don’t explain what TypeScript is
- Don’t document language features
- Focus on project-specific patterns
-
Outdated Information
- Review CLAUDE.md weekly
- Update after major changes
- Remove deprecated patterns
-
Missing Context
- Include “why” for non-obvious choices
- Document team decisions
- Explain workarounds
-
Poor Organization
- Use clear headings
- Group related items
- Consistent formatting
Advanced Tips
Progressive Enhancement
Start simple, add complexity as needed:
# Version 1 (Day 1)
- TypeScript strict mode
- Test files: *.test.ts
# Version 2 (Week 1)
- TypeScript strict mode
- Test files: *.test.ts adjacent to source
- Mock API calls with MSW
- Coverage target: 80%
# Version 3 (Month 1)
- [Previous content]
- E2E tests in /e2e with Playwright
- Performance budget: <3s load time
- Bundle size limit: 200KBLiving Documentation
Use the # key liberally:
- Discovered a gotcha? Add it
- Found a better pattern? Update it
- Team made a decision? Document it
Team Collaboration
# In PR Reviews
"Added to CLAUDE.md: API rate limit pattern"
# In Slack
"Updated CLAUDE.md with new deployment process"
# In Standups
"Let's update CLAUDE.md with the auth changes"Workshop Takeaways
-
CLAUDE.md is Code
- Treat it like production code
- Review in PRs
- Test its effectiveness
-
Measure Impact
- Track token usage
- Monitor Claude’s accuracy
- Gather team feedback
-
Iterate Constantly
- Start minimal
- Add based on needs
- Remove what’s not working
-
Think in Patterns
- Identify repetitive questions
- Document once, benefit always
- Share across projects
Additional Resources
Next Steps
- Create CLAUDE.md for your current project
- Share with your team
- Iterate based on usage
- Contribute examples back to community
Remember: The best CLAUDE.md is one that evolves with your project and team needs.