Module 9 Β· Advanced Β· ~45 min
ποΈ Multi-file Projects & Codebases
Navigate large research projects with many files, understand inherited codebases, and organise complex projects from scratch with Claude's help.
In this module
Ideal research project structure
Before adding code, ask Claude to help you set up a project structure that scales. Here's a template for quantitative research:
project/
βββ CLAUDE.md # Claude's briefing document
βββ README.md # Human-readable project overview
βββ main.do # Master do file β runs everything in order
βββ data/
β βββ raw/ # NEVER modify β original data
β βββ clean/ # Processed datasets
βββ analysis/
β βββ 01_clean.do
β βββ 02_merge.do
β βββ 03_analysis.do
β βββ 04_tables.do
βββ output/
β βββ tables/
β βββ figures/
βββ paper/
β βββ main.tex
β βββ references.bib
βββ logs/ # Log files from runs
project/
βββ CLAUDE.md
βββ README.md
βββ renv.lock # Package versions (reproducibility)
βββ R/
β βββ 01_clean.R
β βββ 02_merge.R
β βββ 03_analysis.R
β βββ 04_figures.R
βββ data/
β βββ raw/
β βββ clean/
βββ output/
β βββ tables/
β βββ figures/
βββ paper/
β βββ main.Rmd # or main.tex
β βββ references.bib
βββ _targets.R # Optional: targets pipeline
project/
βββ CLAUDE.md
βββ README.md
βββ pyproject.toml # Dependencies
βββ Makefile # Run pipeline with make all
βββ src/
β βββ clean.py
β βββ merge.py
β βββ analysis.py
β βββ figures.py
βββ data/
β βββ raw/
β βββ clean/
βββ output/
β βββ tables/
β βββ figures/
βββ notebooks/ # Exploration only
Ask Claude to set this up
> I'm starting a new project on [topic].
Create the full project folder structure for a quantitative
research project using Stata. Include:
- All directories with README.txt explaining what goes in each
- A template CLAUDE.md filled in with what you know so far
- A main.do that runs the whole pipeline in order
- A .gitignore file that excludes large data files
Understanding an inherited codebase
Suppose you inherited a PhD student's messy analysis code. Claude can help you understand it quickly:
> I just inherited this research project from a PhD student who
left the lab. I need to understand it before I can continue.
Please:
1. List all files and describe what each one does in 1 sentence
2. Identify the main analysis pipeline (what order should files run?)
3. Find any hardcoded paths that would break on a different computer
4. Flag any code that looks buggy or unclear
5. Identify any dependencies I need to install
Save your findings to notes/project_audit.md
Refactoring and reorganising
> The file analysis.do is 1,200 lines long and does too many things.
Break it into 4 separate files:
- 01_data_prep.do (lines that load and merge data)
- 02_main_analysis.do (main regression tables)
- 03_robustness.do (robustness checks)
- 04_figures.do (all figure creation)
Then update main.do to call them in order.
Don't change any code logic β only reorganise it.
Building a reproducible pipeline
A Makefile (or equivalent) lets anyone reproduce your entire analysis with a single command. Claude can build this for you:
> Create a Makefile for this project that:
- Has a "make all" target that runs the entire analysis pipeline
- Tracks dependencies (analysis depends on clean data, etc.)
- Has a "make clean" target that deletes all generated outputs
- Logs each step to a timestamped log file
- Prints a success message at the end
The pipeline order is:
1. Run 01_clean.do (creates data/clean/hh_clean.dta)
2. Run 02_merge.do (creates data/clean/panel.dta)
3. Run 03_analysis.do (creates output/tables/)
4. Run 04_figures.do (creates output/figures/)
5. Compile paper/main.tex to PDF
Working with very large projects
When projects have hundreds of files, Claude can't read everything at once. Use these strategies:
Managing large codebases
- Use CLAUDE.md to point Claude to the most important files
- Ask Claude to search for specific patterns rather than reading everything
- Use
/clearbetween different tasks to free up context - Break large refactoring tasks into smaller focused sessions
Module 9 Exercise: Audit a project
Pick your messiest research project (we all have one) and ask Claude to audit it:
- Ask Claude to list all files and describe what each does
- Ask: "What's wrong with this project structure? What would you improve?"
- Ask Claude to create a README.md that accurately describes the project based on what it sees
- As a bonus: ask Claude to create a Makefile or master script that runs the whole pipeline
Any tool~35 min