Agent skill
40-01-state-ownership
Every piece of mutable state has exactly one owner that writes it. Others read. Prevents "who set this?" and invisible coupling.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/40-01-state-ownership
SKILL.md
40.01 State Ownership
Every piece of mutable state has exactly one system that writes it. Everyone else reads.
The Problem
When multiple systems write the same state:
- Race conditions — who set this value?
- Invisible coupling — changing one writer breaks another
- Untestable code — can't isolate the write path
- God objects — one module "owns" everything because it writes everything
The Rule
For every piece of mutable state, you must be able to answer: "Who writes this?" with exactly one name.
| State | Owner (writes) | Everyone else |
|---|---|---|
| Entity position | Physics system | Read-only |
| Connection state | Connection lifecycle | Read-only |
| Player identity | Session resolution | Read-only |
| ECS entity IDs | Entity bridge | Read-only |
| Tuning values | Tuning loader | Read-only |
If you can't fill in the "Owner" column with one name, the design is wrong.
How to Apply
- Declare state in one place. One module, one struct, one table — not scattered across files.
- Write from one system. If two systems need to write the same field, one of them is wrong. Find the real owner.
- Name the owner. Comment, colocation, or naming convention — make ownership obvious at the declaration site.
- Readers access state directly. No getter functions wrapping a read. No passing state through layers of callbacks.
Anti-Pattern: Trapped State
State that can only be accessed through the module that owns it, because it's hidden inside a closure, private field, or local variable. This forces everything into one module.
The fix: move state to a shared location. The owner still writes. But now readers don't need to go through the owner.
Anti-Pattern: Multiple Writers
System A writes entity.position (for physics)
System B writes entity.position (for teleport)
System C writes entity.position (for spawn)
→ "Who moved the entity?" — impossible to answer
Fix: one system owns position. Teleport and spawn send requests/inputs to that system.
The Test
Point at any mutable field. Can you name the ONE system that writes it?
If the answer is "it depends" or "several things" — fix the ownership.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?