Skip to main content
skill CX Codex

link-workspace-packages — Claude Code skill: link monorepo packages

This skill wires dependencies between packages in a monorepo using the workspace commands of npm, yarn, pnpm or bun. Handy when an import from a sibling package fails to resolve.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add nrwl/nx-ai-agents-config --skill link-workspace-packages -a claude-code
Open on GitHub

What link-workspace-packages does

The skill figures out which package manager your repo uses and adds the dependency the way that manager expects. Detection runs on the packageManager field in the root package.json or on the lockfile: pnpm-lock.yaml, yarn.lock, bun.lock, package-lock.json.

Then it identifies the consumer package and the provider package, writes the dependency, and checks that a symlink shows up in the consumer's node_modules/. pnpm and yarn go through the workspace: protocol, npm skips it and links workspace packages on its own, and bun accepts the same workspace: syntax as pnpm.

The skill tells you not to paper over the problem with paths in tsconfig or hand-edited package.json — fix the linking with the manager's own commands. Keep hoisting in mind too, because it differs: npm and bun lift shared deps to the root node_modules, pnpm hoists nothing, and yarn berry defaults to Plug'n'Play with no node_modules at all. If resolution errors survive the new dependency, that is a reason to check the root package.json carries "private": true.

What it helps with

  • link a freshly generated package to the one importing it
  • add a sibling package as a dependency after the import is written
  • fix cannot find module for an @org/* workspace package
  • deal with TS2307 and failed to resolve import in a monorepo
  • pick the right linking syntax for each package manager

Example prompts for the agent

  • I'm importing @org/ui in @org/app, add it as a dependency
  • @org/data-access won't resolve, TS2307 — fix the linking
  • I created a new package under packages/, wire it up to the app

How to install link-workspace-packages

1Skills CLI (Vercel)

npx skills add nrwl/nx-ai-agents-config --skill link-workspace-packages -a claude-code

2Manually: put the files in place

~/.claude/skills/link-workspace-packages/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/link-workspace-packages/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about link-workspace-packages

How do I install link-workspace-packages in Claude?

Run npx skills add nrwl/nx-ai-agents-config --skill link-workspace-packages -a claude-code. The skill lands at ~/.claude/skills/link-workspace-packages/SKILL.md.

What does link-workspace-packages do?

It adds dependencies between monorepo packages through the package manager's workspace commands and verifies the symlinks appear in the consumer's node_modules/.

How is linking different in pnpm and npm?

pnpm needs the explicit workspace: protocol and hoists nothing, while npm links workspace packages itself and writes * as the version in package.json.

Source text

SKILL.md · MIT
---
name: link-workspace-packages
description: 'Link workspace packages in monorepos (npm, yarn, pnpm, bun). USE WHEN: (1) you just created or generated new packages and need to wire up their dependencies, (2) user imports from a sibling package and needs to add it as a dependency, (3) you get resolution errors for workspace packages (@org/*) like "cannot find module", "failed to resolve import", "TS2307", or "cannot resolve". DO NOT patch around with tsconfig paths or manual package.json edits - use the package manager''s workspace commands to fix actual linking.'
---

# Link Workspace Packages

Add dependencies between packages in a monorepo. All package managers support workspaces but with different syntax.

## Detect Package Manager

Check whether there's a `packageManager` field in the root-level `package.json`.

Alternatively check lockfile in repo root:

- `pnpm-lock.yaml` → pnpm
- `yarn.lock` → yarn
- `bun.lock` / `bun.lockb` → bun
- `package-lock.json` → npm

## Workflow

1. Identify consumer package (the one importing)
2. Identify provider package(s) (being imported)
3. Add dependency using package manager's workspace syntax
4. Verify symlinks created in consumer's `node_modules/`

---

## pnpm

Uses `workspace:` protocol - symlinks only created when explicitly declared.

```bash
# From consumer directory
pnpm add @org/ui --workspace

# Or with --filter from anywhere
pnpm add @org/ui --filter @org/app --workspace
```

Result in `package.json`:

```json
{ "dependencies": { "@org/ui": "workspace:*" } }
```

---

## yarn (v2+/berry)

Also uses `workspace:` protocol.

```bash
yarn workspace @org/app add @org/ui
```

Result in `package.json`:

```json
{ "dependencies": { "@org/ui": "workspace:^" } }
```

---

## npm

No `workspace:` protocol. npm auto-symlinks workspace packages.

```bash
npm install @org/ui --workspace @org/app
```

Result in `package.json`:

```json
{ "dependencies": { "@org/ui": "*" } }
```

npm resolves to local workspace automatically during install.

---

## bun

Supports `workspace:` protocol (pnpm-compatible).

```bash
cd packages/app && bun add @org/ui
```

Result in `package.json`:

```json
{ "dependencies": { "@org/ui": "workspace:*" } }
```

---

## Examples

**Example 1: pnpm - link ui lib to app**

```bash
pnpm add @org/ui --filter @org/app --workspace
```

**Example 2: npm - link multiple packages**

```bash
npm install @org/data-access @org/ui --workspace @org/dashboard
```

**Example 3: Debug "Cannot find module"**

1. Check if dependency is declared in consumer's `package.json`
2. If not, add it using appropriate command above
3. Run install (`pnpm install`, `npm install`, etc.)

## Notes

- Symlinks appear in `<consumer>/node_modules/@org/<package>`
- **Hoisting differs by manager:**
  - npm/bun: hoist shared deps to root `node_modules`
  - pnpm: no hoisting (strict isolation, prevents phantom deps)
  - yarn berry: uses Plug'n'Play by default (no `node_modules`)
- Root `package.json` should have `"private": true` to prevent accidental publish

© nrwl · MIT · nrwl/nx-ai-agents-config

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set6

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor