Skip to content

Context7 Platform -- Up-to-date docs for AI agents

fix(cli): recover library ID mangled by Git Bash on Windows (#2733)

Fahreddin Özcan428af3e06753
diff --git a/.changeset/git-bash-library-id.md b/.changeset/git-bash-library-id.md
new file mode 100644
index 00000000..0a185cd0
--- /dev/null
+++ b/.changeset/git-bash-library-id.md
@@ -0,0 +1,5 @@
+---
+"ctx7": patch
+---
+
+Recover Context7 library IDs that Git Bash mangles on Windows. Git Bash rewrites a leading-slash argument like `/facebook/react` into a Windows path under the Git install dir (`C:/Program Files/Git/facebook/react`), causing `ctx7 docs` to reject it as invalid; this mainly affected users running ctx7 through Claude Code. The CLI now detects and undoes the conversion before validation, accepts the `//owner/repo` escape, and points users at that workaround for install layouts it can't auto-detect.
diff --git a/packages/cli/src/__tests__/library-id.test.ts b/packages/cli/src/__tests__/library-id.test.ts
new file mode 100644
index 00000000..13f75d2e
--- /dev/null
+++ b/packages/cli/src/__tests__/library-id.test.ts
@@ -0,0 +1,44 @@
+import { describe, expect, test } from "vitest";
+
+import { recoverLibraryId } from "../utils/library-id.js";
+
+describe("recoverLibraryId", () => {
+ test("passes through a normal library ID unchanged", () => {
+ expect(recoverLibraryId("/facebook/react")).toBe("/facebook/react");
+ expect(recoverLibraryId("/vercel/next.js/v15.1.8")).toBe("/vercel/next.js/v15.1.8");
+ });
+
+ test("recovers a Git Bash mangled path (default install dir)", () => {
+ expect(recoverLibraryId("C:/Program Files/Git/facebook/react")).toBe("/facebook/react");
+ });
+
+ test("recovers a mangled path with backslashes", () => {
+ expect(recoverLibraryId("C:\\Program Files\\Git\\facebook\\react")).toBe("/facebook/react");
+ });
+
+ test("preserves a version segment", () => {
+ expect(recoverLibraryId("C:/Program Files/Git/vercel/next.js/v15.1.8")).toBe(
+ "/vercel/next.js/v15.1.8"
+ );
+ });
+
+ test("recovers from a portable Git install", () => {
+ expect(recoverLibraryId("D:/tools/PortableGit/facebook/react")).toBe("/facebook/react");
+ });
+
+ test("recovers an owner that looks like a system dir", () => {
+ expect(recoverLibraryId("C:/Program Files/Git/usr/some-repo")).toBe("/usr/some-repo");
+ });
+
+ test("collapses the leading double-slash workaround", () => {
+ expect(recoverLibraryId("//facebook/react")).toBe("/facebook/react");
+ });
+
+ test("leaves a non-Windows-path argument untouched", () => {
+ expect(recoverLibraryId("facebook/react")).toBe("facebook/react");
+ });
+
+ test("leaves an unrecognized Windows path untouched", () => {
+ expect(recoverLibraryId("C:/Users/me/project")).toBe("C:/Users/me/project");
+ });
+});
diff --git a/packages/cli/src/commands/docs.ts b/packages/cli/src/commands/docs.ts
index aeed4a22..a7f6d4c3 100644
--- a/packages/cli/src/commands/docs.ts
+++ b/packages/cli/src/commands/docs.ts
@@ -3,6 +3,7 @@ import pc from "picocolors";
import ora from "ora";
import { resolveLibrary, getLibraryContext } from "../utils/api.js";
+import { recoverLibraryId } from "../utils/library-id.js";
import { log } from "../utils/logger.js";
import { trackEvent } from "../utils/tracking.js";
import { loadTokens, isTokenExpired } from "../utils/auth.js";
@@ -120,10 +121,18 @@ async function queryCommand(
): Promise<void> {
trackEvent("command", { name: "docs" });
+ // Git Bash on Windows rewrites "/owner/repo" into a Windows path; recover it.
+ libraryId = recoverLibraryId(libraryId);
+
if (!libraryId.startsWith("/") || !/^\/[^/]+\/[^/]/.test(libraryId)) {
log.error(`Invalid library ID: "${libraryId}"`);
log.info(`Expected format: /owner/repo or /owner/repo/version (e.g., /facebook/react)`);
log.info(`Run "ctx7 library <name>" to find the correct ID`);
+ if (process.platform === "win32") {
+ log.info(
+ `On Git Bash, prefix the ID with an extra slash to avoid path conversion: ctx7 docs "//facebook/react" "<your question>"`
+ );
+ }
process.exitCode = 1;
return;
}
diff --git a/packages/cli/src/utils/library-id.ts b/packages/cli/src/utils/library-id.ts
new file mode 100644
index 00000000..f189d748
--- /dev/null
+++ b/packages/cli/src/utils/library-id.ts
@@ -0,0 +1,22 @@
+/**
+ * Recover a library ID that Git Bash mangled on Windows.
+ *
+ * Git Bash rewrites a leading-slash argument like "/facebook/react" into a
+ * Windows path under the Git install dir, e.g. "C:/Program Files/Git/facebook/react".
+ * We undo that so the "/owner/repo" format still works.
+ */
+export function recoverLibraryId(input: string): string {
+ // "//owner/repo" is the Git Bash escape that skips conversion; collapse it.
+ if (input.startsWith("//")) return input.replace(/^\/+/, "/");
+
+ // Normal library ID, nothing to recover.
+ if (input.startsWith("/")) return input;
+
+ // Only a drive-letter path (e.g. "C:/...") can be a mangled ID.
+ if (!/^[A-Za-z]:[\\/]/.test(input)) return input;
+
+ // Strip the Git install dir, keeping the "/owner/repo[/version]" tail.
+ const normalized = input.replace(/\\/g, "/");
+ const match = normalized.match(/^[A-Za-z]:\/.*?\/(?:Git|PortableGit|git-bash)\/(.+)$/i);
+ return match ? `/${match[1]}` : input;
+}