Create only idempotent artifact write

From ychampion/cskill-agents · View interactive version

Create only idempotent artifact write is an AI agent skill from the GitHub repository ychampion/cskill-agents. Persist deterministic artifacts with a create-only write and treat existing files as replay success instead of an error.

How to use this skill

Skill file

SKILL: Create-Only Idempotent Artifact Write

Domain: tool-orchestration

Trigger: Apply when a deterministic artifact is keyed by a stable invocation ID and may be replayed across retries, compaction, or resume passes.

Source Pattern: Distilled from reviewed tool-loop and result-shaping patterns.

Core Method

When an artifact path is derived from a stable identity, write it once with an atomic create-only operation instead of checking for existence first. If the write hits "already exists," treat that as proof the earlier successful write already materialized the deterministic content and continue with the normal readback or preview path. This removes the stat-then-write race, avoids useless rewrites during replay, and keeps repeated passes behaviorally identical.

Key Rules

Example Application

If a large tool result is persisted under tool-results/<tool_use_id>.json, write it once with a create-only flag. When transcript replay or micro-compaction revisits that same tool result, the write sees EEXIST, skips the rewrite, and still returns the same preview payload and saved path to the caller.

Anti-Patterns (What NOT to 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.