Skip to main content
skill CX Codex

principle-make-operations-idempotent — Claude Code skill: safe

A skill for writing commands and processing loops that converge to the same state regardless of restarts, crashes, or retries. Use it when operations need to survive partial runs and still reach the correct outcome.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a claude-code
Open on GitHub

What principle-make-operations-idempotent does

The core pattern: every step reads the current state and applies only the difference from the goal, rather than assuming the previous run succeeded. A step written this way is safe to repeat—a second run finds nothing left to do.

What matters: anything left behind (a lock, temp file, incomplete record, reserved job) must be recognizable as stale by the next run. Judge staleness by evidence that stays true wherever the previous run could have failed, not just in the happy path. A marker you cannot judge after a crash turns every failure into manual cleanup. For example: write to a temporary path and rename it into place, or compare artifacts by content rather than creation order.

Before you commit: run it twice in a row, imagine it crashes at every possible point, and verify the final state is the same. If the answer is "it depends on what was left behind," add a reconciliation step.

What it helps with

  • Protect data processing from crashes and restarts
  • Avoid manual cleanup after every failure
  • Guarantee the same final result on repeated runs
  • Recognize stale temporary files and locks
  • Design reliable setup scripts and migrations

Example prompts for the agent

  • Help me rewrite this database migration script so it's safe to run twice without errors
  • Make this queue handler idempotent: read the current status before every state change
  • Check whether this command converges to one state even if it crashes midway

How to install principle-make-operations-idempotent

1Skills CLI (Vercel)

npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a claude-code

2Manually: put the files in place

~/.claude/skills/principle-make-operations-idempotent/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/principle-make-operations-idempotent/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about principle-make-operations-idempotent

How do I install principle-make-operations-idempotent in Claude Code?

Run npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a claude-code, then find the skill file at ~/.claude/skills/principle-make-operations-idempotent/SKILL.md.

What does the principle-make-operations-idempotent skill do?

It teaches you to design commands and loops that safely survive crashes, restarts, and retries. Each operation should read the current state and apply only the necessary changes, rather than rely on the success of previous runs.

Why is idempotency important for data processing?

If an operation fails or restarts partway through, the next run must recover automatically. Without idempotency, every crash demands manual cleanup and a restart from the right checkpoint.

Source text

SKILL.md · MIT
---
name: principle-make-operations-idempotent
description: "Apply when designing commands, lifecycle steps, or processing loops that run amid crashes, restarts, and retries. Converge to the same end state regardless of partial prior runs."
disable-model-invocation: true
---

# Make Operations Idempotent

Design operations so they converge to the correct state regardless of how many times they run or where the previous run stopped. Every state-mutating operation should answer: "What happens if this runs twice? What happens if the previous run crashed halfway?"

**Why:** Commands, lifecycle operations, and processing loops run where crashes, restarts, and retries are normal. If partial state changes the next run's outcome, every restart becomes a debugging session.

**The idea:** derive each step from the state that exists, not from what the previous run meant to do. Read the current state, compare it to the goal, and apply only the difference. A step written this way is safe to repeat, because a repeat finds nothing left to do.

Anything a run leaves behind, such as a lock, a temporary file, a half-written record, or a claimed job, must be recognizable as stale by the next run. Judge staleness by evidence that stays true wherever the previous run could have stopped, not only in the common case. A marker that the next run cannot judge turns every crash into manual cleanup. For example, write to a temporary path and rename it into place, or compare artifacts by content instead of by creation order.

**The test:**
1. What happens if this runs twice in a row?
2. What happens if the previous run crashed at every possible point?
3. Does re-execution converge to the same end state?

If any answer is "it depends on what state was left behind," the operation needs a reconciliation step.

© backnotprop · MIT · backnotprop/pstack

Similar skills

All skills for DevOps and infrastructure →

From the same set44

principle-model-the-domain Guides an agent to model domain rules in data structures instead of growing conditionals. Use it when stateful code or repeated shape assumptions start spreading. CX Codex +1 5,200installs principle-redesign-from-first-principles A skill that makes the agent rebuild an existing design as if the new requirement had been there from day one. Use it when a change ripples through types, docs, and examples. CX Codex +1 5,200installs principle-never-block-on-the-human Instructs coding agents to execute reversible changes immediately instead of asking for approval. Useful for autonomous sessions under asynchronous supervision. CX Codex +1 5,200installs principle-build-the-lever A skill that pushes the agent to write a codemod, script or generator for non-trivial work instead of editing by hand, so the result can be rerun. CX Codex +1 5,200installs principle-subtract-before-you-add A development skill that enforces removing dead code, stubs, and unused validators before writing new features or refactoring. CX Codex +1 5,200installs maintain-verification-skill Keep a project's verification guide and feature map aligned with its code. The skill checks each mapped feature against the live app and flags confirmed fixes. CX Codex +1 5,200installs no-comments The skill spawns a comment-sicko subagent, deletes comments that explain nothing, and asks you before encoding real constraints as checks. CX Codex +1 5,200installs teach The skill explains codebases and architecture plainly without walls of text. It runs the how and why skills to combine implementation mechanics with design rationale. CX Codex +1 5,100installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor