CLI tools execution specification (gemini/claude/codex/qwen/opencode) with unified prompt template, mode options, and auto-invoke triggers for code analysis and implementation tasks...
Purpose: Structured CLI tool usage with configuration-driven tool selection, unified prompt templates, and quality-gated execution.
Configuration: ~/.claude/cli-tools.json (Global, always read at initialization)
Before any tool selection or recommendation:
Check if configuration exists in memory:
Read(file_path="~/.claude/cli-tools.json")
Parse the JSON to understand:
enabled statusprimaryModel and secondaryModelUse configuration throughout the selection process
Why: Tools, models, and tags may change. Configuration file is the single source of truth. Optimization: Reuse in-memory configuration to avoid redundant file reads.
āā USER REQUEST
ā
āā STEP 1: Load Configuration
ā āā Check if configuration exists in conversation memory
ā āā If NOT in memory ā Read(file_path="~/.claude/cli-tools.json")
ā
āā STEP 2: Understand User Intent
ā āā Parse task type (analysis, implementation, security, etc.)
ā āā Extract required capabilities (tags)
ā āā Identify scope (files, modules)
ā
āā STEP 3: Select Tool (based on config)
ā āā Explicit --tool specified?
ā ā YES ā Validate in config ā Use it
ā ā NO ā Match tags with enabled tools ā Select best match
ā ā ā No match ā Use first enabled tool (default)
ā āā Get primaryModel from config
ā
āā STEP 4: Build Prompt
ā āā Use 6-field template: PURPOSE, TASK, MODE, CONTEXT, EXPECTED, CONSTRAINTS
ā
āā STEP 5: Select Rule Template
ā āā Determine rule from task type
ā āā Pass via --rule parameter
ā
āā STEP 6: Execute CLI Command
ā āā ccw cli -p "<PROMPT>" --tool <tool> --mode <mode> --rule <rule>
ā
āā STEP 7: Handle Results
āā On success ā Deliver output to user
āā On failure ā Check secondaryModel or fallback tool
Path: ~/.claude/cli-tools.json (Global configuration)
IMPORTANT: Check conversation memory first. Only read file if configuration is not in memory.
Priority: Check conversation memory first
Loading Options:
# Read configuration file
cat ~/.claude/cli-tools.json
The configuration defines all available tools with their enabled status, models, and tags.
The JSON file contains a tools object where each tool has these fields:
| Field | Type | Description | Example |
|---|---|---|---|
enabled |
boolean | Tool availability status | true or false |
primaryModel |
string | Default model for execution | "gemini-2.5-pro" |
secondaryModel |
string | Fallback model on primary failure | "gemini-2.5-flash" |
tags |
array | Capability tags for routing | ["åę", "Debug"] |
type |
string | Tool type | "builtin", "cli-wrapper", "api-endpoint" |
Typical tools found in configuration (actual availability determined by reading the file):
| Tool | Typical Type | Common Use |
|---|---|---|
gemini |
builtin | Analysis, Debug (åę, Debug tags) |
qwen |
builtin | General coding |
codex |
builtin | Code review, implementation |
claude |
builtin | General tasks |
opencode |
builtin | Open-source model fallback |
Note: Tool availability, models, and tags may differ. Use in-memory configuration or read ~/.claude/cli-tools.json if not cached.
enabled: Tool availability (boolean)primaryModel: Default model for executionsecondaryModel: Fallback model on primary failuretags: Capability tags for routing (åę, Debug, implementation, etc.)type: Tool type (builtin, cli-wrapper, api-endpoint)Structure: Every CLI command follows this 6-field template
ccw cli -p "PURPOSE: [goal] + [why] + [success criteria] + [scope]
TASK: ⢠[step 1: specific action] ⢠[step 2: specific action] ⢠[step 3: specific action]
MODE: [analysis|write|review]
CONTEXT: @[file patterns] | Memory: [session/tech/module context]
EXPECTED: [deliverable format] + [quality criteria] + [structure requirements]
CONSTRAINTS: [domain constraints]" --tool <tool-id> --mode <mode> --rule <template>
What: Clear objective + motivation + success criteria + scope boundary
Components:
Example - Good:
PURPOSE: Identify OWASP Top 10 vulnerabilities in auth module to pass security audit;
success = all critical/high issues documented with remediation;
scope = src/auth/** only
Example - Bad:
PURPOSE: Analyze code
What: Specific, actionable steps with clear verbs and targets
Format: Bullet list with concrete actions
Example - Good:
TASK:
⢠Scan for SQL injection in query builders
⢠Check XSS in template rendering
⢠Verify CSRF token validation
Example - Bad:
TASK: Review code and find issues
Options:
analysis - Read-only, safe for auto-executionwrite - Create/Modify/Delete files, full operationsreview - Git-aware code review (codex only)Rules:
analysis for read-only tasks--mode write for file modifications--mode review with --tool codex for git-aware reviewFormat: CONTEXT: @[file patterns] | Memory: [memory context]
File Patterns:
@**/* - All files (default)@src/**/*.ts - Specific pattern@../shared/**/* - Parent/sibling (requires --includeDirs)Memory Context (when building on previous work):
Memory: Building on auth refactoring (commit abc123), using JWT for sessions
Memory: Integration with auth module, shared error patterns from @shared/utils/errors.ts
What: Output format + quality criteria + structure requirements
Example - Good:
EXPECTED: Markdown report with:
severity levels (Critical/High/Medium/Low),
file:line references,
remediation code snippets,
priority ranking
Example - Bad:
EXPECTED: Report
What: Scope limits, special requirements, focus areas
Example - Good:
CONSTRAINTS: Focus on authentication | Ignore test files | No breaking changes
Example - Bad:
CONSTRAINTS: (missing or too vague)
--mode writecodex only (others treat as analysis)--uncommitted, --base, --commit) and prompt are mutually exclusiveccw cli -p "<PROMPT>" --tool <tool-id> --mode <analysis|write|review>
| Option | Description | Example |
|---|---|---|
--tool <tool> |
Tool from config | --tool gemini |
--mode <mode> |
REQUIRED: analysis/write/review | --mode analysis |
--model <model> |
Model override | --model gemini-2.5-flash |
--cd <path> |
Working directory | --cd src/auth |
--includeDirs <dirs> |
Additional directories | --includeDirs ../shared,../types |
--rule <template> |
Auto-load template | --rule analysis-review-architecture |
--resume [id] |
Resume session | --resume or --resume <id> |
--cd)When using --cd:
@**/* = Files within working directory tree only--includeDirs--includeDirs)Two-step requirement for external files:
--includeDirs parameter# Single directory
ccw cli -p "CONTEXT: @**/* @../shared/**/*" \
--tool gemini --mode analysis \
--cd src/auth --includeDirs ../shared
# Multiple directories
ccw cli -p "..." \
--tool gemini --mode analysis \
--cd src/auth --includeDirs ../shared,../types,../utils
When to Use:
Usage:
ccw cli -p "Continue analyzing" --tool <tool-id> --mode analysis --resume # Resume last
ccw cli -p "Fix issues found" --tool <tool-id> --mode write --resume <id> # Resume specific
ccw cli -p "Merge findings" --tool <tool-id> --mode analysis --resume <id1>,<id2> # Merge sessions
Use --rule <template-name> to auto-load protocol + template appended to prompt
universal-rigorous-style - Precise tasks (default)universal-creative-style - Exploratory tasksanalysis-trace-code-execution - Execution tracinganalysis-diagnose-bug-root-cause - Bug diagnosisanalysis-analyze-code-patterns - Code patternsanalysis-analyze-technical-document - Document analysisanalysis-review-architecture - Architecture reviewanalysis-review-code-quality - Code reviewanalysis-analyze-performance - Performance analysisanalysis-assess-security-risks - Security assessmentplanning-plan-architecture-design - Architecture designplanning-breakdown-task-steps - Task breakdownplanning-design-component-spec - Component designplanning-plan-migration-strategy - Migration strategydevelopment-implement-feature - Feature implementationdevelopment-refactor-codebase - Code refactoringdevelopment-generate-tests - Test generationdevelopment-implement-component-ui - UI componentdevelopment-debug-runtime-issues - Runtime debuggingccw cli -p "PURPOSE: Identify OWASP Top 10 vulnerabilities in authentication module to pass security audit; success = all critical/high issues documented with remediation
TASK: ⢠Scan for injection flaws (SQL, command, LDAP) ⢠Check authentication bypass vectors ⢠Evaluate session management ⢠Assess sensitive data exposure
MODE: analysis
CONTEXT: @src/auth/**/* @src/middleware/auth.ts | Memory: Using bcrypt for passwords, JWT for sessions
EXPECTED: Security report with: severity matrix, file:line references, CVE mappings where applicable, remediation code snippets prioritized by risk
CONSTRAINTS: Focus on authentication | Ignore test files
" --tool gemini --mode analysis --rule analysis-assess-security-risks --cd src/auth
ccw cli -p "PURPOSE: Implement rate limiting for API endpoints to prevent abuse; must be configurable per-endpoint; backward compatible with existing clients
TASK: ⢠Create rate limiter middleware with sliding window ⢠Implement per-route configuration ⢠Add Redis backend for distributed state ⢠Include bypass for internal services
MODE: write
CONTEXT: @src/middleware/**/* @src/config/**/* | Memory: Using Express.js, Redis already configured, existing middleware pattern in auth.ts
EXPECTED: Production-ready code with: TypeScript types, unit tests, integration test, configuration example, migration guide
CONSTRAINTS: Follow existing middleware patterns | No breaking changes
" --tool gemini --mode write --rule development-implement-feature
ccw cli -p "PURPOSE: Fix memory leak in WebSocket connection handler causing server OOM after 24h; root cause must be identified before any fix
TASK: ⢠Trace connection lifecycle from open to close ⢠Identify event listener accumulation ⢠Check cleanup on disconnect ⢠Verify garbage collection eligibility
MODE: analysis
CONTEXT: @src/websocket/**/* @src/services/connection-manager.ts | Memory: Using ws library, ~5000 concurrent connections in production
EXPECTED: Root cause analysis with: memory profile, leak source (file:line), fix recommendation with code, verification steps
CONSTRAINTS: Focus on resource cleanup
" --tool gemini --mode analysis --rule analysis-diagnose-bug-root-cause --cd src
# Option 1: Custom focus (reviews uncommitted by default)
ccw cli -p "Focus on security vulnerabilities and error handling" --tool codex --mode review
# Option 2: Target flag only (no prompt with target flags)
ccw cli --tool codex --mode review --uncommitted
ccw cli --tool codex --mode review --base main
ccw cli --tool codex --mode review --commit abc123
STEP 0 (REQUIRED): Load configuration (memory-first strategy)
# Check if configuration exists in conversation memory
# If YES ā Use in-memory configuration
# If NO ā Read(file_path="~/.claude/cli-tools.json")
Then proceed with selection:
0. LOAD CONFIGURATION (memory-first)
āā In memory? ā Use it
āā Not in memory? ā Read ~/.claude/cli-tools.json
ā
1. Explicit --tool specified?
YES ā Validate tool is enabled in config ā Use it
NO ā Proceed to tag-based selection
āā Extract task tags (security, analysis, implementation, etc.)
ā āā Find tools with matching tags
ā ā āā Multiple matches? Use first enabled
ā ā āā Single match? Use it
ā āā No tag match? Use default tool
ā
āā Default: Use first enabled tool in config
Note: Match task type to tags defined in ~/.claude/cli-tools.json
| Task Type | Common Tags to Match |
|---|---|
| Security audit | åę, analysis, security |
| Bug diagnosis | Debug, åę, analysis |
| Implementation | implementation, (any enabled tool) |
| Testing | testing, (any enabled tool) |
| Refactoring | refactoring, (any enabled tool) |
| Documentation | documentation, (any enabled tool) |
Selection Logic: Find tools where tags array contains matching keywords, otherwise use first enabled tool.
When primary tool fails (based on ~/.claude/cli-tools.json configuration):
secondaryModel for same tool (use secondaryModel from config)Example Fallback:
Tool1: primaryModel fails
ā
Try Tool1: secondaryModel
ā (if fails)
Try Tool2: primaryModel (next enabled with matching tags)
ā (if fails)
Try default: first enabled tool
Single-Use Authorization: Each execution requires explicit user instruction. Previous authorization does NOT carry over.
Mode Hierarchy:
analysis: Read-only, safe for auto-executionwrite: Create/Modify/Delete files - requires explicit --mode writereview: Git-aware code review (codex only) - requires explicit --mode reviewProactive CLI invocation - Auto-invoke ccw cli when encountering these scenarios:
| Trigger | Suggested Rule | When |
|---|---|---|
| Self-repair fails | analysis-diagnose-bug-root-cause |
After 1+ failed fix attempts |
| Ambiguous requirements | planning-breakdown-task-steps |
Task description lacks clarity |
| Architecture decisions | planning-plan-architecture-design |
Complex feature needs design |
| Pattern uncertainty | analysis-analyze-code-patterns |
Unsure of existing conventions |
| Critical code paths | analysis-assess-security-risks |
Security/performance sensitive |
--mode analysis (read-only, safe)cli-tools.jsonccw cli -p for consistent parameter handling--mode for read-only, explicitly use --mode write for modifications--rule for templates - Auto-loads protocol + template appended to prompt--mode write for file operationsccw cli -p format--rule <template-name> to load templates@**/* unless specific files needed--mode analysis|write|review@**/*)--cd and/or --includeDirs if needed--tool or tag-based auto-selection--rule <template-name> loads templateFrom global CLAUDE.md:
run_in_background: false for Task tool agent callsrun_in_background: true for CLI callsFrom cli-tools-usage.md: