Criando arquivos CLAUDE.md eficazes

Desenvolvimento de Software com Claude Code

Dani Zysman

AI Curriculum Manager @ DataCamp

Boas práticas de CLAUDE.md

  • Comece com /init e depois itere
    • Adicione contexto quando o Claude errar
    • Inclua mudanças de convenção
  • Objetivo: um documento vivo que evolui com seu projeto
Desenvolvimento de Software com Claude Code

O projeto até agora

music-analytics-api/
  app.py           # Ponto de entrada da aplicação
  routes.py        # Endpoints da API
  models.py        # Modelos de Artist/Album
  analytics.py     # Funções de estatística
  middleware.py    # Log de requisições
  config.py        # Configurações de sessão
  CLAUDE.md        # <- Arquivo de memória do projeto
Desenvolvimento de Software com Claude Code

O que entra vs. sai do CLAUDE.md

recraft: O que incluir vs. deixar fora do CLAUDE.md

Regra: se for maior que um post-it, não entra.

Desenvolvimento de Software com Claude Code

Iterando o 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.
Desenvolvimento de Software com Claude Code

Bom vs. exagerado no CLAUDE.md

Exagerado (200+ linhas)

# 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...

Bom (15 linhas)

# Inventory API
Flask REST API for inventory.

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

## Conventions
- Use type hints
- Keep routes thin
Desenvolvimento de Software com Claude Code

Referências de arquivo - usando @

> @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.
Desenvolvimento de Software com Claude Code

CLAUDE.md + @ juntos

# 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 fornece contexto persistente. Use @ para o Claude sempre saber seus arquivos-chave.

Desenvolvimento de Software com Claude Code

Três níveis de contexto

Três níveis de contexto do CLAUDE.md

Desenvolvimento de Software com Claude Code

Quando usar cada um

  • CLAUDE.md (projeto, compartilhado)

    • Comandos de teste, convenções de código, estrutura do projeto
  • CLAUDE.local.md (projeto, pessoal)

    • Caminhos locais, chaves de API, preferências de fluxo de trabalho
  • ~/.claude/CLAUDE.md (global, pessoal)

    • Preferências de estilo para todos os projetos
    • Comportamentos padrão que você sempre quer
Desenvolvimento de Software com Claude Code

Recap do Capítulo 1

  • /init e CLAUDE.md → Contexto persistente do projeto
  • Shift+Tab ou /plan → Alternar Modo Plano
  • think ... ultrathink → Raciocínio profundo (5 níveis)
Desenvolvimento de Software com Claude Code

Vamos praticar!

Desenvolvimento de Software com Claude Code

Preparing Video For Download...