Why Does a Leading Slash in Patterns Fail on Windows in ripgrep?

On Windows, a leading slash in ripgrep patterns fails because Cygwin and MSYS automatically convert POSIX-style paths, transforming your search pattern into a file system path before ripgrep ever sees it.

When using ripgrep (rg) from the BurntSushi/ripgrep repository on Windows, you may notice that search patterns starting with a forward slash return no matches. This behavior stems not from ripgrep's regex engine, but from the Cygwin or MSYS2 environment that intercepts and rewrites your arguments before they reach the tool.

The Root Cause: Cygwin Path Translation

According to the source code analysis of FAQ.md in the BurntSushi/ripgrep repository, the issue occurs in Cygwin's path-conversion logic. When a pattern starts with /, Cygwin assumes the argument is a POSIX file path and automatically translates it to a Windows-style path. For example, the pattern /foo becomes C:/msys64/foo before it reaches ripgrep.

This behavior is documented in the FAQ section "Why does using a leading / on Windows fail?" (lines 362-378) and traced to GitHub issue #1277. Because ripgrep receives a file system path instead of the intended literal regex pattern, the search never matches your target string.

How to Fix Leading Slash Pattern Failures

Escape the Leading Slash

The simplest workaround is to prefix your pattern with an additional slash. This prevents Cygwin from recognizing it as a path while still allowing ripgrep to search for the literal string.

rg //foo

This command searches for the literal pattern /foo rather than a file path.

Disable Automatic Path Conversion

You can disable Cygwin's path conversion entirely using the MSYS_NO_PATHCONV environment variable.

For a single command:

MSYS_NO_PATHCONV=1 rg /foo

For your entire shell session:

export MSYS_NO_PATHCONV=1
rg /foo

Avoid Cygwin Environments

The most reliable long-term solution is to run ripgrep from a native Windows terminal such as PowerShell, CMD, or Windows Terminal. These environments do not perform POSIX path translation, so patterns like /foo are passed directly to ripgrep as literal regular expressions.

Summary

  • The leading slash failure is caused by Cygwin/MSYS path conversion, not ripgrep itself
  • Cygwin transforms /foo into C:/msys64/foo before ripgrep processes the pattern
  • Escape the slash with //foo or set MSYS_NO_PATHCONV=1 to disable conversion
  • Running ripgrep from PowerShell or CMD avoids the issue entirely

Frequently Asked Questions

Is this a bug in ripgrep?

No. According to the FAQ.md source file and issue #1277, this is expected behavior from Cygwin and MSYS environments that automatically convert POSIX paths to Windows paths. Ripgrep receives the modified string and searches correctly for what it was given.

Does this affect all Windows users?

No. This issue only affects users running ripgrep from Cygwin, MSYS2, or Git Bash terminals. Users running ripgrep from PowerShell, CMD, or native Windows Terminal do not experience path translation and can use leading slashes without problems.

Why does escaping with a double slash work?

When you write //foo, Cygwin's path conversion logic does not recognize //foo as a valid POSIX absolute path, so it leaves the argument unchanged. Ripgrep then receives /foo as the intended regex pattern and performs the search correctly.

Can I use single quotes to prevent the conversion?

No. Single or double quotes do not prevent Cygwin's path conversion because this translation happens at the shell level before arguments are passed to ripgrep. Only the double-slash escape or the MSYS_NO_PATHCONV environment variable effectively bypass the conversion.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →