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.
npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a claude-codeWhat 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-code2Manually: put the files in place
~/.claude/skills/principle-make-operations-idempotent/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/principle-make-operations-idempotent/
1Skills CLI (Vercel)
npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a codex2Manually: put the files in place
.agents/skills/principle-make-operations-idempotent/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a cursor2Manually: put the files in place
.cursor/skills/principle-make-operations-idempotent/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install backnotprop/pstack principle-make-operations-idempotent2Manually: put the files in place
.github/skills/principle-make-operations-idempotent/SKILL.md1Skills CLI (Vercel)
npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a gemini-cli2Platform CLI
gemini skills install https://github.com/backnotprop/pstack --path skills/principle-make-operations-idempotentManually: put the files in place
.devin/skills/principle-make-operations-idempotent/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add backnotprop/pstack --skill principle-make-operations-idempotent -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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