Orchestrates parallel work dispatch to Google Cloud Batch, polls for completion, and harvests results from the GCS mount. Use when jobs are too parallel, slow, or long-running for local execution.
Ships in gcp-compute. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You've decided this work doesn't belong on the workstation. This skill covers the orchestration — dispatch, polling, harvest, failure triage — not the science; what to run and why comes from the task and its own skills.
The thing that makes this integration different from a normal tool: the control
plane and the data plane are separate, and results never travel through a tool
response. submit_run and get_run_status return ids, states and counts. The
actual outputs land in Google Cloud Storage, which is mounted read-only on this
machine at /mnt/gcs, and you read them with ordinary open(). That is what lets a
500-task run with gigabytes of output cost you almost nothing in context. Preserve
it: if you ever find yourself trying to get file contents back from an MCP call,
you have taken a wrong turn.
Dispatch when the work is embarrassingly parallel and genuinely slow locally — per-sequence searches, per-structure scoring, parameter sweeps, anything shaped like "do the same thing to N independent items". Sixty seconds of that overhead is VM provisioning, so the crossover is roughly: if the whole thing finishes locally in under a couple of minutes, run it locally.
Dispatch also when the run outlives the session. The workstation idle-stops; a Batch job doesn't care. A researcher can submit 500 tasks, close the laptop, and the results are waiting. Long local jobs die to the idle timeout — offloaded ones don't. That is often the real reason to reach for this, not raw speed.
There are two mounts, and they are mirror images of each other:
| On the workstation | In each task | Direction |
|---|---|---|
/mnt/gcs (read-only) | $OUT_DIR, $LOG_FILE under /mnt/disks/run | results come back |
/mnt/gcs-in (read-write) | $INPUTS_DIR (read-only) | data goes out |
So to give tasks a file: write it to /mnt/gcs-in from a python cell, then read
it in the command as $INPUTS_DIR/<name>. Nothing else is needed — no credentials,
no upload step, no GCS API calls in the payload.
# python cell — stage the input
import shutil
shutil.copy("my_sequences.fasta", "/mnt/gcs-in/my_sequences.fasta")
# repl cell — the task reads it straight off its own mount
host.mcp("gcp-batch", "submit_run", name="scan",
command='python3 scan.py --in "$INPUTS_DIR/my_sequences.fasta" --out "$OUT_DIR"',
task_count=32)
You never authenticate to GCS, in either direction. You write to a path; gcsfuse, running outside the sandbox, does the upload.
Three things about /mnt/gcs-in worth knowing before you use it as a filesystem:
with open(...) block.If the researcher's data is genuinely enormous, staging through the mount is still the only path; just tell them it will take as long as the upload takes.
Every job runs in this deployment's region, and both data buckets live there.
submit_run returns it as region. There is no per-job override: compute and data
are pinned together, which is what makes the residency story simple, and also what
makes it inflexible.
State the region when you submit rather than leaving it implicit — "submitted to Cloud
Batch in us-central1" costs one clause and pre-empts the question.
Confirm it explicitly whenever the work touches anything regulated: patient or clinical data, human genomes, anything the researcher describes as controlled, governed by GDPR, or "must stay in" somewhere. Ask before submitting, not after:
This deployment runs in
us-central1, and your data would be staged and processed there. Does that satisfy your data-residency requirements? If the work has to stay in a particular jurisdiction, stop here — I cannot dispatch to another region, and your administrator would need to deploy one there.
Do not offer a region parameter, or imply one might work. Getting this wrong is not a failed job; it is a compliance incident that completes successfully.
Most work does not need one. Sequence search, parameter sweeps, statistics, simulation: all CPU. A GPU costs 5–30× a CPU task and buys nothing unless the payload actually uses CUDA. So the first question is whether this job needs one at all.
Usually you can tell without asking — the payload imports torch/tensorflow/jax, calls a structure-prediction or embedding model, or the researcher says "training". If it is clear, don't interrogate them; just pick sensibly and say what you chose. Ask only when it is genuinely ambiguous, and ask about the science rather than the hardware:
Does this step run on GPU — does it use PyTorch/TensorFlow, or a model that needs CUDA? If it is plain Python or NumPy, CPU will be cheaper and usually faster to start.
If no: submit normally. Nothing else changes.
If yes: two things are needed — an accelerator and a container that has CUDA. Pass
gpu_type and leave machine_type unset; Batch resolves the machine family from
the accelerator and installs the driver itself. Never pass a CPU machine type alongside
a GPU — e2 and n2 cannot take accelerators at all, and the job is rejected.
nvidia-l4 is the default. Use it unless the researcher gives you a reason not to.
It is current-generation, has 24 GB, and handles inference and small-to-mid training.
| Type | When | Rough on-demand |
|---|---|---|
nvidia-l4 | the default — start here | ~$0.70/GPU-hr |
nvidia-tesla-a100 | 40/80 GB, large training or a model that will not fit in 24 GB | ~$3/GPU-hr |
nvidia-h100-80gb | very large training | ~$11/GPU-hr |
nvidia-tesla-t4 | fallback only — older and half the memory. Reach for it when L4 capacity is unavailable, not as a cost saving | ~$0.35/GPU-hr |
Indicative for us-central1, excluding the VM's own CPU and disk; Spot is roughly
60–70% cheaper. Quote the rate; do not estimate the job's cost. You do not know how
long their pipeline runs — they do, from having run it before. Give them the number and
let them judge. Never refuse or resize work on a guessed cost.
Do not "save money" by starting at T4 — it is a generation behind with 16 GB, and work that spills out of memory or runs 3× slower costs more than the hourly difference saves. Go up to A100 only when the researcher says the model needs the memory; that multiplies the bill 4×.
image= is effectively required: the Batch host image is bare python3, with no CUDA
and no framework.
Ask for the researcher's own image first. Most groups have one, and it will already carry their pipeline, their framework version and their dependencies:
Do you have a container image for this? If not I'll start from Google's PyTorch deep-learning container, but yours will be closer to what the pipeline expects.
If they don't have one, the images below are starting points, not recommendations — published by Google, pinned to particular framework versions, and not validated against any specific pipeline. Name the one you chose and the version it carries, so the researcher can correct you:
| If the payload uses | Starting point |
|---|---|
| PyTorch | us-docker.pkg.dev/deeplearning-platform-release/gcr.io/pytorch-gpu.2-4.py310:latest |
| TensorFlow | us-docker.pkg.dev/deeplearning-platform-release/gcr.io/tf-gpu.2-16.py310:latest |
| CUDA, own framework | us-docker.pkg.dev/deeplearning-platform-release/gcr.io/base-gpu.py310:latest |
| plain CUDA runtime | nvidia/cuda:12.4.1-runtime-ubuntu22.04 |
CUDA + nvcc to compile | nvidia/cuda:12.4.1-devel-ubuntu22.04 |
If a run fails on framework version, missing packages or a CUDA mismatch, that is the image being wrong for the job rather than the dispatch being broken — say so, and ask what they normally run in.
NVIDIA's NGC images (nvcr.io/nvidia/...) are excellent but many require an NGC
login, which this deployment has no credentials for. Prefer the Google-hosted or
Docker Hub images above unless the researcher confirms NGC access is set up.
Expect a slow first task: these images are several GB and the pull happens before your payload runs.
Jobs with image= get a 200 GB boot disk automatically. Batch's own default is
30 GB, which a real ML container does not fit into — the pull dies partway with
no space left on device, and the task reports exit 1 as though the payload were
broken. If an unusually large image still runs out, pass boot_disk_gb higher rather
than assuming the image is at fault.
host.mcp("gcp-batch", "submit_run", name="embed",
image="us-docker.pkg.dev/deeplearning-platform-release/gcr.io/pytorch-gpu.2-4.py310:latest",
command='python3 /opt/embed.py --shard "$TASK_INDEX" --in "$INPUTS_DIR" --out "$OUT_DIR"',
task_count=8, gpu_type="nvidia-l4", spot=False)
SCHEDULED with no tasks running, for minutes, is normal-ish and has two unrelated
causes worth telling apart before anyone starts debugging the payload:
Both look identical from the job (CODE_GCE_ZONE_RESOURCE_POOL_EXHAUSTED). If the
researcher's team says they hold quota, it is capacity: wait, retry, or fall back to a
different accelerator. Say which you think it is rather than reporting "the job is
stuck".
MCP tools are only attached to the repl tool. host.mcp(...) from a python
cell fails. repl is stdlib-only (python -I -S), so no pandas, no numpy there.
The two kernels share a workspace directory but not memory. So the rhythm is:
repl — every host.mcp("gcp-batch", ...) call. Write anything the analysis
needs to ./handoff/<name>.json.python — read ./handoff/*.json, then read results from run_dir and do the
actual work with the libraries you want.# repl cell
import json, os
r = host.mcp("gcp-batch", "submit_run",
name="msa-fanout",
command='python3 /opt/run_msa.py --shard "$TASK_INDEX" --out "$OUT_DIR"',
task_count=64, machine_type="e2-standard-4", spot=True)
os.makedirs("handoff", exist_ok=True)
json.dump(r, open("handoff/run.json", "w"))
print(r["run_id"], r["run_dir"])
Your command is bash, run once per task, with these already set:
| Variable | Meaning |
|---|---|
TASK_INDEX | zero-padded task number — 0000, 0001, … |
OUT_DIR | write results here; appears under run_dir/outputs/task-NNNN/ |
LOG_FILE | stdout and stderr already land here; append if you want more |
INPUTS_DIR | read-only view of whatever was staged at /mnt/gcs-in |
BATCH_TASK_COUNT | total tasks, for computing your shard |
Shard on TASK_INDEX. Write only into OUT_DIR. Anything else is thrown away with
the VM.
Pass image= if the payload needs a container; omit it to run on the Batch host
image, which has python3 and little else.
1. Submit, then let the cell return. Never block a cell waiting for a job.
2. Poll. get_run_status(run_id) in a repl cell, with a bounded sleep loop —
say a couple of minutes per cell — then return and poll again from a new cell if it
isn't terminal. Report progress to the user between polls; a silent five-minute gap
reads as a hang.
# repl cell
import json, time
rid = json.load(open("handoff/run.json"))["run_id"]
for _ in range(12):
s = host.mcp("gcp-batch", "get_run_status", run_id=rid)
if s["terminal"]:
break
time.sleep(10)
json.dump(s, open("handoff/status.json", "w"))
print(s["state"], s["tasks"])
⚠️ get_run_status is what finalises the run. The _COMPLETE sentinel and
MANIFEST.json are written by the control plane the first time it observes a
terminal state — not by the tasks. A job can be finished in Batch for hours with no
sentinel in the bucket because nobody asked. If you are waiting on a sentinel, call
get_run_status. Never wait on _COMPLETE alone.
3. Harvest, from python.
# python cell
import json, os
run_dir = json.load(open("handoff/status.json"))["run_dir"]
assert os.path.exists(f"{run_dir}/_COMPLETE")
manifest = json.load(open(f"{run_dir}/MANIFEST.json"))
wanted = [o for o in manifest["outputs"] if o["path"].endswith("result.json")]
data = [json.load(open(os.path.join(run_dir, o["path"]))) for o in wanted]
Read MANIFEST.json and open files by name. Do not list the outputs directory.
The manifest is the index precisely so you never have to — it carries path, size,
type and task for every output. os.listdir on a directory holding 10,000 files
is slow through the mount and floods your context with filenames you don't need. This
is the rule that makes the whole design scale, and it costs nothing to follow.
Check manifest["output_count"] against the task count before you trust the set. A
short manifest means tasks failed, not that the work is done.
4. Save what matters. Call save_artifacts() on the assembled result — the
figure, the table, the merged dataset — so it gains provenance and appears in the
artifact panel. Save the synthesis, not 500 raw shards.
Partial failure is normal in a large fan-out; treat it as data, not as an error.
STATUS.json (returned by get_run_status) carries tasks.failed and a capped
failures[] — first few plus a total — so a run with 400 failures still reads in a
few hundred bytes. To diagnose, open run_dir/logs/task-NNNN.log for a couple of
failed tasks. They usually share one cause; reading fifty logs to discover the same
missing import is a waste of the user's context and their patience.
Report honestly: "58 of 64 succeeded; the 6 failures all hit the same missing reference file" is useful. "The job completed" when a tenth of it didn't is not.
With spot=True (the default) a task can be preempted; Batch retries once
automatically, so a retried-then-succeeded task is not a failure worth reporting.
spot=True is roughly 60–90% cheaper and is the right default for anything
restartable. Turn it off for a demo or a long single-shot task where a preemption
would hurt more than the money saves.
Size the machine to one task, not to the job — task_count is what buys parallelism.
e2-standard-4 is a sane default; drop to e2-standard-2 for light work.
Set max_run_duration_s to something realistic. It is the guard against a hung task
billing for hours, and the default of 3600 is generous for most shards.
| Call | Returns |
|---|---|
submit_run(name, command, task_count=1, image=None, machine_type="e2-standard-4", max_run_duration_s=3600, spot=True, env=None) | run_id, run_dir, state |
get_run_status(run_id) | state, terminal, task counts, capped failures[], run_dir — and finalises the run |
list_runs(limit=20, state=None) | recent runs: id, name, state, submitted_at |
cancel_run(run_id) | {ok} — outputs already written are kept |
The run directory, at run_dir (/mnt/gcs/runs/<user>/<run-id>/):
STATUS.json bounded status, rewritten on every poll
_COMPLETE exists <=> terminal. Written last, after MANIFEST.json
MANIFEST.json the index: path, size, type, task for every output
outputs/task-NNNN/...
logs/task-NNNN.log
The first submit_run and get_run_status of a session may raise an approval modal
for the user. That is expected and one-time — don't retry around it, and don't
apologise for it.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/gcp-compute:gcp-batchfrom gcp-compute
npx claudepluginhub ryanymt/claude-science-on-gcp --plugin gcp-compute2 skills in this plugin
Other plugins' skills for the same job