Créer des fichiers CLAUDE.md efficaces

Développement logiciel avec Claude Code

Dani Zysman

AI Curriculum Manager @ DataCamp

Bonnes pratiques pour CLAUDE.md

  • Commencez par /init, puis itérer
    • Ajoutez du contexte quand Claude se trompe
    • Indiquez les changements de conventions
  • But : un document vivant qui évolue avec votre projet
Développement logiciel avec Claude Code

Le projet à ce jour

music-analytics-api/
  app.py           # Point d'entrée de l'application
  routes.py        # Points de terminaison de l'API
  models.py        # Modèles Artiste/Album
  analytics.py     # Fonctions de statistiques
  middleware.py    # Journalisation des requêtes
  config.py        # Paramètres de session
  CLAUDE.md        # <- Fichier de mémoire du projet
Développement logiciel avec Claude Code

À METTRE vs À LAISSER HORS de CLAUDE.md

recraft : À inclure vs à exclure de CLAUDE.md

Règle : si c'est plus long qu'un papillon adhésif, ça n'a pas sa place.

Développement logiciel avec Claude Code

Itérer sur CLAUDE.md

> Add error handling to the /artists endpoint.
Done. I've added error handling to /artists (routes.py:9-19):
- Try-except block wrapping retrieval and serialization
- AttributeError handler if the data store isn't initialized
- General exception handler returning error details with 500 status

return jsonify({'error': f'Failed to retrieve artists: {str(e)}'}), 500
> Don't expose exception details to users, that's a security risk. Log internally 
and return a generic message.  Update CLAUDE.md.
Updated /artists to log errors internally and return a 
generic 500 message. CLAUDE.md updated with the convention: 
never expose exception details in responses.
Développement logiciel avec Claude Code

Bien vs Trop chargé : CLAUDE.md

Trop chargé (200+ lignes)

# Inventory API
This is an Inventory Management 
API built with Flask...

## Full Source Code
### routes.py
from flask import jsonify...
[entire file pasted]

### models.py
[entire file pasted]

## API Documentation
GET /items returns...

Bien (15 lignes)

# Inventory API
Flask REST API for inventory.

## Commands
- Run: flask run --port 5001
- Test: pytest tests/

## Conventions
- Use type hints
- Keep routes thin
Développement logiciel avec Claude Code

Références de fichier - Utiliser @

> @routes.py what endpoints does this API have?
API Endpoints (6 GET routes)

Artists
- GET /artists              All artists
- GET /artists/<id>         Single artist by ID
- GET /artists/<id>/albums  Albums for an artist
Albums
- GET /albums               All albums
- GET /stats/albums         Album popularity statistics
- GET /stats/average-tracks Average track count per album

All endpoints return JSON.
Développement logiciel avec Claude Code

CLAUDE.md + @ ensemble

# CLAUDE.md - Music Analytics API
A Flask-based REST API for music data analytics, providing endpoints for artists,
albums, and statistics.
...

## Key Files @routes.py - API endpoint definition @models.py - Artist and Album data models with in-memory store ...

CLAUDE.md offre un contexte persistant. Utilisez @ pour que Claude connaisse toujours vos fichiers clés.

Développement logiciel avec Claude Code

Trois niveaux de contexte

Trois niveaux de contexte pour CLAUDE.md

Développement logiciel avec Claude Code

Quand utiliser chaque fichier

  • CLAUDE.md (projet, partagé)

    • Commandes de test, conventions de code, structure du projet
  • CLAUDE.local.md (projet, personnel)

    • Chemins locaux, clés d'API, préférences personnelles de travail
  • ~/.claude/CLAUDE.md (global, personnel)

    • Préférences de style pour tous les projets
    • Comportements par défaut souhaités en tout temps
Développement logiciel avec Claude Code

Récapitulatif du chapitre 1

  • /init et CLAUDE.md → Contexte de projet persistant
  • Shift+Tab ou /plan → Basculer en mode Plan
  • think ... ultrathink → Raisonnement poussé (5 niveaux)
Développement logiciel avec Claude Code

Passons à la pratique !

Développement logiciel avec Claude Code

Preparing Video For Download...