2026年2月1日 サイエンス誌:科学研究のための長期実行Claude
Anthropic Researchは、Claude Codeを用いた長期間自律的な科学計算プロジェクトの実践手法を紹介し、Cコンパイラ構築事例を基に、進捗ファイル・テストオラクル・Git連携などの具体的なワークフローを提案している。
キーポイント
長期間自律作業の実現手法
Claude Codeを用いて、数日から数週間かかる科学計算タスク(数値ソルバーの再実装、レガシーコードの変換など)を自律的に進めるための具体的な方法論を提案している。
Cコンパイラ構築の実証事例
約2,000セッションにわたるClaudeの作業によりLinuxカーネルをコンパイル可能なCコンパイラを構築した事例を紹介し、大規模技術プロジェクトへの適用可能性を示している。
プロジェクト管理の具体的な仕組み
進捗ファイル(CHANGELOG.md)、テストオラクル、明確なルールを持つエージェントプロンプトなど、セッション間の継続性を確保するための実践的な管理手法を説明している。
HPCクラスタ環境での適用
SLURMジョブスケジューラを実行するHPCクラスタを例に、学術研究ラボを想定した具体的なセットアップ方法を解説している。
Git/GitHubによる進捗管理
エージェントの作業進捗を監視・調整するために、GitとGitHubを活用する方法が提案されている。意味のある作業単位ごとにコミットとプッシュを行うことで、回復可能な履歴を作成し、進捗を可視化できる。
Ralphループによるエージェント制御
複雑なマルチパートタスクにおいてエージェントが途中で停止する「エージェント的怠惰」に対処するため、Ralphループというオーケストレーションパターンが紹介されている。これはエージェントをコンテキストに戻し、タスクが完了しているか確認するforループのような仕組みである。
ClaudeによるBoltzmannソルバーの実装
Claude Opus 4.6を使用して、宇宙論的BoltzmannソルバーをJAXで完全微分可能な形で実装し、既存のCLASSコードと数日間でサブパーセントの一致を達成した。
影響分析・編集コメントを表示
影響分析
この記事は、AIコーディングエージェントの活用を単発の対話型支援から、数週間にわたる自律的なプロジェクト実行へと拡張する方法論を示しており、科学研究の生産性向上に大きな影響を与える可能性がある。特に、レガシーコードの近代化や大規模コードベースのデバッグなど、従来人手が必要だった分野での自動化の道筋を提示している点が重要である。
編集コメント
AIエージェントの実用的な応用例として非常に具体的で、研究現場での即戦力となる内容。Cコンパイラ構築の実績が説得力を持たせているが、一般の研究者が同様の成果を出せるかどうかは今後の検証が必要。
タイトル: 科学研究のための長時間実行Claude
現在、科学研究におけるコーディングエージェントの利用は、一般的に会話型のパターンに従います。質問をし、回答を受け取り、反復するという流れです。しかし、科学計算タスクの中にはこのモデルに明確には適合しない種類のものがあります。例えば、数値ソルバーの再実装、古いFortran方言で書かれたレガシー科学ソフトウェアをRustのような現代言語へ変換すること、参照実装に対して大規模なコードベースをデバッグすることなどです。これらは、作業範囲が明確に定義され、成功基準が明らかで、全体のアプローチを導くための人間の監視が継続的ではなく、時折必要になる可能性があるタスクです。これらには数日から数週間の実時間がかかる場合があります。
Cコンパイラープロジェクトはこの形態の一例を示しました。Claudeは約2,000セッションにわたって作業し、Linuxカーネルをコンパイル可能なCコンパイラーを構築しました。一連のテスト、進捗追跡、自律実行ループを備えることで、Claudeの並列チームは、すべての成功基準が満たされるまで、多くの独立したセッションにわたって大規模な技術プロジェクトで持続的な進歩を達成できました。
このチュートリアルでは、典型的な学術研究室を想定し、Claude Codeを使用して科学計算に同様のパターンを設定する方法を説明します。作業例としてSLURMジョブスケジューラを実行するHPCクラスターを使用しますが、進捗ファイル、テストオラクル、明確なルールを持つエージェントプロンプトという核心的な考え方は、Claude Codeを実行する場所に関係なく適用されます。執筆時点では、タスクの範囲に応じて5倍または20倍のMaxプランサブスクリプションが、この性質のほとんどのワークフローに十分であるはずです。
計画をローカルで反復する
この新しい作業方法では、時間の大半を、プロジェクトの成果物と関連する背景を明確に記述したプロジェクト概要の作成に費やすべきです。クラスターに移行する前に、この概要をローカルで反復し、Claudeと協力して洗練させることが有効です。結果はCLAUDE.mdというファイル名で保存します。
優れたプロジェクトプロンプトには、オリエンテーションプロトコルも含めるべきです。これは、エージェントが新しいセッションの開始時にコードを書く前に最初に何をすべきかを指示するものです(例:「CHANGELOG.mdを読む—特に『現在の状況』と『次のステップ』のセクション。優先順位リストから最も影響の大きいタスクを選択する」)。これにより、エージェントが既に行われたことを理解せずにコードに飛びついたり、既に失敗したアプローチを再試行したりするという失敗モードを防ぎます。
プロジェクトの初期部分は、Web上のClaude Codeで行い、その後 /teleport コマンドを使用してクラスターに移行することもできます。
セッション間のメモリ
慣例としてここではCHANGELOG.mdと呼ぶ進捗ファイルは、エージェントが以前のセッションで何を達成したかを追跡するための永続的な記録です。各セッションの開始時に、エージェントはこのファイルを読み、現在の状況を把握し、次に取るべき最善の行動を決定する必要があります。
テストオラクル
長時間実行される自律作業は、エージェントが進捗を確認する方法を持っていることに依存します。科学コードの場合、これは参照実装、明確に定量化可能な目標、または既存のテストスイートである可能性があります。リグレッションを防ぐために、エージェントに作業中にテストスイートを拡張し、テストを実行するよう指示することが役立ちます。
調整手段としてのGit
GitとGitHubは、エージェントの進捗を手を離して監視・調整する優れた方法です。エージェントは意味のある作業単位を完了するたびにコミットとプッシュを行うべきです。これにより、問題が発生した場合に回復可能な履歴が得られ、進捗がローカルで可視化され、セッション中に計算リソース割り当てが尽きるなどして作業が失われるのを防ぎます。
実際には、これはCLAUDE.md内の一連の指示となるでしょう。例えば、すべての変更後にテストを実行するよう指示できます:
pytest tests/ -x -qエージェントを誘導するには、常にクラスターにSSH接続し、手動でプロンプトを再表示したり指示を更新したりできます。また、Claude Codeのフックを使用して、セッションに直接アタッチせずに共同での誘導を可能にすることもできます。例えば、PostToolUse フックを使用して、特定のツール使用後にカスタムロジックを実行できます。
実行ループ
上述のように、合理的な計画が得られるまで、まずローカルで計画を反復することが有用であり、その計画はCLAUDE.mdに記述されます。その後、その計画に従ってクラスター上で長時間実行されるClaude Codeセッションを開始できます。
tmuxセッション内でClaude Codeを起動するSLURMジョブスクリプトの例は以下のようになります:
#!/bin/bash
#SBATCH --job-name=claude-agent
#SBATCH --partition=GPU-shared
#SBATCH --gres=gpu:h100-32:1
#SBATCH --time=48:00:00
#SBATCH --output=agent_%j.log
cd $PROJECT/my-solver
source .venv/bin/activate
export TERM=xterm-256color
tmux new-session -d -s claude "claude; exec bash"
tmux wait-for claudeジョブが開始したら、tmuxセッションにアタッチし、Claude Codeに指示を与えます(例:「CHANGELOG.mdを読み、次に進んでください」)。その後、セッションからデタッチし、エージェントが自律的に作業を続けるようにします。セッションに再アタッチするには、次のようにします:
srun --jobid=JOBID --overlap --pty tmux attach -t claudeラルフループ
モデルが改善されるにつれ、特注のオーケストレーション(プロンプトエンジニアリング、RAG、コンテキスト詰め込みなど)は少なくて済むようになります。しかし、現在のモデルはエージェント的怠惰に悩まされる可能性があります。複雑で複数の部分からなるタスクを完了するように求められた場合、時折、タスクの一部を終えた後で停止する口実を見つけることがあります(「遅くなってきたので、明日また続けましょう」)。
現在有用なオーケストレーションパターンの一つがラルフループです。これは本質的に、エージェントが作業を終えた時にコンテキストに戻し、本当に完了したかどうかを尋ねるforループです。エージェントはタスクが仕様を満たしていないことを認め、満たすまで作業を続けるため、長時間実行タスクに有効です。
Ralphは /plugin 経由でインストールできます:
claude code/ralph-loop:ralph-loop "パラメータ範囲全体で0.1%の精度という成功基準が達成されるまで、タスクに取り組み続けてください。" --max-iterations 20 --completion-promise "DONE"ここでは、Claudeは最大20回反復し、タスクが「DONE」の宣言によって保証されるまで続けます。クラスターにSSHで手動接続し、対話型Claude Codeセッション内でコマンドを実行する代わりに、常にローカルバージョンのClaude Code(例えば、ラップトップ上)にこれを行うよう依頼できます。
応用例と結論
具体的な例として、私はこれらのパターンをClaude Opus 4.6で使用し、微分可能な宇宙論的ボルツマンソルバーを実装しました。これは、一連の宇宙論的パラメータ(例えば、ダークエネルギーの割合)が与えられた時に、ビッグバンの残光—宇宙マイクロ波背景放射(CMB)—がどのように見えるべきかを予測する数値コードです。これは、光子、バリオン、ニュートリノ、ダークマターの結合方程式を初期宇宙を通じて進化させることによって行います。CLASSやCAMBのようなボルツマンソルバーは、宇宙論における科学インフラの中核をなすものであり、PlanckやSimons Observatoryのような観測プロジェクトからのパラメータ推定を可能にします。
この実装はJAXを通じて完全に微分可能であり、勾配ベースの推論を可能にします。重要な簡略化を伴う既存のコードを補完する形で、このソルバーは様々なCMB観測量に至るまでの完全なパイプラインをカバーします。テストオラクルとしてCLASSのCソースコードを使用し、精度表と失敗した数値的アプローチを追跡する進捗ファイルを用いて、Claudeは数日間の実時間でゼロから構築し、CLASSとの1%未満の一致を達成しました。この種のタスクは、多数の並列エージェントに委任できるCコンパイラープロジェクトとは構造的に異なります。一方、ボルツマンソルバーは深く結合したパイプラインです。例えば、再結合モジュールの微妙な誤差は、可視関数を静かにシフトさせ、それが拡散減衰スケールを変更する、といった具合です。デバッグには、因果関係を通じてチェーン全体をトレースする必要があり、これは単一のエージェントが順次作業し、必要に応じてサブエージェントを生成し、参照実装を使用して不一致を二分探索し、作業を継続的にテストするのに適しています。
私はClaudeに、プロジェクトの過程でコードの主要な成果物の一部—様々なCMB角パワースペクトラ—の精度を再構築し、マイルストーンもラベル付けするよう依頼しました。それは上のプロットを生成し、数日間の実行(エージェントはこの期間中継続的に実行されていたわけではなく、数回再起動されました)を経て1%未満の精度に至る道筋を示しました。エージェントの進捗はややぎこちないものでした—異なるゲージ規約につまずくなど、宇宙学者には明らかな間違いを犯す可能性がありました—しかし、それは1%未満の精度という設定された目標に向かって持続的な進歩を続けました。
結果として得られたソルバーはプロダクショングレードではありませんが、エージェント駆動開発が研究者の数か月または数年にわたる作業を数日に圧縮できる可能性を示しています。
機械学習研究における普遍的な経験は、実験(例えば、トレーニング実行)を一晩中起動し、翌朝結果を見る満足感を得たいと思うことです。実験を実行しないことは機会費用を伴います。最近では、エージェントを実行しないことも費用を伴うように感じられます。計算リソース割り当て、テストスイートを持つコードベース、明確に定義された精度目標がある場合、セッションを実行しない毎晩は、取り残されている潜在的な進歩です。科学計算は、しばしばエージェントがうまく扱える種類の作業—2の因子を追跡すること、中間値を参照と比較すること、パラメータ空間全体で検証スイープを実行すること—でボトルネックになります。これらは、不可能だからではなく、退屈だから研究者が先延ばしにするタスクです。
関連コンテンツ
- AIの労働市場への影響:新しい尺度と初期の証拠
- Claude Opus 3のモデル廃止に関するコミットメントの更新
- ペルソナ選択モデル
原文を表示
Long-Running Claude for Scientific Research
Use of coding agents for scientific research today typically follows a conversational pattern: you ask a question, get a response, and iterate. Certain flavors of scientific computing tasks don’t clearly fit that model—e.g. reimplementing a numerical solver, converting legacy scientific software written in an old Fortran dialect to a modern language like Rust, or debugging a large codebase against a reference implementation. These are tasks where the work is well-scoped, the success criteria are clear, and human oversight might be needed occasionally rather than continuously to guide overall approach. These could take days or even weeks of wall-clock time.
The C compiler project demonstrated a version of this, where Claude worked across roughly 2,000 sessions to build a C compiler capable of compiling the Linux kernel. With a set of tests, progress tracking, and an autonomous execution loop, a parallel team of Claudes was able to make sustained progress on a large technical project across many independent sessions until all success criteria were met.
This tutorial describes how to set up a similar pattern for scientific computing using Claude Code, with a typical academic lab in mind. We’ll use an HPC cluster running the SLURM job scheduler as our working example, but the core ideas—a progress file, a test oracle, an agent prompt with clear rules—apply regardless of where you run Claude Code. As of writing, a 5x or 20x Max plan subscription, depending on the scope of task, should be adequate for most workflows of this nature.
Iterate on the Plan Locally
In this new way of working, you should spend most of your time crafting the project brief that clearly articulates the project’s deliverables and relevant context. Before moving to the cluster, it is useful to iterate on this brief locally, working with Claude to refine it. Save the result as a file named CLAUDE.md
A good project prompt should also have an orientation protocol, which tells the agent what to do first at the start of a new session before it writes any code, e.g. “Read CHANGELOG.md—especially ‘Current status’ and ‘Next steps’. Pick the highest-impact task from the priority list.” This prevents the failure mode of the agent diving into code without understanding what’s already been done or re-attempting approaches that already failed.
The initial parts of the project could also be done on Claude Code on the web, and then the /teleport
Memory Across Sessions
The progress file, which by convention we call here CHANGELOG.md
The Test Oracle
Long-running autonomous work depends on the agent having a way to know whether it’s making progress. For scientific code, this could be a reference implementation, a clearly quantifiable objective, or an existing test suite. It can be helpful to instruct the agent to expand the test suite and run tests as it works, to prevent regressions.
Git as Coordination
Git and GitHub are good ways to monitor and coordinate the agent’s progress in a hands-off manner. The agent should commit and push after every meaningful unit of work. This gives you a recoverable history if something goes awry, makes progress visible locally, and prevents work from being lost if e.g. your compute allocation runs out mid-session.
Practically, this could be a set of instructions in CLAUDE.md
pytest tests/ -x -q
For steering the agent, you can always SSH into the cluster and manually reprompt and/or update its instructions. You can also use Claude Code hooks to enable collaborative steering without attaching to the session directly. For example, a PostToolUse
The Execution Loop
As mentioned above, it’s often useful to first iterate on the plan locally until you have one that looks reasonable, and is encoded in CLAUDE.md
An example SLURM job script that launches Claude Code in a tmux session might look like the following:
bash#!/bin/bash #SBATCH --job-name=claude-agent #SBATCH --partition=GPU-shared #SBATCH --gres=gpu:h100-32:1 #SBATCH --time=48:00:00 #SBATCH --output=agent_%j.log cd $PROJECT/my-solver source .venv/bin/activate export TERM=xterm-256color tmux new-session -d -s claude "claude; exec bash" tmux wait-for claude
CopyOnce the job starts, you attach to the tmux session, give Claude Code direction (e.g., “Read CHANGELOG.md
bashsrun --jobid=JOBID --overlap --pty tmux attach -t claude
CopyThe Ralph loop
As models get better, they require less bespoke orchestration (prompt engineering, RAG, context stuffing, …). Current models can however suffer from agentic laziness—when asked to complete a complex, multi-part task, they can sometimes finish part of the task before finding an excuse to stop (“It’s getting late, let’s pick back up again tomorrow”).
A useful orchestration pattern today is the Ralph loop, which is essentially a for loop which kicks the agent back into context when it’s done, and asks if it’s really done. This can be useful for long-running tasks since the agent will admit the task is not up to spec, and continue until it is.
Ralph can be installed via /plugin
claude code/ralph-loop:ralph-loop "Please keep working on the task until the success criterion of 0.1% accuracy across the entire parameter range is achieved." --max-iterations 20 --completion-promise "DONE"
CopyHere, Claude will iterate up to 20 times until it guarantees that the task is done with a “DONE” incantation. Instead of manually SSH’ing into the cluster and running commands inside the interactive Claude Code session, you can always ask a local version of Claude Code (e.g., on your laptop) to do this.
An Application, and Conclusions
As a concrete example, I used these patterns with Claude Opus 4.6 to implement a differentiable cosmological Boltzmann solver, which is a numerical code that predicts what the afterglow of the Big Bang—the Cosmic Microwave Background, or CMB—should look like given a set of cosmological parameters (e.g., dark energy fraction). It does this by evolving coupled equations for photons, baryons, neutrinos, and dark matter through the early universe. Boltzmann solvers like CLASS and CAMB are core pieces of scientific infrastructure in cosmology, enabling parameter estimation from surveys like Planck and the Simons Observatory.
The implementation is fully differentiable through JAX, enabling gradient-based inference. Complementing existing codes which come with significant simplifications, this solver covers the full pipeline through to various CMB observables. Using the CLASS C source as a test oracle and a progress file tracking accuracy tables and failed numerical approaches, Claude built it from scratch over a few days of wall-clock time, reaching sub-percent agreement with CLASS. This kind of task is structurally different from the C compiler project, which can be farmed out to a large number of parallel agents. A Boltzmann solver on the other hand is a deeply coupled pipeline: a subtle error in the recombination module can silently shift the visibility function, which changes the diffusion damping scale, and so on. Debugging requires tracing causally through the entire chain, which is better suited to a single agent working sequentially, spawning sub-agents as needed, and using the reference implementation to bisect discrepancies and continuously testing its work.
I asked Claude to reconstruct the accuracy of some of the main deliverables of the code—the various CMB angular power spectra—over the course of the project, also labeling milestones. It produced the plot above, showing the path to sub-percent accuracy after running for a few days (the agent wasn’t running continuously during this period, and was restarted several times). The agent’s progress was a bit clunky—it can make mistakes that would be obvious to a cosmologist, such as tripping over different gauge conventions—but it kept making sustained progress towards the stated goal of sub-percent accuracy.
While the resulting solver is not production-grade, it demonstrates that agent-driven development can compress months or even years of researcher work into days.
A universal experience in machine learning research is wanting to launch an experiment (e.g., a training run) overnight and then have the satisfaction of seeing the results in the morning. Not running the experiment comes with an opportunity cost. These days, not running agents feels like it has a cost as well. If you have a compute allocation, a codebase with a test suite, and a well-defined accuracy target, every night you don’t run a session is potential progress left on the table. Scientific computing often bottlenecks on exactly the kind of work agents handle well—tracking down factors of 2, comparing intermediate values against a reference, running validation sweeps across parameter space. These are tasks researchers defer because they’re boring, not because they’re impossible.
Related content
Labor market impacts of AI: A new measure and early evidence
An update on our model deprecation commitments for Claude Opus 3
The persona selection model
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み