---
name: obtener-codigo-fuente-dependencias
description: Descarga y almacena en caché el código fuente de paquetes npm, PyPI y crates.io para que los agentes de IA puedan explorar implementaciones internas más allá de los tipos y la documentación. Resuelve versiones automáticamente desde los lockfiles del proyecto.
allowed-tools: Bash(opensrc:*)
license: Apache-2.0
metadata:
  id: 5f41971d
  slug: obtener-codigo-fuente-dependencias
  titulo: "Obtener Código Fuente de Dependencias"
  servicio: IA-Ingenieria-MLOps
  categoria_recurso: Automatizacion
  tipo: sistema
  nivel: avanzado
  idioma: es
  idioma_original: en
  acceso: gratis
  precio_eur: 0
  plataformas: [npm, PyPI, crates.io, GitHub]
  dependencias: [opensrc CLI]
  licencia: { spdx: Apache-2.0, redistribuible: true, uso_comercial: true }
  fuente:
    repo: mxyhi/ok-skills
    url: https://github.com/mxyhi/ok-skills/tree/main/opensrc
    commit: ee29738
    autor: mxyhi
    nombre_original: opensrc
    duplicados_en: []
  seguridad: { veredicto: seguro, riesgo: bajo, escaneado: "2026-06-14", motor: "grep-estatico+auditor-llm" }
  ficha:
    que_hace: "Descarga el código fuente de cualquier dependencia (npm, PyPI, crates.io o repositorio GitHub) y lo almacena en caché para inspección directa."
    como_lo_hace: "Usa el CLI `opensrc path <paquete>` para clonar el repositorio en la versión correcta y devolver la ruta local, integrándose en subshells de Bash para búsqueda y lectura de archivos."
  content_hash: "5f41971d53a558b5b0840ba3da05950f72c976d265a50511b1addfcc0144c338"
  version: 1.0.0
---

# Source Code Fetching with opensrc

Fetches dependency source code so agents can read implementations, not just types. Clones repositories at the correct version tag and caches them globally at `~/.opensrc/`.

## Core Pattern

```bash
rg "parse" $(opensrc path zod)
cat $(opensrc path zod)/src/types.ts
find $(opensrc path zod) -name "*.test.ts"
```

`opensrc path <pkg>` prints the absolute path to cached source. If not cached, it fetches automatically. Progress goes to stderr, path to stdout, so `$(opensrc path ...)` works in subshells.

## Fetching Source Code

```bash
opensrc path zod
opensrc path pypi:requests
opensrc path crates:serde
opensrc path facebook/react

# Multiple packages at once
opensrc path zod react next
opensrc path pypi:requests pypi:flask
opensrc path crates:serde crates:tokio

# Specific versions
opensrc path zod@3.22.0
opensrc path pypi:flask@3.0.0
opensrc path owner/repo@v1.0.0
opensrc path owner/repo#main
```

### Version Resolution

For npm packages, opensrc auto-detects the installed version from lockfiles (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`). Use `--cwd` to resolve from a different project:

```bash
opensrc path zod --cwd /path/to/project
```

For PyPI and crates.io, explicit versions or latest are used. For repos, use `@ref` or `#ref` to pin a branch, tag, or commit.

## Managing the Cache

Source is cached globally at `~/.opensrc/` (override with `OPENSRC_HOME`).

```bash
opensrc list                     # show all cached sources
opensrc list --json              # JSON output

opensrc remove zod               # remove a package
opensrc remove facebook/react    # remove a repo

opensrc clean                    # remove everything
opensrc clean --npm              # only npm packages
opensrc clean --pypi             # only PyPI packages
opensrc clean --crates           # only crates.io packages
opensrc clean --packages         # all packages, keep repos
opensrc clean --repos            # all repos, keep packages
```

## When to Fetch Source

Fetch source when you need to:
- Understand internal behavior that types don't reveal
- Debug unexpected library behavior
- Learn patterns from well-known implementations
- Verify how a function handles edge cases

Don't fetch source for simple API usage questions that docs or types can answer.
