Skip to main content
skill CX Codex

principle-separate-before-serializing-shared-state: Claude Code skill

Architectural guideline for concurrent actors: eliminate shared mutable state across files or keys first, resorting to locks only when a single writer is strictly required.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add backnotprop/pstack --skill principle-separate-before-serializing-shared-state -a claude-code
Open on GitHub

What principle-separate-before-serializing-shared-state does

Concurrent writes to shared state cause race conditions that are hard to reproduce. This skill enforces a clear rule: before adding locks or relying on conventions, eliminate the shared target altogether. Each actor gets its own isolated file, branch, or key, and data merges only at the read boundary. For instance, two workers write to indexer-state.json and metrics-state.json rather than modifying one shared state.json.

When a single shared write target is an unavoidable invariant, the principle mandates structural serialization: lockfiles, sequential execution phases, a dedicated single-writer actor, or atomic operations. The guide explicitly treats the reflex of needing a lock as a design smell to investigate.

Because the frontmatter sets disable-model-invocation: true, the assistant treats this skill as an internal architectural constraint rather than an invokable runtime tool.

What it helps with

  • eliminate race conditions in concurrent agent workflows
  • split shared mutable state into isolated actor-specific files
  • structure access via lockfiles or sequential phases when sharing is mandatory
  • shift data merging to the read boundary

Example prompts for the agent

  • Refactor our background workers using principle-separate-before-serializing-shared-state to avoid race conditions
  • Review the shared state files against principle-separate-before-serializing-shared-state guidelines

How to install principle-separate-before-serializing-shared-state

1Skills CLI (Vercel)

npx skills add backnotprop/pstack --skill principle-separate-before-serializing-shared-state -a claude-code

2Manually: put the files in place

~/.claude/skills/principle-separate-before-serializing-shared-state/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/principle-separate-before-serializing-shared-state/

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

Questions about principle-separate-before-serializing-shared-state

How do I install principle-separate-before-serializing-shared-state in Claude Code?

Run npx skills add backnotprop/pstack --skill principle-separate-before-serializing-shared-state -a claude-code in your terminal.

What is the main goal of this skill?

It provides an architectural rule that prevents race conditions by isolating write targets per actor instead of immediately adding lock mechanisms.

Why is disable-model-invocation set to true?

This flag keeps the skill as a design guideline in context without exposing it as a callable execution tool.

Source text

SKILL.md · MIT
---
name: principle-separate-before-serializing-shared-state
description: "Apply when concurrent actors might write to the same file, branch, key, or state object. Eliminate the sharing first; serialize structurally only when one shared writer is a real invariant."
disable-model-invocation: true
---

# Separate Before Serializing Shared State

When concurrent actors might share mutable state, first ask whether they need the same mutable object. If not, eliminate the sharing. When sharing is real, enforce serialization structurally: lockfiles, sequential phases, exclusive ownership. Instructions and conventions are not concurrency control.

**Why:** Concurrent writes to shared state create race conditions that are intermittent, hard to reproduce, and expensive to debug.

**Pattern:**
1. **Identify shared mutable state** (files both read and write, branches both push to, APIs both define and consume).
2. **Default: eliminate the shared write target.** Ask: do these actors need one canonical object, or are they publishing independent facts? Give each actor its own owned file, key, branch, or state directory, and merge only at the read/reporting boundary. Two workers writing their own `lastX` field into one `state.json` is still shared mutation. `indexer-state.json` + `metrics-state.json` is not.
3. **Only when one shared write target is a real invariant, serialize access structurally** (lockfiles, sequential phases, single-writer actor, or atomic compare-and-swap). Treat "we need a lock" as a design smell to check, not as the default answer.

© backnotprop · MIT · backnotprop/pstack

Similar skills

All skills for Code review and refactoring →

From the same set44

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 tdd This skill makes the agent write a failing regression test for a bug before touching production code. It only kicks in when a cheap test path exists. CX Codex +1 5,100installs principle-experience-first A principle skill that shifts priority toward the user when product, UX, or feature-scope tradeoffs come up. Useful when deciding what to cut. CX Codex +1 5,100installs principle-attack-the-premise This skill tests the shared premise behind repeated failed fixes. Use it before writing another fix that hits the same gate. CX Codex +1 5,100installs principle-foundational-thinking A principle set for the stage before logic: pick core types and data structures, order the scaffold, check what concurrent actors share. CX Codex +1 5,100installs correct Finds repeated mistakes made by coding agents and makes them impossible through architecture, types, linters, or tests. Useful when agents keep making the same wrong edits. CX Codex +1 4,200installs benchmark-checklist A skill that makes the agent answer seven questions with evidence from a run before it reports a speedup or a regression. CX Codex +1 4,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