Automatic project context detection with priority-based resolution (Manual setting → Git remote → Subdirectory pattern → Local path → Custom patterns). Auto-activates at start of every CCPM command to ensure correct project context. Supports monorepos with subdirectory detection using glob patterns and priority weighting. Handles ambiguous detection (multiple matches) by asking user to clarify. Caches detection result for command duration (fast reuse). Provides clear error messages with actionable suggestions when no project detected. Displays project context in command headers (e.g., "📋 Project: My Monorepo › frontend"). Supports auto-detection mode (cd = switch) or manual setting (stable context across sessions). Performance: <100ms for auto-detection, 0ms for manual.
Auto-detects your project context using priority-based resolution (manual → git remote → subdirectory → local path → custom patterns). Activates automatically at the start of every CCPM command to ensure correct project context, with <100ms performance and intelligent monorepo subproject detection.
/plugin marketplace add duongdev/ccpm/plugin install ccpm@duongdev-ccpm-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
This skill ensures every CCPM command has the correct project context. It auto-activates to provide seamless project detection without user intervention.
This skill activates automatically:
graph TD
A[Command Starts] --> B{Manual Project Set?}
B -->|Yes| C[Use Manual Setting]
B -->|No| D{Auto-Detection Enabled?}
D -->|Yes| E[Invoke project-detector]
D -->|No| F[Prompt User for Project]
E --> G{Project Detected?}
G -->|Yes| H[Load Full Config]
G -->|No| F
H --> I[Cache Context]
I --> J[Command Proceeds]
C --> H
F --> J
Manual Setting (Highest Priority)
/ccpm:project:set my-projectcontext.current_projectGit Remote URL Match
projects.*.repository.urlSubdirectory Pattern Match (NEW)
local_pathcontext.detection.subdirectories patternsLocal Path Match
projects.*.repository.local_pathCustom Patterns
context.detection.patternsAlways use the project-detector agent:
// At the start of every command
const detection = Task(project-detector): `
Detect active project
Environment:
- Current directory: ${cwd}
- Git remote: ${gitRemote}
- Config: ~/.claude/ccpm-config.yaml
`
if (detection.error) {
// Handle no project detected
console.error(detection.error.message)
detection.error.suggestions.forEach(s => console.log(s))
return
}
// Cache for command duration
const PROJECT_CONTEXT = {
id: detection.project_id,
name: detection.project_name,
subproject: detection.subproject,
method: detection.detection_method
}
For monorepos with multiple sub-projects:
projects:
my-monorepo:
repository:
url: https://github.com/org/monorepo
local_path: /Users/dev/monorepo
context:
detection:
subdirectories:
- subproject: web-app
match_pattern: "*/apps/web/*"
priority: 10
- subproject: mobile-app
match_pattern: "*/apps/mobile/*"
priority: 10
- subproject: api-server
match_pattern: "*/services/api/*"
priority: 10
code_repository:
subprojects:
- name: web-app
path: apps/web
tech_stack:
frontend: [react, nextjs]
- name: mobile-app
path: apps/mobile
tech_stack:
frontend: [react-native, expo]
Example 1: Web App Directory
$ cd /Users/dev/monorepo/apps/web/src/components
$ /ccpm:plan "Add dark mode"
# Detection flow:
# 1. Git remote → matches "my-monorepo" ✓
# 2. Subdirectory → CWD matches "*/apps/web/*" ✓
# 3. Result: project="my-monorepo", subproject="web-app"
# Display:
📋 Project: My Monorepo › web-app
🛠️ Tech Stack: React, Next.js
# Linear labels: [my-monorepo, web-app, planning]
Example 2: Mobile App Directory
$ cd /Users/dev/monorepo/apps/mobile
$ /ccpm:work WORK-123
# Detection:
# → project="my-monorepo", subproject="mobile-app"
# Display:
📋 Project: My Monorepo › mobile-app
🛠️ Tech Stack: React Native, Expo
Example 3: Repository Root
$ cd /Users/dev/monorepo
$ /ccpm:project:list
# Detection:
# 1. Git remote → matches "my-monorepo" ✓
# 2. Subdirectory → CWD at root, no pattern match
# 3. Result: project="my-monorepo", subproject=null
# Display:
📋 Project: My Monorepo
⭐ Active (Git remote match)
Glob Patterns Supported:
# Match any path containing /frontend/
"*/frontend/*"
# Match specific nesting
"apps/web/src/*"
# Match multiple levels
"**/services/**"
# Match alternatives (requires extension)
"apps/{web,mobile}/*"
Priority Handling:
When multiple patterns match, higher priority wins:
subdirectories:
# Specific pattern (high priority)
- subproject: admin-panel
match_pattern: "*/apps/web/admin/*"
priority: 20
# General pattern (lower priority)
- subproject: web-app
match_pattern: "*/apps/web/*"
priority: 10
# Working in: /apps/web/admin/users
# Both patterns match, but "admin-panel" wins (priority 20 > 10)
In Command Headers:
📋 Project: My Monorepo › frontend
In Status Displays:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📋 Active Project
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Project: My Monorepo
Subproject: frontend
Tech Stack: React, TypeScript, Vite
Location: /Users/dev/monorepo/apps/frontend
Detection: Auto (subdirectory match)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Situation: User runs command outside any configured project
Detection Result:
{
error: {
code: "NO_PROJECT_DETECTED",
message: "Could not detect active project",
suggestions: [
"Set active project: /ccpm:project:set <project-id>",
"Enable auto-detection: /ccpm:project:set auto",
"Check current directory is within a configured project",
"List projects: /ccpm:project:list"
]
}
}
Command Response:
❌ Could not detect active project
You are currently in: /Users/dev/random-project
CCPM couldn't match this to any configured project.
Options:
1. Set a specific project:
/ccpm:project:set <project-id>
2. Enable auto-detection and cd to a configured project:
/ccpm:project:set auto
cd ~/my-project
3. Add this project to CCPM:
/ccpm:project:add new-project
4. See all configured projects:
/ccpm:project:list
Situation: Multiple projects match (rare, but possible)
Detection Result:
{
error: {
code: "AMBIGUOUS_PROJECT",
message: "Multiple projects match current context",
candidates: [
{ project: "my-monorepo", reason: "Git remote matches" },
{ project: "local-clone", reason: "Working directory matches" }
]
}
}
Command Response:
⚠️ Multiple projects match your current location
Candidates:
1. my-monorepo (Git remote: github.com/org/monorepo)
2. local-clone (Local path: /Users/dev/monorepo)
Please specify which project:
/ccpm:project:set my-monorepo
Or disable one detection method in config.
Situation: Project detected but config invalid
Command Response:
❌ Project configuration error
Project 'my-project' detected but has errors:
- Missing required field: linear.team
- Missing required field: linear.project
Fix with:
/ccpm:project:update my-project --field linear.team
Or edit config manually:
~/.claude/ccpm-config.yaml
Use When:
How:
/ccpm:project:set my-project
# Now ALL commands use my-project, regardless of directory
Pros:
Cons:
Use When:
How:
/ccpm:project:set auto
# Now commands detect based on directory/git
cd ~/monorepo/apps/frontend # → project: monorepo, sub: frontend
cd ~/other-project # → project: other-project
Pros:
Cons:
Detection Speed:
Caching:
// Detect once per command
if (!CACHED_CONTEXT) {
CACHED_CONTEXT = Task(project-detector): "Detect project"
}
// Reuse for entire command
const project = CACHED_CONTEXT.project_id
Optimization:
Every CCPM command should start with:
## Step 1: Detect Project Context
Skill(project-detection): This auto-activates
Task(project-detector): `
Detect active project
`
If detection succeeds → proceed
If detection fails → show error and exit
Then load full config:
## Step 2: Load Project Configuration
Task(project-config-loader): `
Load configuration for project: ${PROJECT_ID}
Include subproject: ${SUBPROJECT}
Validate: true
`
Problem: "No project detected" but I'm in a project
Solution:
# Check config file exists
ls -la ~/.claude/ccpm-config.yaml
# Check git remote matches
git remote get-url origin
# Compare with config: projects.*.repository.url
# Check local path if set
pwd
# Compare with config: projects.*.repository.local_path
# Try manual setting
/ccpm:project:set <project-id>
Problem: "Wrong subproject detected"
Solution:
# Check subdirectory patterns in config
cat ~/.claude/ccpm-config.yaml | grep -A 20 "subdirectories:"
# Verify pattern matches current path
pwd
# Should match one of the patterns
# Adjust pattern or priority if needed
/ccpm:project:update <project-id> --field context.detection.subdirectories
Problem: "Detection is slow"
Solution:
/ccpm:project:set <project-id>Skills:
project-operations - Overall project management guidancepm-workflow-guide - Workflow guidance with project contextAgents:
project-detector - Detection implementationproject-config-loader - Config loadingproject-context-manager - Context managementWhen to update:
Update locations:
project-detector agent (implementation)This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.