mcpField
O
opensrc

opensrc

github.com/third774Development691 installsUpdated 1d ago
Repository

About opensrc

opensrc is a CLI tool for developers and coding agents that fetches package or repository source code into a project, providing implementation context beyond interfaces. It detects installed npm versions and resolves repositories to matching tags.

Key features

  1. 01Fetch package and repository source
  2. 02Detect installed npm package versions
  3. 03Resolve repositories and matching tags
  4. 04List, update, and remove fetched sources
  5. 05Add source pointers to AGENTS.md

Use cases

  1. 01Inspect a dependency's internal implementation
  2. 02Debug issues that types alone cannot explain
  3. 03Explore implementation patterns in dependencies

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/third774/dotfiles --skill opensrc

After installing, type/opensrcin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
architecture.md
cli-usage.md
registry-support.md

Details

From the project README

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 [email protected]
npx opensrc owner/[email protected]

Commands

CommandDescription
opensrc <packages...>Fetch source for packages/repos
opensrc listList all fetched sources
opensrc remove <name>Remove specific source
opensrc cleanRemove 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 - adds opensrc/ to ignore list
  • tsconfig.json - excludes opensrc/ from compilation
  • AGENTS.md - adds section pointing agents to source code

Use --modify or --modify=false to skip prompt.

Key Behaviors

  1. Version Detection - For npm, auto-detects installed version from node_modules, package-lock.json, pnpm-lock.yaml, or yarn.lock
  2. Repository Resolution - Resolves package to its git repo via registry API, clones at matching tag
  3. Monorepo Support - Handles packages in monorepos via repository.directory field
  4. Shallow Clone - Uses --depth 1 for efficient cloning, removes .git after clone
  5. 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:

Comments

Markdown supported