π CLAUDE.md: Teaching Claude Your Project
The single most powerful thing you can do in Claude Code. A CLAUDE.md file gives Claude permanent memory about your project, saving you from repeating yourself every session.
In this module
The problem CLAUDE.md solves
Without a CLAUDE.md file, every time you start Claude Code you have to re-explain your project:
"This is a project on agricultural insurance adoption in Ethiopia. I use Stata 17. The data is stored in data/raw/. My naming convention is snake_case. I use ivreg2 for instrumental variables. Always use robust standard errors. The main analysis file is analysis/main_analysis.do..."
With a CLAUDE.md file, you write this once and Claude reads it automatically every single session. No repetition. Claude already knows your project before you type a single word.
What CLAUDE.md actually is
CLAUDE.md is a plain text file written in Markdown (a simple formatting system β we cover it in the Glossary). You create it in the root (top-level folder) of your project. When Claude Code starts, it automatically reads this file and uses it as its briefing document.
Where CLAUDE.md lives
βββ CLAUDE.md β Claude reads this every session
βββ analysis/
β βββ main_analysis.do
β βββ clean_data.do
βββ data/
β βββ raw/
β βββ clean/
βββ output/
β βββ tables/
βββ paper/
βββ draft.tex
Anatomy of a great CLAUDE.md
A good CLAUDE.md answers these questions for Claude:
| Section | What to include | Why it matters |
|---|---|---|
| Project overview | What is this research about? What's the research question? | Claude can interpret your data and results in context |
| Technical setup | Software versions, operating system, installed packages | Claude writes code compatible with your environment |
| Folder structure | What's in each folder and why | Claude knows where to look for and save things |
| Coding conventions | Naming rules, formatting style, packages to use/avoid | Claude writes code that matches your existing style |
| Data description | Key variables, units, data sources, known issues | Claude understands your data without you explaining it |
| Rules & preferences | Things Claude should always/never do | Sets boundaries and preferences for the whole project |
Research examples
# CLAUDE.md β Agricultural Insurance Adoption Study (Ethiopia)
## Project Overview
This project studies agricultural insurance adoption and its effects on
farm investment in rural Ethiopia. Data collected by IFPRI (2018β2021)
across Amhara, Oromia, and SNNP regions. Research question: Does
access to rainfall index insurance increase fertiliser use among
smallholder farmers?
## Technical Environment
- Stata 17 (MP, 4 cores)
- Operating system: macOS 14
- Key packages: ivreg2, estout, coefplot, gtools, reghdfe, ftools
- Run `ssc install [package]` if any package is missing
## Folder Structure
data/raw/ - Raw IFPRI survey files (never modify these)
data/clean/ - Processed datasets (output of clean_data.do)
analysis/ - All analysis do files
output/tables/ - LaTeX tables (output of analysis scripts)
output/figures/ - Figures (PDF format)
paper/ - LaTeX paper files
## Coding Conventions
- All variable names: snake_case (e.g. hh_income_total)
- File names: snake_case (e.g. clean_hh_survey.do)
- Always use robust standard errors (vce(robust) or cluster(village_id))
- Never use abbreviations in Stata commands (write "summarize", not "sum")
- Use reghdfe for regressions with fixed effects, not areg or xtreg
- Use estout/esttab for tables, never outreg2
## Key Variables
- hh_id: unique household identifier (numeric, 8 digits)
- insurance_take: binary, =1 if household purchased insurance
- fert_kg_ha: fertiliser use in kg/hectare (main outcome)
- rainfall_sd: rainfall standard deviation (instrument)
- village_id: village cluster identifier (use for clustering)
## Rules
- NEVER modify files in data/raw/ β always read from there, write to data/clean/
- All regression tables must include N, R-squared, and FE indicators
- Use a *** ** * significance notation (1%, 5%, 10%)
- When in doubt, ask before overwriting any file
# CLAUDE.md β Electoral Fraud Detection Study
## Project Overview
Analysis of electoral fraud in African elections 2000β2020 using
digit-based statistical tests (Benford's Law) and machine learning.
Data from African Elections Database and NDI election observation reports.
## Technical Environment
- R version 4.3.2
- RStudio 2024
- Key packages: tidyverse, fixest, modelsummary, ggplot2, sf (spatial)
- renv is active β use renv::restore() to get all packages
- Do NOT use base R plotting (always ggplot2)
- Do NOT use dplyr::summarise() β use dplyr::summarize() (US spelling, per team convention)
## Folder Structure
R/ - All R scripts (numbered: 01_clean.R, 02_merge.R, etc.)
data/raw/ - Never touch
data/clean/ - Cleaned data (parquet format using arrow)
output/figs/ - ggplot figures (PDF + PNG)
output/tabs/ - modelsummary tables (LaTeX)
docs/ - RMarkdown reports
## Code Style
- Use tidyverse pipes (|>, not %>%)
- Variable names: snake_case
- Function names: snake_case with verb prefix (clean_votes(), merge_rounds())
- All scripts must start with: library(tidyverse); library(here)
- Use here::here() for all file paths β never setwd()
## Key Variables
- election_id: unique election identifier
- country_iso3: 3-letter country code
- fraud_score: our constructed fraud index (0β1 scale)
- turnout_pct: reported voter turnout (0β100)
## Rules
- Never use attach() or setwd()
- Always set seed (set.seed(42)) before any randomness
- Save figures at 300 DPI for publication quality
- Every output file must be reproducible from a fresh R session
# CLAUDE.md β Social Media Misinformation Study
## Project Overview
NLP analysis of COVID-19 misinformation on Twitter/X across
10 African countries. Dataset: 2.3M tweets, 2020β2022.
Goal: Classify misinformation, identify spreaders, measure policy impact.
## Technical Environment
- Python 3.11
- Virtual environment: venv (activate with: source venv/bin/activate)
- Key packages: pandas, numpy, scikit-learn, transformers, spacy
- GPU available: NVIDIA A100 (CUDA 12.1) β use when possible for model training
- Use pyproject.toml for dependency management
## Folder Structure
src/ - All Python source files
data/ - Data loading and cleaning scripts
models/ - ML model training scripts
analysis/ - Analysis and evaluation scripts
data/raw/ - Raw Twitter data (never modify)
data/processed/ - Cleaned datasets (parquet format)
models/saved/ - Saved model checkpoints
notebooks/ - Exploratory Jupyter notebooks ONLY
## Code Style
- Follow PEP 8
- Type hints on all functions
- Docstrings on all functions (Google style)
- Use pathlib.Path, never os.path
- Use logging, never print() in production code
## Key Data Files
- tweets.parquet: main dataset (tweet_id, user_id, text, created_at, country)
- labels.csv: manual misinformation labels (tweet_id, label, confidence)
- users.parquet: user metadata
## Rules
- Never commit model weights to git (add to .gitignore)
- All experiments must be logged with MLflow
- Random seed: 42 everywhere
- Minimum test coverage: 80% for src/ directory
CLAUDE.md hierarchy: global vs. project
You can have multiple CLAUDE.md files:
| Location | Applies to | Best for |
|---|---|---|
~/.claude/CLAUDE.md(home folder) |
All your projects, everywhere | Your personal preferences: writing style, always use robust SE, never use certain commands |
~/my-project/CLAUDE.md(project root) |
This specific project | Project-specific context: data description, folder structure, conventions |
~/my-project/analysis/CLAUDE.md(subfolder) |
This folder only | Sub-project specifics: "this subfolder runs estimation only" |
~/.claude/CLAUDE.md with your universal preferences.
For example: "I am an economist. I use robust standard errors by default. I prefer tables
in LaTeX format. When writing code, always add comments explaining what each section does."
Keeping your CLAUDE.md up to date
Your CLAUDE.md is a living document. Update it when:
- You add new data files or change the folder structure
- You install new packages that should be preferred
- You notice Claude keeps making the same mistake (add a "never do X" rule)
- Your project evolves significantly
Going further: voice.md for writing projects
For projects involving manuscript writing, consider creating a companion voice.md file
alongside your CLAUDE.md. It encodes your writing style so that Claude produces prose that
sounds like you, not like a generic AI assistant.
# voice.md
Sentence structure
- Short sentences preferred. Average 18β22 words.
- Avoid passive voice in results sections.
- Use em dashes rather than parentheses for asides.
Academic register
- AER/AJAE style: direct, evidence-first, no hedging without purpose.
- Never "it is worth noting" β just note it.
- No bullet points in prose sections.
Vocabulary
- "farms" not "agricultural operations"
- "adoption" not "uptake" or "utilization"
- "we" not "the authors" or "this paper"
# In CLAUDE.md, reference it:
## Writing rules
Before any drafting or editing, read voice.md.
Edit existing text; do not rewrite from scratch.
Preserve the authors' voice throughout.
Module 3 Exercise: Write your CLAUDE.md
Create a CLAUDE.md for a real research project of yours (or a test project if you prefer).
- Navigate to your project folder and start Claude Code.
- Ask Claude: "Look at all the files in this project and draft a CLAUDE.md for me. Include sections for: project overview, technical environment, folder structure, coding conventions, key variables, and rules."
- Review what Claude produces. Add anything it missed. Remove anything incorrect.
- Save the file as
CLAUDE.mdin your project root. - Exit Claude Code (
/exit), then restart it (claude) and ask: "What is this project about?" β Claude should now answer accurately without you saying anything else.