principle-separate-before-serializing-shared-state
What it does
Gives the assistant a rule for handling concurrent work that might write to the same file, branch or state. It is for engineers who run several workers or agents at once.
When to use it
- ✓When several agents or processes might write to the same file or state object.
- ✓When two branches or workers would push to the same target.
- ✓When you are tempted to add a lock to fix intermittent race conditions.
Skill link
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-separate-before-serializing-shared-state/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Three agents write to one shared status file and it keeps getting corrupted. Fix the design.”
5 new skills a week. 1 minute to read.
How it works
The assistant asks whether the workers really need one shared object. If not, it gives each its own file or key and merges only at the reporting step. Only when a single shared writer is truly required does it add structural serialization, such as a lock.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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:
- Identify shared mutable state (files both read and write, branches both push to, APIs both define and consume).
- 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
lastXfield into onestate.jsonis still shared mutation.indexer-state.json+metrics-state.jsonis not. - 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.
FAQ
Are instructions enough to prevent conflicts?
No. The skill says instructions and conventions are not concurrency control.
Is a lock the default fix?
No. The skill treats the need for a lock as a design smell to check first.
What is a good split?
Separate state files that each actor owns, instead of several workers writing into one shared file.
Details
Original description by the author
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.
repo: cursor/plugins
Popularity
- GitHub stars
- 15k
- Ranking position
- #10987
- License
- —
- Updated
- 10/31/2026
Comments
- …
More skills from this repository
advisor
15kLets your agent consult a stronger second model at key checkpoints, such as before a big decision or when stuck on an error, if you turn it on.
check-agent-compatibility
15kRuns a full check of whether AI coding agents can start, verify and document a repository, and returns one compatibility score with the main issues.
cli-for-agents
15kTeaches your agent to design or review command-line tools so AI agents can run them without prompts, with clear help text and examples.
continual-learning
15kKeeps your AGENTS.md notes up to date by handing the work of reviewing past chats to a dedicated memory updater.
Similar skills
api-connector-builder
280kHas your agent build new API connections following the existing pattern. Use when you need to add one more integration without creating a new way of doing things.
api-design
280kHelps your agent design REST APIs following best practices. It's useful for defining how APIs communicate, how errors are shown, and how to organize data.
backend-patterns
280kHelps your agent with server-side architecture patterns and database optimization. It's useful for building or reviewing code that runs on the server.