---
id: gh-opensrc
name: "opensrc"
url: https://skills.yangsir.net/skill/gh-opensrc
author: vercel-labs
domain: ai-dev-tools-workflow
tags: ["source-code", "dependency", "cli", "cache", "code-reading"]
install_count: 2100
rating: 4.30 (120 reviews)
github: https://github.com/vercel-labs/opensrc/tree/main/skills/opensrc
---

# opensrc

> 此技能通过 opensrc 命令快速获取并缓存 npm/PyPI/crates.io 包或 GitHub 仓库的源代码，使 AI 智能体能够直接阅读依赖实现细节，而不仅限于类型与文档。适合调试库的意外行为、验证边界情况、学习知名项目的内部设计时使用，能显著提升上下文理解与问题定位效率。

**Stats**: 2,100 installs · 4.3/5 (120 reviews)

## Before / After 对比

### 定位并理解依赖源码的效率提升

**Before**:

开发者或 AI 智能体在排查库的异常行为时，需要手动搜索仓库、确认版本标签、下载源码并逐层打开文件，整个过程平均耗时约 60 分钟，且容易因版本不匹配而误判。

**After**:

此技能自动解析 lockfile 中的确切版本并缓存源码，只需一条命令即可获得正确的源码路径，使开发者能立即阅读实现逻辑，平均用时缩短至 10 分钟以内，调查效率显著提升。

| Metric | Before | After | Change |
|---|---|---|---|
| 平均定位与获取源码时间 | 60分钟 | 10分钟 | -83% |

## Readme

# 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.


---
*Source: https://skills.yangsir.net/skill/gh-opensrc*
*Markdown mirror: https://skills.yangsir.net/api/skill/gh-opensrc/markdown*