upstash/context7 · warning

Library has been redirected

Error message

Library has been redirected

What it means

The library-context lookup returned ctx.error together with a redirectUrl: the requested library ID has been renamed/migrated upstream. The spinner branch (spinner?.warn, line 158) prints the notice, the CLI then shows the new ID and a ready-to-copy `ctx7 docs <newId> <query>` command, sets process.exitCode=1, and stops without fetching docs.

Source

Thrown at packages/cli/src/commands/docs.ts:158

    result = await getLibraryContext(libraryId, query, { type: outputType }, accessToken);
  } catch (err) {
    spinner?.fail(`Error: ${err instanceof Error ? err.message : String(err)}`);
    if (!spinner) log.error(err instanceof Error ? err.message : String(err));
    process.exitCode = 1;
    return;
  }

  if (typeof result === "string") {
    spinner?.stop();
    console.log(result);
    return;
  }

  const ctx = result as ContextResponse;

  if (ctx.error) {
    if (ctx.redirectUrl) {
      spinner?.warn("Library has been redirected");
      if (!spinner) log.warn("Library has been redirected");
      log.info(`New ID: ${pc.cyan(ctx.redirectUrl)}`);
      log.info(`Run: ${pc.cyan(`ctx7 docs "${ctx.redirectUrl}" "${query}"`)}`);
      process.exitCode = 1;
      return;
    }

    spinner?.fail(ctx.message || ctx.error);
    if (!spinner) log.error(ctx.message || ctx.error);
    process.exitCode = 1;
    return;
  }

  const total = (ctx.codeSnippets?.length || 0) + (ctx.infoSnippets?.length || 0);
  if (total === 0) {
    spinner?.warn(`No documentation found for: "${query}"`);
    if (!spinner) log.warn(`No documentation found for: "${query}"`);
    return;

View on GitHub (pinned to 5284672feb)

Solutions

  1. Re-run using the new ID printed on the 'New ID:' line
  2. Resolve the canonical ID fresh with `context7 docs "<name>" search` and use that
  3. Update any scripts/configs that hardcode the old library ID

Example fix

# before
ctx7 docs "/old-org/old-lib" "hooks"   # → Library has been redirected

# after — use the printed New ID
ctx7 docs "/new-org/new-lib" "hooks"
Defensive patterns

Strategy: type-guard

Validate before calling

// resolve the canonical ID right before fetching docs
const search = await searchLibraries(library, token);
if (search.results?.length) library = search.results[0].id; // fresh canonical ID

Type guard

function isRedirect(ctx: { error?: string; redirectUrl?: string }): ctx is { error: string; redirectUrl: string } {
  return !!ctx.error && typeof ctx.redirectUrl === "string" && ctx.redirectUrl.length > 0;
}

Prevention

When it happens

Trigger: Requesting docs for an outdated library ID after the registry consolidated/moved it (package rename, org transfer, docs merge); hit when re-running old commands or using IDs saved earlier from search results.

Common situations: Stale IDs in shell history, scripts, or notes; libraries that renamed upstream; consolidated documentation pages replacing several old IDs.

Related errors


AI-assisted analysis of upstash/context7@5284672feb (2026-08-18). Data as JSON: /api/errors/f606a75e6f29bdd8. Report an issue: GitHub.