Codex CLI crashes with Error: spawn rg ENOENT when ripgrep isn’t installed

Resolved 💬 6 comments Opened Apr 16, 2025 by bjmoonn Closed Apr 16, 2025
💡 Likely answer: A maintainer (tibo-openai, collaborator) responded on this thread — see the highlighted reply below.

When running codex without having rg (ripgrep) on the PATH, the CLI throws an unhandled “spawn rg ENOENT” error and exits.

Ensure ripgrep is not installed or not in your $PATH.

node:events:502
      throw er; // Unhandled 'error' event
      ^

Error: spawn rg ENOENT
    at ChildProcess._handle.onexit (…)
    …
    code: 'ENOENT',
    syscall: 'spawn rg',
    path: 'rg',
    spawnargs: [ '--files' ]
}

The CLI should detect if rg is unavailable and either:

  • Fall back to a bundled file-walk implementation, or
  • Emit a user-friendly error asking to install ripgrep (e.g. “Please install ripgrep (https://github.com/BurntSushi/ripgrep) and ensure rg is on your PATH.”)

View original on GitHub ↗

6 Comments

donutdan4114 · 1 year ago

After installing ripgrep, still running into an issue when it tries to execute the command.
Maybe related to having pipe in the command?

Repo command: codex "how many files in this codebase?" -m gpt-4o

╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│Shell Command                                                                                                                                                       │
│                                                                                                                                                                    │
│$ 'rg --files | wc -l'                                                                                                                                              │
│                                                                                                                                                                    │
│Allow command?                                                                                                                                                      │
│                                                                                                                                                                    │
│  ❯ Yes (y) ✔                                                                                                                                                       │
│    Yes, always approve this exact command for this session (a)                                                                                                     │
│    Edit or give feedback (e)                                                                                                                                       │
│    No, and keep going (n)                                                                                                                                          │
│    No, and stop for now (esc)                                                                                                                                      │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
node:events:485
      throw er; // Unhandled 'error' event
      ^

Error: spawn rg --files | wc -l ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn rg --files | wc -l',
  path: 'rg --files | wc -l',
  spawnargs: []
}

Node.js v23.6.1

Possibly related to https://github.com/openai/codex/issues/45

tibo-openai collaborator · 1 year ago

Issue of hard requirement on rg should be fixed in
https://github.com/openai/codex/pull/50

kelin1003 · 1 year ago

Running into same issue. Even after installing rg it keeps failing with same error.

kelin1003 · 1 year ago

Works when using

codex -m o4-mini-2025-04-16
korzen · 1 year ago

Same problem on Windows...

tibo-openai collaborator · 1 year ago

We removed the rg requirement in https://github.com/openai/codex/pull/50 and re-released.