MetaClaw idempotent-script-design
Use this skill when writing scripts, cron jobs, data pipelines, or any automated process that may be run multiple times. Design every operation to be safely re-runnable without side effects.
install
source · Clone the upstream repo
git clone https://github.com/aiming-lab/MetaClaw
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/aiming-lab/MetaClaw "$T" && mkdir -p ~/.claude/skills && cp -r "$T/memory_data/skills/idempotent-script-design" ~/.claude/skills/aiming-lab-metaclaw-idempotent-script-design && rm -rf "$T"
manifest:
memory_data/skills/idempotent-script-design/SKILL.mdsource content
Idempotent Script Design
An idempotent operation produces the same result whether run once or ten times.
Techniques:
- Check before create:
,CREATE TABLE IF NOT EXISTS
, check file existence before writing.mkdir -p - Upsert instead of insert: Use
in SQL.INSERT ... ON CONFLICT DO UPDATE - Atomic writes: Write to a temp file, then rename — prevents corrupt partial output.
- Track progress: Write a completion marker or checkpoint so reruns skip done work.
Testing idempotency: Run your script twice on the same input and verify the output is identical.
Anti-patterns:
- Appending to a file without checking if the data is already there.
- Inserting rows without checking for duplicates.