Logo Vincent
Back to all posts

Claude Code /add-dir: The Monorepo Command You Miss

Claude
Claude Code /add-dir: The Monorepo Command You Miss

What is /add-dir

When using Claude Code, you might run into situations like these:

  • You’re working in Project A but need to reference code from Project B
  • You started Claude Code in a monorepo sub-package but need to check another sub-package’s implementation
  • You want Claude Code to understand both your frontend and backend repos to help with integration

By default, Claude Code can only see files under your current working directory. Whichever directory you launch it from, that’s all it knows.

This is where the /add-dir command comes in.

/add-dir is a Claude Code slash command that lets you add extra directories to Claude Code’s workspace during a conversation, allowing it to read and operate on files in those directories.

In short: break down directory walls and let Claude Code see more code.

Two Ways to Use It

/add-dir comes in two flavors: add directories on the fly during a conversation, or specify them upfront at launch.

Option 1: Add in Interactive Mode (/add-dir)

In Claude Code’s interactive mode, type:

/add-dir /path/to/another/project

Once executed, Claude Code gains access to all files in that directory. You can ask it to read, search, and even edit code there.

Each /add-dir call adds one directory. To add multiple, run it multiple times:

/add-dir /path/to/frontend
/add-dir /path/to/backend
/add-dir /path/to/shared-libs

Option 2: Specify at Launch (—add-dir)

If you already know which extra directories you’ll need before starting Claude Code, use the --add-dir flag to specify them all at once:

claude --add-dir ../apps ../lib

Note the difference from interactive mode — --add-dir lets you specify multiple directories at once, separated by spaces. Each path is validated to ensure it exists and is a directory.

This approach works great when you have a fixed set of projects you always work with together.

Using Relative Paths

Both methods support relative paths:

# Interactive mode
/add-dir ../another-project

# At launch
claude --add-dir ../apps ../../shared/components

Paths are resolved relative to the current working directory.

When You Need It

Scenario 1: Cross-Package Work in a Monorepo

This is the most common scenario. Say you have a monorepo structured like this:

my-monorepo/
├── packages/
│   ├── frontend/
│   ├── backend/
│   └── shared/

You started Claude Code in packages/frontend/. Now you want it to check a utility function in the shared package and use it in the frontend project.

/add-dir ../shared

Now Claude Code can see both the frontend and shared package code, helping you write correct import paths and function calls.

Scenario 2: Frontend-Backend Integration

You’re working in a frontend project but need to know the backend API’s request and response formats:

/add-dir /Users/me/projects/my-backend

Now you can ask Claude Code: “What format does the /api/users endpoint return? Generate a matching TypeScript type definition.”

It will find the API definition in the backend directory, then generate the type file in your frontend project.

Scenario 3: Referencing Open Source Projects

Want to reference how an open source project implements something? Add it in:

/add-dir ~/projects/reference-project

Then you can say: “Look at how this project implements routing, and let’s follow the same approach in ours.”

Scenario 4: Shared Configs and Documentation

Many teams keep shared configs, design specs, and API docs in separate repos:

/add-dir ~/team/design-system
/add-dir ~/team/api-docs

Once added, Claude Code can write code based on these specs, ensuring consistency.

Practical Tips

Tip 1: Only Add What You Need

Don’t add your entire disk. The more directories you add, the larger the search scope for Claude Code, which can affect efficiency. Only add directories that your current task actually needs.

Tip 2: Be Specific About Sources

When working with multiple directories, specify which project you’re referring to:

Look at the formatDate function in the shared package, then call it in the frontend project

Instead of vaguely saying “check formatDate” — there might be identically named files or functions across directories, and being specific avoids confusion.

Tip 3: Monorepo Best Practices

If you frequently work in a monorepo, the best approach is to start Claude Code from the monorepo root rather than inside a sub-package. This way Claude Code naturally sees all sub-packages without extra /add-dir calls.

But if your monorepo is massive — dozens or hundreds of packages — launching from the root might be too noisy. In that case, starting in a sub-package and selectively /add-dir-ing other packages is more efficient.

Tip 4: Create Aliases with —add-dir

If you switch between the same set of projects every day, create a shell alias:

alias claude-fullstack="claude --add-dir ../backend ../shared"

Now just type claude-fullstack in your frontend directory, and it automatically includes the backend and shared libs. Much easier than manually /add-dir-ing every time.

Tip 5: Pair with CLAUDE.md

If you frequently need to add a specific external directory, mention its purpose and path in your CLAUDE.md. While CLAUDE.md can’t automatically add directories, it helps Claude Code better understand what the added directories are for.

/add-dir vs —add-dir vs Launching from Root

/add-dir (Interactive)—add-dir (CLI Flag)Launch from Root
TimingAdd anytime during conversationSpecify all at launchNo extra action needed
Multiple dirsOne at a time, run multiple timesSpecify multiple at onceNaturally includes all subdirs
FlexibilityHighest, add on demandMedium, requires planningFixed workspace
Best forAd-hoc cross-project needsFixed multi-project setupsSmall to medium monorepos

My recommendations:

  • Small to medium monorepos → Launch from root, keep it simple
  • Large monorepos → Launch in a sub-package, use claude --add-dir for the packages you need
  • Cross-repo work → Launch in the main repo, /add-dir other repos as needed
  • Fixed project combos → Create a shell alias with --add-dir, one command and done

Final Thoughts

/add-dir is an unassuming command that can be a lifesaver when you need it. The problem it solves is straightforward: freeing Claude Code’s vision from a single directory.

Real-world development rarely stays in one directory. Frontend-backend separation, monorepo multi-package setups, shared library dependencies — in these scenarios, Claude Code seeing only one directory is far from enough.

Next time you find yourself thinking “if only Claude Code could see that other project,” give /add-dir a try. Open another window for it.

© 2026 vincentqiao.com . All rights reserved.