Capture environment

From pedrohcgs/claude-code-my-workflow · View interactive version

Capture environment is an AI agent skill from the GitHub repository pedrohcgs/claude-code-my-workflow. Snapshot the computational environment for a replication package — detects the analysis stack (R / Stata / Python) and emits the right lockfiles (renv.lock + sessionInfo.txt, requirements.txt / environment.yml / uv.lock, Stata version + ado package list), records seeds and RNG kind, optionally write

How to use this skill

Skill file

`/capture-environment` — snapshot the computational environment

A replication package that runs on the author's laptop in 2026 and nowhere else in 2029 is not reproducible. This skill captures the exact computational environment — language versions, package versions, seeds, RNG kind, and (optionally) the OS layer — so a referee, the AEA Data Editor, or future-you can reconstruct it. It detects which stack the project uses and emits the artifacts that stack's ecosystem expects, then verifies the lockfile installs clean.

Core principle: Pin everything a result depends on. Display rounding aside, a re-run on a pinned environment should reproduce the paper to the CODE0 tolerances — byte-identical when the optional Dockerfile is used.

When to use

Inputs

Workflow

Phase 0: Detect the stack

Glob for stack signals and decide which capture paths to run (a project may be multi-language — DiD in R, an IV robustness check in Stata):

| Signal | Stack | Capture path |

|---|---|---|

| scripts/R/*.R, DESCRIPTION, renv/, *.Rproj | R | renv + sessionInfo |

| scripts/python/*.py, *.ipynb, pyproject.toml, requirements.txt, environment.yml, uv.lock | Python | pip / conda / uv |

| scripts/stata/*.do | Stata | version + ado list |

If no signal is found, report and stop — there is no environment to capture.

Phase 1: Capture per language

R — emit two artifacts:

Python — emit whichever matches the project's existing tooling (do not invent a new one):

Always also record the interpreter version (python --version) in the report.

Stata — Stata has no lockfile, so capture the closest equivalents (mirrors CODE0 §3):

Phase 1b: Record seeds and RNG

Grep the analysis scripts for the master seed and RNG kind so the "Computational requirements" block can state them:

If the pipeline does randomized work (bootstrap, MC, RCT re-randomization, permutation inference) and no seed is found, surface it as a WARNING — an unseeded random result is not reproducible.

Phase 2: Dockerfile (only with `--docker`)

Emit a Dockerfile that pins the OS + language version + system libraries for byte-identical reproduction:

Pin a digest where possible (FROM image@sha256:…) so the base image can't drift.

Phase 3: Verify the lockfile installs clean (best-effort; skip with `--no-verify`)

Attempt a clean restore in a throwaway location and report PASS / FAIL — never overwrite the working environment:

A FAIL here means the lockfile references a package version that can't be resolved (yanked release, private remote, platform-specific wheel). Report it; do not auto-edit the lockfile.

Phase 4: Report

Print a paste-ready block and write it to output/computational_requirements.md:

## Computational requirements

**Software:** R 4.4.1 (or: Stata 18.0 SE, update 2026-01-15; Python 3.12.3)
**OS used:** macOS 15.5 (arm64) — Dockerfile pins Ubuntu 24.04 for portability
**Key packages:** fixest 0.12.1, did 2.1.2 (full list in renv.lock)
**Random seeds:** set.seed(20260609); RNGkind("L'Ecuyer-CMRG") for the bootstrap
**Approx. runtime:** [author confirms — e.g. ~12 min, 8 cores]
**Lockfiles in package:** renv.lock, output/sessionInfo.txt[, Dockerfile]

Pre-fill software/package/seed lines from the captured artifacts; leave runtime for the author to confirm.

Output / artifacts

| Stack | Files written |

|---|---|

| R | renv.lock, output/sessionInfo.txt |

| Python | requirements.txt or environment.yml or uv.lock (matching project tooling) |

| Stata | output/sessionInfo_stata.txt (version + ado list; named so it does not overwrite R's in a mixed project) |

| Any (--docker) | Dockerfile |

| Always | output/computational_requirements.md (the paste-ready block) |

Exit behavior

Cross-references

What this skill does NOT do

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.