/working-in-monorepos:working-in-monoreposfrom working-in-monorepos
Ensures commands execute from correct directories in monorepos using absolute paths. Prevents directory confusion and redundant cd commands when working across multiple subprojects.
Ships in working-in-monorepos. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Helps Claude work effectively in monorepo environments by ensuring commands always execute from the correct location using absolute paths.
Core principle: Bash shell state is not guaranteed between commands. Always use absolute paths.
Use this skill when:
Don't use for:
Run each command in a monorepo subproject with an absolute cd prefix:
✅ CORRECT:
cd /Users/josh/workspace/schemaflow/ruby && bundle exec rspec
cd /Users/josh/workspace/schemaflow/cli && npm test
❌ WRONG:
# Relative paths (assumes current directory)
cd ruby && bundle exec rspec
# No cd prefix (assumes location)
bundle exec rspec
# Chaining cd (compounds errors)
cd ruby && cd ruby && rspec
Why: You cannot rely on shell state. Absolute paths guarantee correct execution location regardless of where the shell currently is.
If .monorepo.json exists at repo root:
root field for absolute repo pathpath from subprojects mapcd {root}/{path} && commandExample:
{
"root": "/Users/josh/workspace/schemaflow",
"subprojects": { "ruby": { "path": "ruby" } }
}
→ cd /Users/josh/workspace/schemaflow/ruby && bundle exec rspec
Use git to find repo root, then construct absolute path:
git rev-parse --show-toplevelcd /absolute/path/to/repo/ruby && bundle exec rspecExample workflow:
# Step 1: Get repo root
git rev-parse --show-toplevel
# Output: /Users/josh/workspace/schemaflow
# Step 2: Use absolute path in commands
cd /Users/josh/workspace/schemaflow/ruby && bundle exec rspec
Why not use command substitution: cd $(git rev-parse --show-toplevel)/ruby requires user approval. Instead, run git rev-parse once, then use the absolute path directly in all subsequent commands.
⚠️ Git subtree caveat: In repositories containing git subtrees (nested git repos), git rev-parse --show-toplevel returns the innermost repo root, not the monorepo root. This makes it unreliable for subtree scenarios. Creating a .monorepo.json config is the robust solution that works in all cases.
When the repo looks like a monorepo but has no .monorepo.json, offer to generate one with scripts/monorepo-init. If the user agrees, run it with --dry-run, show the output, and run it with --write once they approve. If not, get the repo root once with git rev-parse and use absolute paths. They can also write .monorepo.json by hand from the schema below.
Script location: scripts/monorepo-init in this skill's base directory. Call it by absolute path so it works from any directory. --help documents every flag, so there's no need to read the source.
If .monorepo.json defines command rules:
{
"commands": {
"rubocop": { "location": "root" },
"rspec": {
"location": "subproject",
"command": "bundle exec rspec",
"overrides": { "root": { "command": "bin/rspec" } }
}
}
}
Check rules before executing:
commands maplocation: "root" | "subproject"command overrideoverridesExample:
bundle exec rspecbin/rspec| Task | Command Pattern |
|---|---|
| Get repo root | git rev-parse --show-toplevel (run once, use result in all commands) |
| Run tests in subproject | cd /absolute/path/to/repo/subproject && test-command |
| With config | cd {root}/{subproject.path} && command |
| Check for config | test -f .monorepo.json |
| Generate config | <skill-dir>/scripts/monorepo-init --dry-run (works from any directory) |
| Always rule | Absolute path and cd prefix on each command. Get the repo root once, then use it directly. |
.monorepo.json at repository root:
{
"root": "/absolute/path/to/repo",
"subprojects": {
"subproject-id": {
"path": "relative/path",
"type": "ruby|node|go|python|rust|java",
"description": "Optional"
}
},
"commands": {
"command-name": {
"location": "root|subproject",
"command": "optional override",
"overrides": {
"context": { "command": "context-specific" }
}
}
}
}
Minimal example:
{
"root": "/Users/josh/workspace/schemaflow",
"subprojects": {
"ruby": { "path": "ruby", "type": "ruby" },
"cli": { "path": "cli", "type": "node" }
}
}
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub technicalpickles/pickled-claude-plugins --plugin working-in-monoreposOther plugins' skills for the same job