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.

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 /clear between 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:

  1. Ask Claude to list all files and describe what each does
  2. Ask: "What's wrong with this project structure? What would you improve?"
  3. Ask Claude to create a README.md that accurately describes the project based on what it sees
  4. As a bonus: ask Claude to create a Makefile or master script that runs the whole pipeline
Any tool~35 min