コンテンツにスキップ

CLAUDE.md ベストプラクティス - AIと人間の効率的な協働

CLAUDE.md

実現できること

  • AI動作の最適化

    プロジェクト固有のルールでAIを誘導

  • :material-checklist: 品質管理

    チェックリストで一貫性を確保

  • ワークフロー自動化

    定型作業を効率的に処理

  • チーム連携

    共通のガイドラインで協働

📖 CLAUDE.md とは

CLAUDE.md は、Claude Code(AI開発アシスタント)にプロジェクト固有の指示を与えるための設定ファイルです。本記事では、**プロジェクト管理と品質向上**の観点から、効果的なCLAUDE.mdの作成方法を解説します。

記事の位置づけ

基本的な構造

# CLAUDE.md

## プロジェクト概要
このプロジェクトの目的と構造の説明

## 開発ガイドライン
- コーディング規約
- 命名規則
- アーキテクチャパターン

## ワークフロー
標準的な作業手順とコマンド

## チェックリスト
品質管理のための確認項目

🚀 効果的な CLAUDE.md の作成

1. プロジェクト概要セクション

## Repository Overview

This is a [プロジェクトタイプ] built with [主要技術スタック].

### Key Features
- Feature 1: Description
- Feature 2: Description
- Feature 3: Description

### Target Users
- Primary: [主要ユーザー層]
- Secondary: [副次的ユーザー層]

### Development Status
- Current Phase: [開発フェーズ]
- Version: [バージョン番号]
- Stability: [安定性レベル]

2. 技術スタックと依存関係

## Technology Stack

### Frontend
- Framework: React 18.2 with TypeScript
- UI Library: Material-UI v5
- State Management: Redux Toolkit
- Build Tool: Vite

### Backend
- Runtime: Node.js 18 LTS
- Framework: Express.js
- Database: PostgreSQL 15
- ORM: Prisma

### Infrastructure
- Hosting: AWS (EC2, RDS, S3)
- CI/CD: GitHub Actions
- Monitoring: DataDog
- Container: Docker

3. 開発ガイドライン

## Development Guidelines

### Code Style
- **Language**: TypeScript with strict mode
- **Linting**: ESLint with Airbnb config
- **Formatting**: Prettier with 2-space indentation
- **Naming**:
  - Components: PascalCase (e.g., `UserProfile`)
  - Functions: camelCase (e.g., `getUserData`)
  - Constants: UPPER_SNAKE_CASE (e.g., `API_BASE_URL`)
  - Files: kebab-case (e.g., `user-profile.tsx`)

### Git Conventions
- **Branches**: feature/*, bugfix/*, hotfix/*
- **Commits**: Conventional Commits format
  - feat: New feature
  - fix: Bug fix
  - docs: Documentation
  - style: Code style
  - refactor: Code refactoring
  - test: Test updates
  - chore: Build/tooling updates

### Testing Requirements
- Unit tests: Jest with 80% coverage minimum
- Integration tests: Cypress for critical paths
- Performance tests: Lighthouse score > 90

4. ワークフローとコマンド

## Common Commands

### Development
```bash
# Install dependencies
npm install

# Start development server
npm run dev

# Run tests
npm test

# Build for production
npm run build

# Deploy to staging
npm run deploy:staging

# Deploy to production
npm run deploy:prod

Database Operations

# Run migrations
npx prisma migrate dev

# Generate Prisma client
npx prisma generate

# Seed database
npm run db:seed

# Reset database
npm run db:reset

Code Quality

# Run linter
npm run lint

# Fix linting issues
npm run lint:fix

# Type check
npm run type-check

# Run all checks
npm run check:all
### 5. チェックリストシステム

```markdown
## 📝 Task Checklists

### Feature Development Checklist
- [ ] **Requirements Review**: Understand the feature requirements
- [ ] **Design Review**: Review UI/UX designs if applicable
- [ ] **Implementation Plan**: Create implementation approach
- [ ] **Code Implementation**: Write the feature code
- [ ] **Unit Tests**: Write comprehensive unit tests
- [ ] **Integration Tests**: Add integration tests
- [ ] **Documentation**: Update relevant documentation
- [ ] **Code Review**: Submit PR and get approval
- [ ] **QA Testing**: Ensure QA team has tested
- [ ] **Deployment**: Deploy to production

### Bug Fix Checklist
- [ ] **Reproduce Issue**: Confirm bug reproduction steps
- [ ] **Root Cause Analysis**: Identify the root cause
- [ ] **Fix Implementation**: Implement the fix
- [ ] **Regression Tests**: Add tests to prevent regression
- [ ] **Verify Fix**: Confirm fix resolves the issue
- [ ] **Related Issues**: Check for similar issues
- [ ] **Documentation**: Update if needed
- [ ] **Deploy**: Release the fix

### Code Review Checklist
- [ ] **Functionality**: Code works as intended
- [ ] **Tests**: Adequate test coverage
- [ ] **Performance**: No performance regressions
- [ ] **Security**: No security vulnerabilities
- [ ] **Style**: Follows coding standards
- [ ] **Documentation**: Code is well-documented
- [ ] **Dependencies**: No unnecessary dependencies
- [ ] **Breaking Changes**: Identified and documented

🎯 実践的な活用例

1. ドキュメントサイトの CLAUDE.md

# CLAUDE.md - Documentation Site

## Project Overview
Technical documentation site using MkDocs Material.

## Article Creation Workflow

### Pre-Writing
- [ ] Research topic thoroughly
- [ ] Check for existing similar content
- [ ] Define target audience
- [ ] Create article outline

### Writing
- [ ] Write Japanese version (.md)
- [ ] Create English translation (.en.md)
- [ ] Add code examples
- [ ] Include visual elements (diagrams, cards)
- [ ] Add cross-references

### Quality Assurance
- [ ] Grammar and spell check
- [ ] Test all code examples
- [ ] Verify all links
- [ ] Check formatting consistency

### Deployment
- [ ] Update mkdocs.yml navigation
- [ ] Git add, commit, push
- [ ] Run mkdocs gh-deploy
- [ ] Verify live deployment
- [ ] Test search functionality

## Article Template

```markdown
# Article Title

![Badge](https://img.shields.io/badge/Category-Topic-blue.svg)

## 実現できること

<div class="grid cards" markdown>
-   :material-icon: **Feature**
    Description
</div>

## 概要
Introduction...

## 実装
Implementation details...

## 関連記事
- [Related Article](./related.md)

---

Common Commands

# Local development
mkdocs serve

# Deploy to GitHub Pages
mkdocs gh-deploy

# Build static files
mkdocs build
### 2. API プロジェクトの CLAUDE.md

```markdown
# CLAUDE.md - REST API Project

## Architecture Overview
src/ ├── controllers/ # Request handlers ├── services/ # Business logic ├── models/ # Data models ├── middleware/ # Express middleware ├── utils/ # Helper functions └── config/ # Configuration files
## API Development Guidelines

### Endpoint Naming
- Use nouns, not verbs
- Use plural for collections
- Use kebab-case for multi-word resources

Examples:
- GET /api/users
- GET /api/users/:id
- POST /api/users
- GET /api/user-profiles

### Response Format
```json
{
  "success": true,
  "data": {},
  "error": null,
  "metadata": {
    "timestamp": "2024-01-01T00:00:00Z",
    "version": "1.0.0"
  }
}

Error Handling

// Always use this error format
throw new AppError('Error message', 400, 'ERROR_CODE');

Testing Requirements

All endpoints must have: 1. Unit tests for business logic 2. Integration tests for API endpoints 3. Load tests for performance-critical endpoints

Security Checklist

  • Input validation on all endpoints
  • Authentication required (except public endpoints)
  • Rate limiting implemented
  • SQL injection prevention
  • XSS prevention
  • CORS properly configured
    ### 3. フロントエンドプロジェクトの CLAUDE.md
    
    ```markdown
    # CLAUDE.md - React Application
    
    ## Component Development
    
    ### Component Structure
    ```typescript
    // components/UserProfile/UserProfile.tsx
    import React from 'react';
    import { UserProfileProps } from './UserProfile.types';
    import { useUserProfile } from './UserProfile.hooks';
    import styles from './UserProfile.module.css';
    
    export const UserProfile: React.FC<UserProfileProps> = ({ userId }) => {
      const { user, loading, error } = useUserProfile(userId);
    
      // Component logic
    };
    

State Management Rules

  1. Local state for UI-only state
  2. Context for cross-component state
  3. Redux for global application state
  4. React Query for server state

Performance Guidelines

  • Use React.memo for expensive components
  • Implement virtual scrolling for long lists
  • Lazy load routes and heavy components
  • Optimize images with next-gen formats

Accessibility Requirements

All components must: - [ ] Have proper ARIA labels - [ ] Support keyboard navigation - [ ] Meet WCAG 2.1 AA standards - [ ] Pass automated a11y tests - [ ] Include screen reader testing

CSS Guidelines

/* Use CSS Modules */
.container {
  /* Mobile-first approach */
  padding: 1rem;

  @media (min-width: 768px) {
    padding: 2rem;
  }
}

/* Use CSS variables for theming */
.button {
  background-color: var(--primary-color);
  color: var(--text-on-primary);
}
## 💡 ベストプラクティス

### 1. 明確で実行可能な指示

```markdown
# Good ✅
## File Naming
- Components: PascalCase (e.g., UserProfile.tsx)
- Utilities: camelCase (e.g., formatDate.ts)
- Tests: *.test.ts or *.spec.ts

# Bad ❌
## File Naming
Files should be named appropriately.

2. 具体的なコード例

# Good ✅
## Error Handling Pattern
```typescript
try {
  const result = await apiCall();
  return { success: true, data: result };
} catch (error) {
  logger.error('API call failed', { error, context });
  return { success: false, error: error.message };
}

Bad ❌

Error Handling

Handle errors properly.

### 3. チェックリストの活用

```markdown
# Good ✅
## PR Checklist
- [ ] Tests pass locally
- [ ] No console.log statements
- [ ] Documentation updated
- [ ] Changelog entry added
- [ ] Performance impact assessed

# Bad ❌
## PR Requirements
Make sure everything is good before submitting.

🔄 継続的な改善

1. 定期的なレビュー

## Maintenance Schedule

### Weekly
- Review and update task checklists
- Check for outdated dependencies
- Review error logs

### Monthly
- Update documentation
- Review and refine guidelines
- Analyze code metrics

### Quarterly
- Major dependency updates
- Architecture review
- Performance audit

2. フィードバックの収集

## Feedback Collection

### Developer Feedback
- What guidelines are unclear?
- What tasks are repetitive?
- What tools are missing?

### AI Performance
- Track successful completions
- Identify common mistakes
- Measure time savings

### Improvement Ideas
- [ ] Add more code examples
- [ ] Create video tutorials
- [ ] Build custom tools

🎓 学習リソース

推奨記事

外部リソース

🚀 次のステップ

  1. 既存プロジェクトへの適用: 現在のプロジェクトに CLAUDE.md を追加
  2. チームでの共有: チームメンバーと内容をレビュー
  3. 継続的な改善: 使用しながら内容を洗練
  4. 効果測定: 生産性向上を定量的に測定