> ## Documentation Index
> Fetch the complete documentation index at: https://bun.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://bun.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://bun.manicule.dev/api/mcp.
> Every agent surface: https://bun.manicule.dev/.well-known/llms-manifest.json

# Parse command-line arguments (/guides/process/argv)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 282 · updated: 2026-08-02 -->
Related: [Listen for CTRL+C](/guides/process/ctrl-c.md), [Spawn a child process and communicate using IPC](/guides/process/ipc.md), [Get the process uptime in nanoseconds](/guides/process/nanoseconds.md), [Listen to OS signals](/guides/process/os-signals.md), [Read stderr from a child process](/guides/process/spawn-stderr.md), [Read stdout from a child process](/guides/process/spawn-stdout.md)

The *argument vector* is the list of arguments passed to the program when it is run. It is available as `Bun.argv`.

```ts icon="/icons/typescript.svg" title="cli.ts"
console.log(Bun.argv);
```

***

Running this file with arguments results in the following:

```sh icon="terminal" title="terminal" terminal
bun run cli.ts --flag1 --flag2 value
```

```txt
[ "/path/to/bun", "/path/to/cli.ts", "--flag1", "--flag2", "value" ]
```

***

To parse `argv` into a more useful format, use `util.parseArgs`.

```ts icon="/icons/typescript.svg" title="cli.ts"
import { parseArgs } from "util";

const { values, positionals } = parseArgs({
  args: Bun.argv,
  options: {
    flag1: {
      type: "boolean",
    },
    flag2: {
      type: "string",
    },
  },
  strict: true,
  allowPositionals: true,
});

console.log(values);
console.log(positionals);
```

***

Running `cli.ts` with the same arguments prints the parsed values.

```sh icon="terminal" title="terminal" terminal
bun run cli.ts --flag1 --flag2 value
```

```txt
[Object: null prototype] {
  flag1: true,
  flag2: "value",
}
[ "/path/to/bun", "/path/to/cli.ts" ]
```
