opensrc
opensrc
CLI tool to fetch source code for packages/repos, giving AI coding agents deeper implementation context.
When to Use
- Need to understand how a library/package works internally (not just its interface)
- Debugging issues where types alone are insufficient
- Exploring implementation patterns in dependencies
- Agent needs to reference actual source code of a package
Quick Start
# Install globally or use npx
npm install -g opensrc
# Fetch npm package (auto-detects installed version from lockfile)
npx opensrc zod
# Fetch from other registries
npx opensrc pypi:requests # Python/PyPI
npx opensrc crates:serde # Rust/crates.io
# Fetch GitHub repo directly
npx opensrc vercel/ai # owner/repo shorthand
npx opensrc github:owner/repo # explicit prefix
npx opensrc https://github.com/colinhacks/zod # full URL
# Fetch specific version/ref
npx opensrc zod@3.22.0
npx opensrc owner/repo@v1.0.0
Commands
| Command | Description |
|---|---|
opensrc <packages...> |
Fetch source for packages/repos |
opensrc list |
List all fetched sources |
opensrc remove <name> |
Remove specific source |
opensrc clean |
Remove all sources |
Output Structure
After fetching, sources stored in opensrc/ directory:
opensrc/
├── settings.json # User preferences
├── sources.json # Index of fetched packages/repos
└── repos/
└── github.com/
└── owner/
└── repo/ # Cloned source code
File Modifications
On first run, opensrc prompts to modify:
.gitignore- addsopensrc/to ignore listtsconfig.json- excludesopensrc/from compilationAGENTS.md- adds section pointing agents to source code
Use --modify or --modify=false to skip prompt.
Key Behaviors
- Version Detection - For npm, auto-detects installed version from
node_modules,package-lock.json,pnpm-lock.yaml, oryarn.lock - Repository Resolution - Resolves package to its git repo via registry API, clones at matching tag
- Monorepo Support - Handles packages in monorepos via
repository.directoryfield - Shallow Clone - Uses
--depth 1for efficient cloning, removes.gitafter clone - Tag Fallback - Tries
v{version},{version}, then default branch if tag not found
Common Workflows
Fetching a Package
# Agent needs to understand zod's implementation
npx opensrc zod
# → Detects version from lockfile
# → Finds repo URL from npm registry
# → Clones at matching git tag
# → Source available at opensrc/repos/github.com/colinhacks/zod/
Updating Sources
# Re-run same command to update to currently installed version
npx opensrc zod
# → Checks if version changed
# → Re-clones if needed
Multiple Sources
# Fetch multiple at once
npx opensrc react react-dom next
npx opensrc zod pypi:pydantic vercel/ai
References
For detailed information:
- CLI Usage & Options - Full command reference
- Architecture - Code structure and extension
- Registry Support - npm, PyPI, crates.io details
More from third774/dotfiles
natural-writing
Write like a human, not a language model. Avoid AI-tell vocabulary, formulaic structures, and hollow emphasis. Apply to ALL written output including prose, documentation, comments, and communication. Use when drafting prose, documentation, comments, or any written output that should sound human.
66agent-skills
Author and improve Agent Skills following the agentskills.io specification. Use when creating new SKILL.md files, modifying existing skills, reviewing skill quality, or organizing skill directories with proper naming, descriptions, and progressive disclosure.
31documenting-code-comments
Standards for writing self-documenting code and best practices for when to write (and avoid) code comments. Use when auditing, cleaning up, or improving inline code documentation.
28customizing-opencode
Configure OpenCode via opencode.json, agents, commands, MCP servers, custom tools, plugins, themes, keybinds, and permissions. Use when setting up or modifying OpenCode configuration.
23adversarial-code-review
Review code through hostile perspectives to find bugs, security issues, and unintended consequences the author missed. Use when reviewing PRs, auditing codebases, or before critical deployments.
21verification-before-completion
Run verification commands before claiming work is complete or fixed. Use before asserting any task is done, bug is fixed, tests pass, or feature works.
18