Opensrc
Fetch source code for npm packages to give AI coding agents deeper context
Last verified:
What is Opensrc?
opensrc is a CLI tool that gives AI coding agents access to any package's source code. It resolves packages from registry APIs, shallow-clones the source repository at the correct version tag, and caches it globally at ~/.opensrc/. Users can use opensrc path inside other commands to search, read, or explore implementations — not just types.
The tool supports multiple package registries including npm (default), PyPI (Python), crates.io (Rust), GitHub, GitLab, and Bitbucket. It automatically detects the installed version from lockfiles like package-lock.json, pnpm-lock.yaml, and yarn.lock for npm packages. The cached source matches the version in your project, not just the latest release.
opensrc is designed for AI coding agents, developers who need to understand internal library behavior, debug unexpected library issues, learn patterns from well-known implementations, or verify how functions handle edge cases. It works with any shell tool like rg, grep, cat, find, and ls by outputting the absolute path to stdout while progress goes to stderr.
Key features include global caching for instant subsequent access, AGENTS.md integration for AI agents, support for private repositories via environment variable authentication, and commands for listing, removing, and cleaning cached sources. The tool requires Node.js 18+ and Git for cloning repositories.
Opensrc pricing
Pricing model: Freemium
Free and open source. Install via npm install -g opensrc. No paid tiers, subscription, or licensing fees mentioned on the website.
Opensrc pros
- Gives AI coding agents access to actual source code, not just types
- Supports npm, PyPI, crates.io, GitHub, GitLab, and Bitbucket registries
- Automatically detects installed version from project lockfiles
- Global caching at ~/.opensrc/ for instant subsequent access
- Shallow clone (--depth 1) for fast, minimal checkout
- Works with any shell tool like rg, grep, cat, find, ls
- Path output to stdout, progress to stderr for clean subshell usage
- Supports private repositories via GITHUB_TOKEN, GITLAB_TOKEN, BITBUCKET_TOKEN
- Raised GitHub API rate limit from 60 to 5,000 requests/hour with token
- Commands for listing, removing, and cleaning cached sources
- Can fetch multiple packages at once in a single command
- Supports specific versions with @version syntax
- Supports fetching from specific branches/tags with #ref syntax
- OPENSRC_HOME environment variable overrides default cache location
- AGENTS.md integration designed for AI coding agent workflows
- Open source tool from Vercel Labs
Opensrc cons
- Requires Node.js 18+ as a dependency
- Requires Git installed for cloning repositories
- Only supports HTTPS cloning, not SSH
- Private repos require manual environment variable setup
- Fine-grained PAT needs specific Contents read scope
- No built-in GUI, purely CLI-based tool
- Cache must be manually cleaned with opensrc clean command
- No official Windows installation method mentioned
Frequently asked questions about Opensrc
What is opensrc?
opensrc is a CLI tool that gives coding agents access to any package's source code. It resolves packages from registry APIs, shallow-clones the source repository at the correct version tag, and caches it globally. Use opensrc path inside other commands to search, read, or explore implementations — not just types.
How do I install opensrc?
Install globally via npm: npm install -g opensrc. The tool requires Node.js 18+ and Git for cloning repositories.
Which package registries does opensrc support?
opensrc supports npm (default), PyPI (use pypi: prefix), crates.io (use crates: prefix), GitHub (owner/repo format), GitLab (use gitlab: prefix), and Bitbucket (use bitbucket: prefix).
How does version detection work?
For npm packages, opensrc checks in order: node_modules/<package>/package.json, package-lock.json, pnpm-lock.yaml, yarn.lock, then falls back to the latest tag. This ensures the cached source matches your project's version.
Where is source code cached?
All source is cached globally at ~/.opensrc/ with the structure ~/.opensrc/repos/github.com/owner/package/version/. The OPENSRC_HOME environment variable can override this location.
How do I authenticate with private repositories?
Set environment variables: GITHUB_TOKEN for GitHub, GITLAB_TOKEN for GitLab, BITBUCKET_TOKEN for Bitbucket. Tokens are read from the environment on each run and never persisted to disk.
How do I list cached packages?
Use opensrc list to show all cached packages and repositories, or opensrc list --json for JSON output.
How do I remove cached sources?
Use opensrc remove <package> to remove a specific package or repository. Use opensrc clean to remove everything, or filter with flags like --npm, --pypi, --crates, --packages, or --repos.
When should I fetch source code?
Fetch source when you need to understand internal behavior that types don't reveal, debug unexpected library behavior, learn patterns from well-known implementations, or verify how a function handles edge cases. Don't fetch for simple API usage questions that docs or types can answer.