hassanzohdy/atom/derived
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, dynamic dep graphs, chaining, and React consumption.
Install
npx vskill@latest install hassanzohdy/atom/derivedSKILL.md
Derived atoms
derive(key, compute) creates a computed atom whose value is built from other atoms. Dependencies are tracked automatically: whichever atoms the compute function reads via its get argument become dependencies. When any of them change, the derived atom recomputes and notifies its own subscribers.
Signature
The returned atom is a normal Atom<T> — every consumer pattern from @mongez/react-atom (useValue, useState, use(key), useWatch, etc.) and from the core (onChange, watch, destroy) works on it.
Behavior
- Eager initial compute. The function runs once on creation to seed the value and discover the first set of dependencies.
- Eager recompute. When any tracked dependency changes (via
update/change/merge), the function runs again and the result is pushed through the atom's normalupdateflow — every subscriber re-renders. - Dynamic dependency graph. Conditional reads (
if (get(branch) === "a") return get(a); else return get(b);) work correctly. After each recompute the engine diffs the new dep set against the old one, unsubscribes from atoms no longer read, and subscribes to newly-seen ones. - Chaining propagates. A derived atom can be a dependency of another derived atom. Updates fan out through the chain.
- Error isolation. If
computethrows, the previous value is kept and the error is surfaced asynchronously (via a microtask re-throw) so the source atom's update cycle isn't broken. - Destroy unsubscribes deps.
derivedAtom.destroy()drops every dependency subscription before clearing the registry entry.
Examples
Simple
Filtered view
Cross-atom gate (the killer use case)
Conditional reads (dynamic dep graph)
Chained derivations
React consumption
Through @mongez/react-atom, derived atoms get the same hooks as any other atom:
For object-valued derived atoms, use(key) still works to scope subscription to one field.
Gotchas
- Don't write to derived atoms. Calling
update/merge/changeon the returned atom works, but the next dependency change will overwrite your write. If you need writable state, use a regular atom. - Don't depend on yourself. A derive that reads its own atom inside
computecreates an infinite loop. The engine doesn't detect cycles — keep dependency graphs acyclic. - Throws are asynchronous. Errors inside
computeare caught and re-thrown in a microtask so the upstream update cycle isn't broken. Catch them with aprocess.on("uncaughtException")handler or browserwindow.onerrorif you need to log them centrally.
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/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)