skills/bun-guides-process-ipc/SKILL.md
Spawn a child process and communicate using IPC
npx skillsauth add jarle/bun-skills Bun Spawn a child process and communicate using IPCInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use Bun.spawn() to spawn a child process. When spawning a second bun process, you can open a direct inter-process communication (IPC) channel between the two processes.
const child = Bun.spawn(["bun", "child.ts"], {
ipc(message) {
/**
* The message received from the sub process
**/
},
});
The parent process can send messages to the subprocess using the .send() method on the returned Subprocess instance. A reference to the sending subprocess is also available as the second argument in the ipc handler.
const childProc = Bun.spawn(["bun", "child.ts"], {
ipc(message, childProc) {
/**
* The message received from the sub process
**/
childProc.send("Respond to child");
},
});
childProc.send("I am your father"); // The parent can send messages to the child as well
Meanwhile the child process can send messages to its parent using with process.send() and receive messages with process.on("message"). This is the same API used for child_process.fork() in Node.js.
process.send("Hello from child as string");
process.send({ message: "Hello from child as object" });
process.on("message", message => {
// print message from parent
console.log(message);
});
All messages are serialized using the JSC serialize API, which allows for the same set of transferrable types supported by postMessage and structuredClone, including strings, typed arrays, streams, and objects.
// send a string
process.send("Hello from child as string");
// send an object
process.send({ message: "Hello from child as object" });
See Docs > API > Child processes for complete documentation.
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling