hassanzohdy/atom/derived-atoms
Claude Code and agent skill by hassanzohdy/atom
- community
Checking that the SKILL.md file is still in the repository.
How to create computed atoms with `derive()` — auto-tracked dependencies, conditional reads, chained derivations, and cleanup.
Install
npx vskill@latest install hassanzohdy/atom/derived-atomsSKILL.md
Derived Atoms
What derive() does
derive(key, compute) creates a normal Atom<T> whose value is produced by a pure compute function. The function receives a get helper; any atom read through get becomes a tracked dependency. When any dependency changes, the compute function re-runs and the derived atom's value updates automatically.
The returned atom is a full Atom<T> — you can subscribe to it with onChange, read .value, use it in React with useValue(derived), even chain it into another derive.
Basic example
Multiple sources
Conditional reads — dynamic dependency graph
The dependency set is re-evaluated on every run. Branches that are not taken on a given run do not create a subscription for that run:
When branch flips to "last", selected unsubscribes from firstName and subscribes to lastName. Memory-safe: no stale subscriptions accumulate.
Chaining derivations
A derived atom that reads another derived atom recomputes when either level changes:
Subscribing to a derived atom
Derived atoms are normal Atom<T> instances; all subscription APIs work:
Cleanup / destroying a derived atom
When you destroy() a derived atom, it automatically unsubscribes from all tracked dependencies. No manual cleanup is needed:
Signature reference
Key pitfalls
- Never write to a derived atom directly.
derivedAtom.update(x)works at runtime but the next dependency change will overwrite it. Use a regularcreateAtomif you need writable state. - Object return values always re-trigger because the compute function builds a new object reference every call. For primitives, the atom's
update()short-circuits on===equality — soderive("flag", get => get(a) > 0)will only notify subscribers when the boolean value actually changes. - Errors in compute are surfaced asynchronously via
queueMicrotask. The atom keeps its previous value on error. This prevents one broken derivation from crashing the source atom's update cycle — but errors may appear in the console later than expected. - Keys must be unique just like any atom key. Use a namespaced key:
"cart.totalPrice"not just"total". - Initial computation is eager.
derive(...)runs the compute function once immediately on creation. If a dependency atom doesn't exist yet at that moment, it will beundefined. Register all source atoms before their derived counterparts.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/derived-atoms/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hassanzohdy/atom/derived-atoms)