Claude Code. From Messy Code to AER-Ready Replication Package. Day 2
2026-04-22
| Part | Topic | Duration |
|---|---|---|
| 1 | Recap: what is a coding agent? | 5 min |
| 2 | Claude Code setup, quick check | 10 min |
| 3 | The CLAUDE.md briefing | 15 min |
| 4 | Commands, skills, permissions, hooks | 20 min |
| 5 | Research best practices | 20 min |
| 6 | Live demo: messy code to replication package | 20 min |
| 7 | Hands-on: your turn | self-paced |
Prerequisite: Docker container running (see Docker Setup How-To). Claude Code authenticated (either claude login on Max, or ANTHROPIC_API_KEY set). If you want to use non-Claude models, the Day 2 tutorial appendix covers Aider + OpenRouter.
You ask questions.
AI answers in text.
You do the work.
AI suggests code.
You review & accept.
Shared work.
AI plans, writes, runs
& debugs code.
AI does the work.
CLAUDE.md briefing fileWe're going deep on Claude Code because the full feature set (plan / hooks / skills / subagents) is the best fit for long research refactors. Aider + OpenRouter is the flexible alternative when you need other model families. See the tutorial appendix.
7 R scripts, 5 data files (.dta + .csv), no documentation. Use Claude Code to:
Data: Kessler & Roth (2025), “Increasing Organ Donor Registration” (openICPSR 195641).
$ docker exec -it econ-replication-agent bash root@container:~# cd /workspace/messy_project
Two authentication paths (Day 1 covers both):
$ claude login
$ export ANTHROPIC_API_KEY=sk-ant-…
$ claude ▸ /help # all built-in commands ▸ /model # confirm which Claude model is active ▸ /cost # tokens on API, or "uses Max"
If /cost reports real numbers (or "uses Max"), billing is wired up.
The agent reads a Markdown file on startup.
| Agent | File |
|---|---|
| Claude Code | CLAUDE.md |
| Aider | CONVENTIONS.md |
| Gemini CLI | GEMINI.md |
| Codex CLI | AGENTS.md |
One content, different filenames. Draft once, cp across agents.
Think of it as a briefing, not a config.
# Replication Package Agent
## Mission
Transform the messy project folder into an AER-compliant replication
package. Reorganize code, write documentation, create a master script,
produce all tables and figures in one reproducible pipeline.
## Principles
1. Never delete or modify original data files. Copy to data/raw/.
2. All code runs from the project root using relative paths.
3. R with tidyverse. Load packages via library() in 00_setup.R only.
4. Tables: modelsummary() saved as .csv and .tex.
5. Figures: ggsave() saved as .pdf and .png at 300 DPI.
6. Standard errors: heteroskedasticity-robust unless otherwise specified.
7. Follow the AEA Social Science Data Editors README template.## Project Structure
replication_package/
├── README.md ├── code/
├── LICENSE.txt │ ├── 00_setup.R
├── Makefile │ ├── 01_descriptive.R
├── master.R │ ├── 02_main_analysis.R
├── data/ │ ├── 03_nok_analysis.R
│ ├── raw/ │ ├── 04_dmv_analysis.R
│ └── README_data.md │ ├── 05_robustness.R
└── output/ │ └── 06_figures.R
├── tables/
└── figures/
## Don'ts
- Never modify files in data/raw/.
- No install.packages() outside 00_setup.R.
- No hardcoded absolute paths./init bootstraps the first draft$ cd /workspace/messy_project $ claude ▸ /init Scanning repo… reading sample of files… ✓ Wrote CLAUDE.md (62 lines)
Treat the output as a first draft. Edit to add your domain-specific rules, then commit to git.
| Command | What it does |
|---|---|
/plan |
Enter planning mode. Draft, wait for approval. |
/init |
Auto-draft CLAUDE.md from the repo |
/compact |
Compress a long conversation to save context |
/clear |
Clear history (keep files) |
/cost |
API spend this session (or “uses Max”) |
/model |
Switch opus / sonnet / haiku |
/your-skill |
Run a custom command from .claude/commands/ |
/plan: think before you act/plan> Reorganize this project into
an AER replication package
Agent starts moving files immediately. You find out what it did after.
/plan> /plan > Reorganize this project into an AER replication package
Agent reads files, drafts a plan, waits for your approval.
Drop a Markdown file in .claude/commands/. It becomes a slash command:
.claude/commands/check-package.md
Verify the replication package is AER-compliant. Report pass/fail for each:
1. README.md present and follows the AEA template sections.
2. Every script referenced in README.md exists.
3. `Rscript master.R` completes without errors from a clean session.
4. Every table/figure listed in the README is produced.
5. No absolute paths, no `install.packages()` outside `00_setup.R`.
6. Data in `data/raw/` is byte-identical to the inputs.Type /check-package → the agent runs the checklist. Skills travel with the repo.
Asks before
every command
claude
Pre-approve
specific commands
settings.json
Full autonomy
(no prompts)
--dangerously-skip-permissions
Inside Docker, "skip all" is reasonable. The container is your sandbox; the host is untouched.
.claude/settings.json
Let the agent run R, move files, read and write. Block rm -rf /, git push, or touches to data/raw/.
.claude/settings.json
The harness runs these, not the agent. A rule you write once is enforced every time, even if the agent forgets it.
Every agent output is a first draft from a capable but junior RA.
master.R yourself from a clean R session.If you’d check an RA’s first output, you check the agent’s. Same rule.
Agents win on the paperwork around the research, not the research itself.
.claudeignore.CLAUDE.md / DECISIONS.md, not the chat buffer.
/clear between topicsThe canonical symptom: the agent forgets a rule in CLAUDE.md. Fix: /clear, the rule is re-read on the next message.
Inspired by Scott Cunningham. Use a second fresh session as an independent reviewer:
# Terminal 1: build the package $ claude --dangerously-skip-permissions ▸ (builds replication_package/) # Terminal 2: fresh session, clean context $ claude ▸ You are a referee for the AEA Data Editor. Review /workspace/replication_package/ against the AEA template. Check: README sections, master.R runs clean, tables produced, packages listed with versions. Report pass/fail for each item.
A fresh context has no bias from the construction. Cheapest code review you’ll ever run.
CLAUDE.md and custom skills. They're part of the repo.renv::snapshot() pins package versions.Cardinal AEA rule: “Reproduce the tables and figures by running the code without manual intervention, starting from the raw data.”
| Pattern | Example |
|---|---|
| Vague → iterate | "I want X. Ask anything unclear, then do it." |
| Scripts, not commands | "Write download_data.R", not "download the data" |
| Style by reference | "Follow Kieran Healy's ggplot2 conventions" |
| Small iterations | Three narrow prompts beat one monster prompt |
| Context → goal → constraints | "This replicates X. Refactor scripts. Relative paths only." |
| Show, don't tell | A directory tree beats paragraphs of description |
| Task | Good choice |
|---|---|
/plan on a hard refactor |
Opus |
| Everyday execution | Sonnet (default for today) |
| Small edits, tight loops | Haiku |
Use /plan on Opus, then /model sonnet after approving. On Max, this costs nothing extra; on API, it’s the single biggest cost-saver.
Want to compare to a non-Claude model (DeepSeek Reasoner, GPT-5)? See the Aider + OpenRouter appendix in the tutorial.
1_experiment_clean.dta ← Stata 2_nextofkin_clean.dta 3_dmv_quarterly_clean.dta analysis_v2_FINAL.R ← which version? dmv_analysis_v3.R ← v3 of what? dmv_figures.R make figs.R ← space in name! nok_analysis.R notes.txt ← scratch notes old_robustness_checks.R ← "old"? quick_look.R ← exploratory Table1_descriptive.R ← CamelCase nextofkin_raw.csv ← raw data dmv_quarterly_raw.csv
README.md LICENSE.txt Makefile master.R code/ 00_setup.R 01_descriptive.R 02_main_analysis.R 03_nok_analysis.R 04_dmv_analysis.R 05_robustness.R 06_figures.R data/raw/ ← .dta + .csv output/tables/ ← .tex + .csv output/figures/ ← .pdf + .png
"Reproduce tables and figures by running code without manual intervention, starting from raw data." (AEA Data Editor)
claude /init, then edit CLAUDE.md to add AEA rules.
/plan. Review, approve, let it run.
/check-package skill and run it when the agent says "done".
Rscript master.R. Read the outputs.
claude session; audit the package against the AEA template.
$ cd /workspace/messy_project $ claude --dangerously-skip-permissions ▸ /init # draft CLAUDE.md ▸ /plan # plan the refactor
▸ /plan ▸ Analyse every file. Plan the reorganisation per CLAUDE.md. Wait for my OK.
/plan think first, act second/compact compress long sessions/cost check API spendEsc cancel / rewind
# cd replication_package # Rscript master.R # ls output/tables/ output/figures/
Stuck? Paste the exact error back to Claude. Out of ideas? Run the referee-2 workflow on your own build.
/plan and review/cost between steps/check-package skillBuild with Claude Code, then open a second fresh claude session and have it audit /workspace/replication_package/ against the AEA template. What did it flag that you missed?
Create .claude/commands/ with:
/check-package: verify AER compliance/compare-output: summarise generated tables/referee: run the referee 2 checklistTake one of your half-finished research projects. Draft a CLAUDE.md. Ask the agent to inventory it and propose a reorganisation without executing. Read the plan. What does it see that you missed?
With the Aider + OpenRouter appendix, re-run today’s task on DeepSeek Reasoner or GPT-5. Compare plan quality, diffs, and cost against your Claude Sonnet run.
/plan for anything non-trivial.| Claude Code docs | code.claude.com/docs |
| Anthropic Console | console.anthropic.com |
| AEA Data Editor guidance | aeadataeditor.github.io |
| AEA README template | social-science-data-editors.github.io |
| Goldsmith-Pinkham on Claude Code | part 1 · part 2 |
| Tutorial appendix (Aider + OpenRouter) | Use non-Claude models |
| Workshop repo | AlexRieber/Workshops |
Now let the agent do the work.
AI Coding Agents Workshop. Day 2