bedkillerspacex-boop/codex-skill-library/node-worker-threads-basics
Claude Code and agent skill by bedkillerspacex-boop/codex-skill-library
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Use Node.js worker_threads for CPU-bound work without blocking the event loop: Worker API, message passing, SharedArrayBuffer care, pooling, and memory leak avoidance. Use for owned Node services doing CPU-heavy tasks.
Install
npx vskill@latest install bedkillerspacex-boop/codex-skill-library/node-worker-threads-basicsSKILL.md
The same SKILL.md was published earlier as bedkillerspacex-boop/codex-skill-library/node-worker-threads-basics.
Node.js worker_threads Basics
Scope And Authorization
- In scope: Node applications you own.
- Out of scope: crypto-mining malware patterns; abusing shared hosts.
- Workers are not free — pool size ≈ CPU cores for pure CPU tasks.
- Pair with undici tuning for I/O; permission model for sandboxing.
When To Use
- CPU-heavy work (image resize, parse, crypto, compression) blocking event loop.
- Offloading from Express/Fastify request path.
- Replacing naive
child_processfor in-process parallelism with structured messaging. - Debugging growing memory with unbounded Worker creation.
Do Not Use As Primary
| Need | Skill instead | |
|---|---|---|
| HTTP client pooling | node-undici-agent-tuning | |
| Permission flags | nodejs-permission-model | |
| diagnostics_channel | nodejs-diagnostics-channel | |
| Implementation quality baseline | code-quality-standards |
Domain Focus
| API | Role | ||
|---|---|---|---|
| `new Worker(filename | url)` | Start worker | |
parentPort.postMessage | Send structured clone / transfer list | ||
worker.on('message') | Receive | ||
worker.terminate() | Stop | ||
isMainThread | Branch entry | ||
workerData | Init payload | ||
| Transferables | ArrayBuffer move ownership | ||
| Piscina / pool | Reuse workers |
Workflow
1. Identify CPU bottleneck
- I/O-bound work should stay async on main thread — workers won’t help much.
- Success: p95 latency drops; main thread lag reduced; memory stable.
2. Minimal worker
3. Prefer a pool
- Never
new Workerper request at high RPS without pool limits. - Queue overflow → 503 to caller rather than unbounded memory.
4. Message design
- Prefer structured clone of plain data; transfer large ArrayBuffers.
- Avoid circular objects; handle clone errors.
- Protocol:
{ id, type, payload }for multiplexed tasks on one worker.
5. SharedArrayBuffer / Atomics
- Only when needed; mind
crossOriginIsolatedfor browsers (N/A server). - Race bugs are easy — prefer message passing first.
- Document memory ordering assumptions.
6. Errors and teardown
- Unhandled worker exceptions kill worker — pool should respawn.
- On process shutdown: terminate pool gracefully.
7. Memory leak checklist
| Smell | Fix | |
|---|---|---|
| Workers per request | Pool | |
| Huge closures in workerData | Pass minimal data | |
| Listeners not removed | Once handlers / pool managed | |
| Unbounded result buffers | Stream/chunk | |
| Old Node worker bugs | Stay patched |
Good / Bad
| Topic | Good | Bad | |
|---|---|---|---|
| Creation | Pooled workers | new Worker every request | |
| Work type | CPU-bound | Wrapping simple fs.readFile | |
| Messages | Small JSON + transfer buffers | Clone multi-MB objects every ms | |
| Failures | Respawn + fail request | Hang promise forever | |
| Size | ~CPU count | 1000 threads on 4 CPUs |
Output Checklist
- [ ] Bottleneck is CPU not I/O
- [ ] Worker module isolated
- [ ] Pool with max threads + queue
- [ ] Message protocol defined
- [ ] Error/exit handled
- [ ] Shutdown terminates workers
- [ ] Memory stable under load test
- [ ] Main thread lag improved
- [ ]
code-quality-standardsapplied
Rules
- Bound worker count and queue depth.
- Do not block workers on async I/O meant for main thread patterns without reason.
- Owned services only.
- Measure before and after.
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 repositoryCheckingnode-worker-threads-basics/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/bedkillerspacex-boop/codex-skill-library/node-worker-threads-basics)