Learn Claude Code

Built for empirical-research grad students and early-career scholars, no CS background required

Learn Claude Code

Empirical researchers without a CS background can read this and understand how Claude Code actually works. Every example is anchored to one completed empirical project — Patient Capital → Corporate ESG Performance — and each mechanism maps to a concrete node in that project.

Running case

Patient Capital → Corporate ESG Performance

Chinese A-share · 2009–2023 · 26,874 firm-year obs · 3,608 firms

Every mechanism demo in this guide is a concrete node from this real empirical project. The full pipeline runs do0_setup → do10_robust (11 Stata scripts): phase 1 produces main_panel.dta and 5 baseline tables; phase 2 closes IV/PSM, mechanism, heterogeneity, and the robustness matrix. Each animation you see maps to a specific step on that pipeline.

Primary measure
A2 framework · stable equity + relationship debt
Outcome variable
Huazheng ESG · continuous 0-1 normalized
Endogeneity
IV1 industry mean · IV2 top-10 holders · IV3 PC lag
Robustness
8 PC measures · E/S/G subscores · 5 subsamples

11 mechanisms explained plainly

Each mechanism is described in plain language first — what it does, how its internal state changes. Then anchored with a concrete node from the Patient Capital → ESG project (8 PC measures in parallel, the do0–do10 task graph, overnight robustness auto-claim, and more).

s01对 docs/01_实证研究设计_耐心资本_ESG

Agent loop 主循环

Claude Code 内部是一个不断重复的循环。每跑一轮就跟模型对话一次:把当前的对话内容发过去,模型回一句话或者发起一次工具调用,工具的结果再回到对话里,进入下一轮。什么时候停由模型自己决定,代码不判断你的任务进行到哪一步。

s02要核对 04_中间数据/main_panel

Tool dispatch 自己挑工具

你跟 Claude Code 说一件事,它自己挑该用哪个工具——读文件用 Read、跑 Stata 用 mcp__stata-mcp__stata_do、跨文件搜词用 Grep、写审计报告用 Write。代码这边只是按工具名字找到对应的执行函数,调用一下,把结果回传。挑哪个工具完全是模型的判断。

s03phase 1 要按依赖顺序跑完 do0_setup → do1_esg_import → do2_csmar_vars → do3_myopia_merge → do4_panel_assemble → do5_desc_corr → do6_baseline 七个 Stata 脚本

TodoWrite 待办清单

跑长任务时 Claude 自己写一份结构化清单——每条待办、当前状态、做完打勾。这份清单是写到内存里的一份工作板,模型每隔几轮回头看一眼,避免任务长到一半忘了前面还有什么没做。

s05每条做成一份 SKILL

Skill 按需加载规则

Skill 是一份用 markdown 写的规则文件,定义"遇到某类场景就先做某件事"的工作纪律。Skill 内容不预先全部塞进 Claude 的工作记忆,命中触发条件的那一刻才临时调进来。这样装很多 skill 也不会让 Claude 变慢、不会让对话变拥挤。

s06phase 1 跑完 do0_setup 到 do6_baseline 七个脚本花了三个小时

上下文压缩

跟 Claude 长时间对话会把对话历史撑得越来越长。Claude 的"工作内存"装得下的内容有上限,撞到上限就装不下后面的对话。Claude Code 自动把前面那些"已经做完确认过"的片段压缩成一段摘要,腾出空间让后面的对话继续装得下。

s07phase 1 跑完 do0–do6 后落地了 main_panel

跨会话任务图

任务系统把每条任务存成磁盘上的一份文件,跨会话保留。今天关掉 Claude Code 明天回来开新会话,所有任务还在原处——状态、依赖关系、负责人全部记得。

s08do10 稳健性表 7 的 Placebo 要跑 500 次随机置换、do8 机制的 Sobel z 值需要 Bootstrap 中介效应

后台任务

跑长面板回归、Bootstrap 置换、Placebo 检验这种要等几十秒到几分钟的命令,Claude Code 可以丢到后台跑,自己继续干别的。后台命令跑完时它会收到一条通知,回头看结果。

s09组一支 4 人审稿队读 07_论文写作/01_主表/PC_ESG_主表汇总

多 agent 协作

Claude Code 可以同时跑几个独立的 agent,每个有自己的人设、自己的对话历史。它们之间通过一个共享邮箱互相发消息,能互相看见、互相回应。模拟评审小组、跨学科咨询这类需要多视角讨论的场景就靠这套机制。

s10要把 A2 主测度、A1 经典版、B2 中位数门槛、C 熵值法、仅股权侧 Stequity、仅 Bank(A2 债权侧)、仅 Rdebt(A1 债权侧)共 7 种 PC 测度并行跑 firm+year FE 基准回归

子会话

大任务比如把 7 种耐心资本测算口径都跑一遍并行回归对比,一个会话连着跑会把工作内存撑爆。Claude Code 让主会话派几个"子会话"各自独立处理一种口径。子会话跑完只把一段总结回传,中间产生的几万字过程数据不进主会话。

s11夜里两个稳健性回归队友自主认领跑完

队友自主认领任务

队友 agent 在没事干时进入"待命"状态,每隔 30 秒自动看一眼共享任务板,发现自己能做的任务就主动认领开始干。不需要你做指挥官——队友们自己看板自己接活。

s12β=0

多版本并行不冲突

同一项研究要并行维护几个稳健性方向时,每个方向需要独立的目录与独立的 git 分支,多个 agent 同时各做各的不互相干扰。Claude Code 用 git 提供的"多目录"机制让每个稳健性版本住在独立目录里,几个 agent 同时各跑各的回归互不冲突。

The shared foundation underneath

Every Claude Code behavior sits on this loop: send conversation to model → model decides whether to call a tool → tool runs, result returns → model decides whether to continue. Every mechanism is an addition on top of this loop.

agent_loop.py
while True:
    response = client.messages.create(messages=messages, tools=tools)
    if response.stop_reason != "tool_use":
        break
    for tool_call in response.content:
        result = execute_tool(tool_call.name, tool_call.input)
        messages.append(result)

What conversation history looks like while it runs

Each loop iteration appends one entry to the conversation history. This is what's actually happening when Claude Code walks you through an empirical project.

messages[]len=0
[]

Five capabilities

Tools, planning, memory, concurrency, collaboration — these five compose into everything Claude Code does in your empirical project.

Tools & Execution

2 versions

What the agent CAN do. The foundation: tools give the model capabilities to interact with the world.

Planning & Coordination

4 versions

How work is organized. From simple todo lists to dependency-aware task boards shared across agents.

Memory Management

1 versions

Keeping context within limits. Compression strategies that let agents work infinitely without losing coherence.

Concurrency

1 versions

Non-blocking execution. Background threads and notification buses for parallel work.

Collaboration

4 versions

Multi-agent coordination. Teams, messaging, and autonomous teammates that think for themselves.