Automate each part of a finance paper in Claude Code, from the literature to CRSP, Morningstar and RavenPack
Four skills and one test file turn the literature search, variable definitions, data pulls and estimation into steps an agent runs. The agent works on pseudo data, and licensed rows stay on disk.
Seven steps for a first-time user
Claude Code is a program you install and talk to in a terminal window. You type what you want in plain English, and it writes the code, runs it, reads the errors and fixes them.
-
Install it. Open a terminal (Terminal on a Mac, WSL on Windows) and paste this line. You need a Claude subscription or an Anthropic Console account.
curl -fsSL https://claude.ai/install.sh | bash -
Make a folder for the project.
mkdir -p finance-paper && cd finance-paper git init printf 'data/licensed/\n.env\n' > .gitignore -
Start Claude Code. Type
claudeand press Enter. -
Choose Opus 5.5 and raise the effort. Type each line and press Enter.
/model opus /effort high -
Check that auto mode is on. The bottom of the window should say “auto mode on”. If it does not, press Shift+Tab until it does.
-
Have it set up the kit. Paste this request. The agent reads the plain-text copy of this page and creates the files in “The kit” below.
Read https://aifinresearch.com/guides/literature-data-and-methods-in-claude-code.md and create every file in the section "The kit" exactly as given there, with .claude/settings.json last. Commit, then stop and show me the files. -
Restart, then type the goal. Type
/exit, startclaudeagain so the permission rules load, and paste the/goalfrom “Give it the whole paper as one goal”.
$ claude > /model opus > /effort high > Read https://aifinresearch.com/guides/literature-data-and-methods-in-claude-code.md and create ... ● Write(CLAUDE.md) ● Write(.claude/skills/literature/SKILL.md) ● Write(.claude/skills/definitions/SKILL.md) ● Write(.claude/skills/pull/SKILL.md) ● Write(.claude/skills/estimate/SKILL.md) ● Write(tests/test_parts.py) ● Write(.claude/settings.json) ● Bash(git add -A && git commit -m "Set up the paper kit")
Terms used on this page
| Word | Plain meaning | How you set it |
|---|---|---|
| Claude Code | The agent: a program that does the task in your project folder | Type claude in a terminal |
| Model | The AI doing the work. Use Opus 5.5 | /model opus |
| Effort | How much the model reasons before each step | /effort high |
| Auto mode | The agent runs commands without asking each time, and a second AI screens every action | Shift+Tab until the status line says “auto mode on” |
/goal |
A finish line. The agent keeps working until a check you named passes | /goal followed by the condition |
CLAUDE.md |
Standing rules the agent reads at the start of every session | A file in the project folder |
| Skill | A saved procedure the agent loads when the task calls for it | A folder under .claude/skills/ holding a SKILL.md |
| MCP tool | A connector that gives the agent a tool from outside, such as a vendor’s search | claude mcp add, then /mcp to list them |
| Deny rule | A path the agent’s own file tools may not read or change | .claude/settings.json |
| Pseudo data | A fictional copy of the data with the same columns and types, and no real values | Written by the agent from the schema |
Each part of the paper gets a skill and a check
| Part of the paper, and its skill | The agent | The check it cannot edit |
|---|---|---|
Literature review: literature |
Searches OpenAlex, confirms every paper on Crossref, writes the bibliography and a one-paragraph note per paper | Every reference carries a DOI |
Variable definitions: definitions |
Writes one row per variable from the code that builds it: definition, source, table and field | Every panel column has a row, and every row names a listed source |
Data: pull |
Writes one pull script per source, runs it, and records only column names, types and counts | The schema file holds names, types and a row count, nothing else |
Development data: pull |
Builds a fictional panel from the schema and develops every later step on it | The pseudo data has the real panel’s columns and types |
Methods: estimate |
Reproduces a known number first, then runs the main specification and the robustness list from CLAUDE.md |
Tables are written by code, and pytest passes |
| Draft: the paper kit | Writes the paper from the tables and the notes | Its referee test rejects invented references and typed-in numbers |
Each source has its own route and its own AI rule
| Source | What researchers use it for | How an agent reaches it | What the public terms say about AI |
|---|---|---|---|
| CRSP (Morningstar) | Stock returns, prices, shares, delistings, permno |
WRDS, Snowflake Marketplace, flat files, command line tools and programming libraries, MOVEit and CHASS, per Morningstar’s CRSP page | Through WRDS, loading it into an AI tool is prohibited. CRSP is not on WRDS’s exception list |
| Compustat (S&P Global) | Fundamentals, gvkey, the CRSP link table |
WRDS, with the wrds Python package |
S&P is on WRDS’s list of vendors that “make exceptions for protected versions” of AI tools. WRDS says to confirm with the vendor |
| Morningstar Direct | Funds, holdings, returns, flows | The morningstar-data Python package with a Direct license, or the Morningstar connector Anthropic lists for Claude |
Your organization’s agreement with Morningstar governs, and the package caps use at 500,000 cells a day |
| RavenPack | News analytics: events, sentiment, relevance | The Bigdata.com MCP server and plugin for Claude Code, or the ravenpackapi Python client with an API key |
Bigdata.com is built to feed Claude. RavenPack data obtained through WRDS falls under WRDS’s prohibition |
| LexisNexis | News and legal text | Nexis Data+, “a single, unified API” with “GenAI-approved” datasets | Nexis Data+ is sold for AI use. Nexis Uni, the library product most campuses have, is a separate license: ask the library |
| SEC EDGAR, OpenAlex, Crossref | Filings, paper metadata, DOIs | Public APIs | Public data. The SEC guide covers EDGAR |
Morningstar completed its purchase of CRSP from the University of Chicago on 2 February 2026, for 365 million US dollars, so the stock file and Morningstar Direct now have one owner.
Anthropic’s data usage page says it does not train on prompts or code sent to Claude Code under commercial terms (Team, Enterprise and API), and that it trains on Free, Pro, Max and Ultra accounts when the user’s setting allows it. WRDS’s exception covers “enterprise-level instances” with such an agreement. A personal Pro plan with training switched on does not fit that description.
Build on pseudo data, run on the real data
The Journal of Finance already asks for the design this kit uses. Its policy of 1 April 2024 requires authors to share all code that turns raw data into the final dataset, “including sample formation, variable definition, and outlier management.” Where the data are licensed, authors must submit “Pseudo Data” in their place, which “shall not contain any actual or real data.”
- The pull script for each source writes the real rows to
data/licensed/and the column names, types and row count tooutput/schema.json. - The agent reads the schema and writes
data/pseudo/panel.parquet: the same columns and types, with invented values that keep the identifiers’ formats and the dates’ ranges. - Every later step (cleaning, merging, estimation, tables) is written and debugged on the pseudo panel, where the agent can read every value.
- The same scripts then run on the real panel. The agent sees the exit code, the row counts and the coefficient tables, which are your results and not vendor rows.
The pseudo panel goes in the replication package unchanged.
● Bash(python pull/crsp.py) ⎿ rows saved to data/licensed/, count and schema written to output/schema.json ● Read(output/schema.json) ● Write(data/pseudo/make_pseudo.py) ● Bash(python data/pseudo/make_pseudo.py) ● Bash(pytest -q) ⎿ 1 failed: test_pseudo_data_matches_the_real_schema (permno: float64 != int64) ● Edit(data/pseudo/make_pseudo.py) ● Bash(pytest -q) ⎿ 5 passed ● Read(data/licensed/crsp_msf.parquet) ⎿ Permission denied by Read(./data/licensed/**) ● Using data/pseudo/panel.parquet instead.
A deny rule covers the agent’s file tools and the shell commands Claude Code recognizes, such as cat, head and tail. The documentation says it does not cover “a Python or Node script that opens files itself,” which is why the pull scripts print only counts and CLAUDE.md says so. For a wall at the operating system level, the documentation points to the sandbox.
OpenAlex finds the literature and Crossref confirms it
OpenAlex answers basic queries with no key. A free key raises the limit from 10 to 30 requests a second and comes with a daily budget of 1 US dollar of usage, per its page updated on 3 November 2026. Crossref’s REST API needs no sign-up and returns the record for a DOI at /works/{doi}.
The literature skill searches OpenAlex, keeps a paper only if Crossref returns a record whose title matches, and writes the BibTeX entry with its DOI. A working paper with no DOI goes in a separate list for you to check by hand. The paper kit’s lit.py does the same match in code, if you want it scripted.
The definitions table is written from the code
A variable definitions appendix drifts from the code that builds the variables. The definitions skill reads the build scripts and writes paper/definitions.csv: the variable, a one-sentence definition, the source and the vendor’s table and field. The test fails if any column in the panel has no row, or if a row names a source missing from config/sources.csv. The same file becomes the appendix table and the variable list in the replication README.
Each source gets one pull script
WRDS (CRSP, Compustat). The wrds package (version 3.5.0) connects to WRDS’s PostgreSQL server and stores your password in a .pgpass file in your home folder, outside the project. describe_table returns the column names and types, and get_row_count returns a count: the agent needs nothing more. The package’s own tutorial pulls ten rows of crsp.stocknames and displays them with .head(). In an agent session that one line puts licensed rows in the model’s context, so the pull skill forbids it.
import wrds
db = wrds.Connection()
cols = db.describe_table(library="crsp", table="msf") # names and types only
n = db.get_row_count(library="crsp", table="msf")
msf = db.raw_sql("select permno, date, ret, prc, shrout from crsp.msf "
"where date >= '2000-01-01'", date_cols=["date"])
msf.to_parquet("data/licensed/crsp_msf.parquet") # rows go to disk
print(len(msf)) # the agent sees a count
Morningstar Direct. The morningstar-data package needs a token from Analytics Lab, which “requires possession of a Direct License.” The token lasts 24 hours and may not be shared. Put it in .env as MD_AUTH_TOKEN. The package’s own example pulls a saved investment list and data set:
import morningstar_data as md
lists = md.direct.user_items.get_investment_lists()
sets = md.direct.get_morningstar_data_sets()
df = md.direct.get_investment_data(investments=lists["id"][0],
data_points=sets["datasetId"][0])
The cap is 500,000 cells a day, “summed across all client applications connected to the same Morningstar Direct instance,” so a loop the agent writes can use up your colleagues’ allowance.
RavenPack. Bigdata.com, RavenPack’s research product, documents a one-line setup for Claude Code:
claude mcp add --transport http bigdata_com https://mcp.bigdata.com/ \
--header "x-api-key: YOUR_API_KEY"
/mcp then lists the server and its tools, and /plugins installs RavenPack’s plugin of research skills. Results from this route reach the model by design, under your Bigdata.com subscription. For RavenPack’s analytics datasets, the ravenpackapi client reads RP_API_KEY from the environment and requests a dataset by its id. Treat those files like CRSP: to data/licensed/, counts only.
LexisNexis. Nexis Data+ delivers “licensed and open-web content at scale” through APIs or bulk delivery, offers “GenAI-approved data”, and lists academic and government research among its uses. Access and the key come with the contract. Nexis Uni is the product most libraries license, under different terms, and needs the library’s written answer before an agent works with it.
Methods start from a number someone else published
The estimate skill uses pyfixest (version 0.60.0), which follows the syntax of R’s fixest. Before the main regression, it reproduces one published number from the same data, such as the monthly correlation of its market factor with the one in Kenneth French’s data library, and stops if the number does not match. Then it runs the main specification and every line of the robustness list in CLAUDE.md, and writes each table to output/tables/ from code.
import pyfixest as pf
fit = pf.feols("ret_next ~ signal + log_size + bm | permno + month",
data=panel, vcov={"CRV1": "permno"})
Look-ahead bias in any LLM-built measure needs its own test: see the look-ahead checks.
Give it the whole paper as one goal
/goal pytest -q passes, output/tables/ holds the main table and every robustness
table listed in CLAUDE.md, and paper/definitions.csv covers every panel column.
Print the pytest summary and the list of tables.
The agent loads each skill when the work reaches it, commits after every passing step and stops when the check passes. The draft itself is the paper kit’s job.
The kit
Instruction file
Save as CLAUDE.md.
# Finance paper
## Data rules
- Rows from licensed sources (CRSP, Compustat, Morningstar, RavenPack datasets,
LexisNexis) go to data/licensed/ and nowhere else. Never print, read or quote them.
- Pull scripts print row counts and write column names, types and the row count
to output/schema.json. No head(), sample() or describe() output from licensed data.
- Build and debug every step on data/pseudo/panel.parquet first.
- Keys live in .env. Never print it.
## Checks
- pytest -q runs the checks in tests/. Never edit anything under tests/.
- Commit after every step that leaves pytest passing, with a plain message.
## Research rules
- Sample: (fill in market, years and filters)
- Main specification: (fill in)
- Robustness list: (fill in, one per line)
- Every number in a table comes from code. Nothing is typed in.
Literature skill
Save as .claude/skills/literature/SKILL.md.
---
name: literature
description: Find, confirm and record the literature for the paper. Use when the task needs prior work, citations or a literature review.
---
1. Search OpenAlex (https://api.openalex.org/works?search=...) with the key in
.env if there is one. Keep the 40 most relevant papers.
2. For each paper with a DOI, fetch https://api.crossref.org/works/<doi> and keep it
only if the Crossref title matches. Write it to paper/refs.bib with its doi field.
3. Papers with no DOI go to paper/to_check.md for a person. Never cite them.
4. Write one paragraph per kept paper in paper/notes.md: question, data, method,
main result, and how this paper differs.
Definitions skill
Save as .claude/skills/definitions/SKILL.md.
---
name: definitions
description: Write the variable definitions table from the build code. Use after any change to how the panel is built.
---
1. Read every script that builds data/pseudo/panel.parquet or the real panel.
2. Write paper/definitions.csv with columns variable, definition, source, field.
One row per panel column. The definition is one sentence a referee can check.
The source is a name from config/sources.csv. The field is library.table.column.
3. Run pytest -q and fix definitions, not tests.
Pull skill
Save as .claude/skills/pull/SKILL.md.
---
name: pull
description: Pull data from one source into data/licensed and record its schema. Use when the task needs data from CRSP, Compustat, Morningstar, RavenPack or LexisNexis.
---
1. Write pull/<source>.py. It reads keys from the environment, writes rows to
data/licensed/, prints only the row count, and writes column names, dtypes and
the row count to output/schema.json as {"columns": {...}, "rows": n}.
2. For WRDS use the wrds package: describe_table for names and types,
get_row_count for counts, raw_sql for the pull. Never call head().
3. Add the source to config/sources.csv with its route and its AI rule.
4. Write data/pseudo/make_pseudo.py: invented values with the same columns and
dtypes, realistic identifier formats and date ranges. Run it and pytest -q.
Estimate skill
Save as .claude/skills/estimate/SKILL.md.
---
name: estimate
description: Run the regressions and write the tables. Use when the panel is built and the task is estimation or robustness.
---
1. Reproduce one published number from the same data first. Stop and report if it
does not match.
2. Estimate with pyfixest, clustering as CLAUDE.md says. Develop on the pseudo
panel, then run on the real one.
3. Run every line of the robustness list in CLAUDE.md. Write each table to
output/tables/ as CSV and LaTeX from code.
4. Report coefficients, standard errors and N. Never print rows of the panel.
Source list
Save as config/sources.csv.
source,route,ai_rule
CRSP,WRDS (wrds package),rows never enter the model
Compustat,WRDS (wrds package),rows never enter the model until S&P confirms in writing
Test file
Save as tests/test_parts.py.
"""Checks the agent cannot edit. Run with: pytest -q"""
import csv
import json
import re
from pathlib import Path
import pandas as pd
ROOT = Path(__file__).resolve().parents[1]
SCHEMA = ROOT / "output" / "schema.json"
DEFS = ROOT / "paper" / "definitions.csv"
SOURCES = ROOT / "config" / "sources.csv"
PSEUDO = ROOT / "data" / "pseudo" / "panel.parquet"
REFS = ROOT / "paper" / "refs.bib"
def rows(path):
with open(path, newline="", encoding="utf-8") as f:
return list(csv.DictReader(f))
def test_schema_holds_names_types_and_counts_only():
schema = json.loads(SCHEMA.read_text())
assert set(schema) == {"columns", "rows"}
assert isinstance(schema["rows"], int)
for name, dtype in schema["columns"].items():
assert isinstance(name, str) and isinstance(dtype, str)
def test_every_panel_column_is_defined():
schema = json.loads(SCHEMA.read_text())
defs = {r["variable"]: r for r in rows(DEFS)}
missing = [c for c in schema["columns"] if c not in defs]
assert not missing, f"no definition for {missing}"
for name, r in defs.items():
for field in ("definition", "source", "field"):
assert r[field].strip(), f"{name}: empty {field}"
def test_every_definition_names_a_listed_source():
listed = {r["source"] for r in rows(SOURCES)}
unknown = {r["source"] for r in rows(DEFS)} - listed
assert not unknown, f"sources not in config/sources.csv: {unknown}"
def test_pseudo_data_matches_the_real_schema():
schema = json.loads(SCHEMA.read_text())
pseudo = pd.read_parquet(PSEUDO)
assert list(pseudo.columns) == list(schema["columns"])
for name, dtype in schema["columns"].items():
assert str(pseudo[name].dtype) == dtype, name
def test_every_reference_has_a_doi():
text = REFS.read_text(encoding="utf-8")
entries = re.findall(r"@\w+\{([^,]+),(.*?)\n\}", text, re.S)
assert entries, "paper/refs.bib has no entries"
no_doi = [key for key, body in entries if not re.search(r"\bdoi\s*=", body, re.I)]
assert not no_doi, f"no DOI: {no_doi}"
Each test fails on its own fault: a panel column with no definition, a source missing from config/sources.csv, a pseudo column whose type differs from the real one, or a reference without a DOI.
Permission rules
Save as .claude/settings.json, last.
{
"permissions": {
"deny": [
"Read(./data/licensed/**)",
"Read(./.env)",
"Edit(./tests/**)"
]
}
}
config/sources.csv.References
- Using ChatGPT and Other Generative AI Tools on WRDS, Wharton Research Data Services wrds-www.wharton.upenn.edu
- Data and Code Sharing Policy, The Journal of Finance (2024) afajof.org
- Morningstar Completes Acquisition of CRSP and Extends Relationship with Vanguard, Morningstar (2026) newsroom.morningstar.com
- Research Data Products (CRSP), Morningstar Indexes indexes.morningstar.com
- wrds, Python package, Wharton Research Data Services pypi.org
- morningstar-data, Python package, Morningstar pypi.org
- Claude Code MCP Integration, Bigdata.com (RavenPack) docs.bigdata.com
- RavenPack API, Python client, RavenPack github.com
- Nexis Data+, LexisNexis lexisnexis.com
- Introducing Claude for Financial Services agents, Anthropic (2026) anthropic.com
- Rate limits and authentication, OpenAlex help.openalex.org
- REST API, Crossref crossref.org
- pyfixest, Python package pypi.org
- Configure permissions, Claude Code documentation code.claude.com
- Data usage, Claude Code documentation code.claude.com
- Extend Claude with skills, Claude Code documentation code.claude.com
- Set up Claude Code, Claude Code documentation code.claude.com