# Bun Spawn a child process

> Spawn a child process

- Skill: `jarle/bun-spawn-a-child-process` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jarle/bun-spawn-a-child-process`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jarle/bun-spawn-a-child-process/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jarle (https://skillmd.com/u/jarle)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/jarle/bun-spawn-a-child-process

---


# Spawn a child process

Use [`Bun.spawn()`](/runtime/child-process) to spawn a child process.

```ts  theme={"theme":{"light":"github-light","dark":"dracula"}}
const proc = Bun.spawn(["echo", "hello"]);

// await completion
await proc.exited;
```

***

The second argument accepts a configuration object.

```ts  theme={"theme":{"light":"github-light","dark":"dracula"}}
const proc = Bun.spawn(["echo", "Hello, world!"], {
  cwd: "/tmp",
  env: { FOO: "bar" },
  onExit(proc, exitCode, signalCode, error) {
    // exit handler
  },
});
```

***

By default, the `stdout` of the child process can be consumed as a `ReadableStream` using `proc.stdout`.

```ts  theme={"theme":{"light":"github-light","dark":"dracula"}}
const proc = Bun.spawn(["echo", "hello"]);

const output = await proc.stdout.text();
output; // => "hello\n"
```

***

See [Docs > API > Child processes](/runtime/child-process) for complete documentation.

