ccw-cli-tools
Original:🇺🇸 English
Translated
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. Supports configurable CLI endpoints for analysis, write, and review modes.
11installs
Added on
NPX Install
npx skill4agent add catlog22/claude-code-workflow ccw-cli-toolsTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →CLI Tools - Unified Execution Framework
Purpose: Structured CLI tool usage with configuration-driven tool selection, unified prompt templates, and quality-gated execution.
Configuration: (Global, always read at initialization)
~/.claude/cli-tools.jsonInitialization (Required First Step)
Before any tool selection or recommendation:
-
Check if configuration exists in memory:
- If configuration is already in conversation memory → Use it directly
- If NOT in memory → Read the configuration file:
bash
Read(file_path="~/.claude/cli-tools.json")
-
Parse the JSON to understand:
- Available tools and their status
enabled - Each tool's and
primaryModelsecondaryModel - Tags defined for tag-based routing
- Tool types (builtin, cli-wrapper, api-endpoint)
- Available tools and their
-
Use 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.
Process Flow
┌─ 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 toolConfiguration Reference
Configuration File Location
Path: (Global configuration)
~/.claude/cli-tools.jsonIMPORTANT: Check conversation memory first. Only read file if configuration is not in memory.
Reading Configuration
Priority: Check conversation memory first
Loading Options:
- Option 1 (Preferred): Use in-memory configuration if already loaded in conversation
- Option 2 (Fallback): Read from file when not in memory
bash
# Read configuration file
cat ~/.claude/cli-tools.jsonThe configuration defines all available tools with their enabled status, models, and tags.
Configuration Structure
The JSON file contains a object where each tool has these fields:
tools| Field | Type | Description | Example |
|---|---|---|---|
| boolean | Tool availability status | |
| string | Default model for execution | |
| string | Fallback model on primary failure | |
| array | Capability tags for routing | |
| string | Tool type | |
Expected Tools (Reference Only)
Typical tools found in configuration (actual availability determined by reading the file):
| Tool | Typical Type | Common Use |
|---|---|---|
| builtin | Analysis, Debug (分析, Debug tags) |
| builtin | General coding |
| builtin | Code review, implementation |
| builtin | General tasks |
| builtin | Open-source model fallback |
Note: Tool availability, models, and tags may differ. Use in-memory configuration or read if not cached.
~/.claude/cli-tools.jsonConfiguration Fields
- : Tool availability (boolean)
enabled - : Default model for execution
primaryModel - : Fallback model on primary failure
secondaryModel - : Capability tags for routing (分析, Debug, implementation, etc.)
tags - : Tool type (builtin, cli-wrapper, api-endpoint)
type
Universal Prompt Template
Structure: Every CLI command follows this 6-field template
bash
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>Field Specifications
PURPOSE (Goal Definition)
What: Clear objective + motivation + success criteria + scope boundary
Components:
- What: Specific task goal
- Why: Business/technical motivation
- Success: Measurable success criteria
- Scope: Bounded context/files
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/** onlyExample - Bad:
PURPOSE: Analyze codeTASK (Action Steps)
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 validationExample - Bad:
TASK: Review code and find issuesMODE (Permission Level)
Options:
- - Read-only, safe for auto-execution
analysis - - Create/Modify/Delete files, full operations
write - - Git-aware code review (codex only)
review
Rules:
- Always specify explicitly
- Default to for read-only tasks
analysis - Require explicit for file modifications
--mode write - Use with
--mode reviewfor git-aware review--tool codex
CONTEXT (File Scope + Memory)
Format:
CONTEXT: @[file patterns] | Memory: [memory context]File Patterns:
- - All files (default)
@**/* - - Specific pattern
@src/**/*.ts - - Parent/sibling (requires
@../shared/**/*)--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.tsEXPECTED (Output Specification)
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 rankingExample - Bad:
EXPECTED: ReportCONSTRAINTS (Domain Boundaries)
What: Scope limits, special requirements, focus areas
Example - Good:
CONSTRAINTS: Focus on authentication | Ignore test files | No breaking changesExample - Bad:
CONSTRAINTS: (missing or too vague)CLI Execution Modes
MODE: analysis
- Permission: Read-only
- Use For: Code review, architecture analysis, pattern discovery, exploration
- Safe: Yes - can auto-execute
- Default: When not specified
MODE: write
- Permission: Create/Modify/Delete files
- Use For: Feature implementation, bug fixes, documentation, code creation
- Safe: No - requires explicit
--mode write - Requirements: Must be explicitly requested by user
MODE: review
- Permission: Read-only (git-aware review output)
- Use For: Code review of uncommitted changes, branch diffs, specific commits
- Tool Support: only (others treat as analysis)
codex - Constraint: Target flags (,
--uncommitted,--base) and prompt are mutually exclusive--commit
Command Structure
Basic Command
bash
ccw cli -p "<PROMPT>" --tool <tool-id> --mode <analysis|write|review>Command Options
| Option | Description | Example |
|---|---|---|
| Tool from config | |
| REQUIRED: analysis/write/review | |
| Model override | |
| Working directory | |
| Additional directories | |
| Auto-load template | |
| Resume session | |
Advanced Directory Configuration
Working Directory (--cd
)
--cdWhen using :
--cd- = Files within working directory tree only
@**/* - Cannot reference parent/sibling without
--includeDirs - Reduces token usage by scoping context
Include Directories (--includeDirs
)
--includeDirsTwo-step requirement for external files:
- Add parameter
--includeDirs - Reference in CONTEXT with @ patterns
bash
# 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,../utilsSession Resume
When to Use:
- Multi-round planning (analysis → planning → implementation)
- Multi-model collaboration (tool A → tool B on same topic)
- Topic continuity (building on previous findings)
Usage:
bash
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 sessionsAvailable Rule Templates
Template System
Use to auto-load protocol + template appended to prompt
--rule <template-name>Universal Templates
- - Precise tasks (default)
universal-rigorous-style - - Exploratory tasks
universal-creative-style
Analysis Templates
- - Execution tracing
analysis-trace-code-execution - - Bug diagnosis
analysis-diagnose-bug-root-cause - - Code patterns
analysis-analyze-code-patterns - - Document analysis
analysis-analyze-technical-document - - Architecture review
analysis-review-architecture - - Code review
analysis-review-code-quality - - Performance analysis
analysis-analyze-performance - - Security assessment
analysis-assess-security-risks
Planning Templates
- - Architecture design
planning-plan-architecture-design - - Task breakdown
planning-breakdown-task-steps - - Component design
planning-design-component-spec - - Migration strategy
planning-plan-migration-strategy
Development Templates
- - Feature implementation
development-implement-feature - - Code refactoring
development-refactor-codebase - - Test generation
development-generate-tests - - UI component
development-implement-component-ui - - Runtime debugging
development-debug-runtime-issues
Task-Type Specific Examples
Example 1: Security Analysis (Read-Only)
bash
ccw 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/authExample 2: Feature Implementation (Write Mode)
bash
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-featureExample 3: Bug Root Cause Analysis
bash
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 srcExample 4: Code Review (Codex Review Mode)
bash
# 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 abc123Tool Selection Strategy
Selection Algorithm
STEP 0 (REQUIRED): Load configuration (memory-first strategy)
bash
# 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:
- Parse task intent → Extract required capabilities
- Load configuration → Parse enabled tools with tags from JSON
- Match tags → Filter tools supporting required capabilities
- Select tool → Choose by priority (explicit > tag-match > default)
- Select model → Use primaryModel, fallback to secondaryModel
Selection Decision Tree
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 configCommon Tag Routing
Note: Match task type to tags defined in
~/.claude/cli-tools.json| Task Type | Common Tags to Match |
|---|---|
| Security audit | |
| Bug diagnosis | |
| Implementation | |
| Testing | |
| Refactoring | |
| Documentation | |
Selection Logic: Find tools where array contains matching keywords, otherwise use first enabled tool.
tagsFallback Chain
When primary tool fails (based on configuration):
~/.claude/cli-tools.json- Check for same tool (use
secondaryModelfrom config)secondaryModel - Try next enabled tool with matching tags (scan config for enabled tools)
- Fall back to default enabled tool (first enabled tool in 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 toolPermission Framework
Single-Use Authorization: Each execution requires explicit user instruction. Previous authorization does NOT carry over.
Mode Hierarchy:
- : Read-only, safe for auto-execution
analysis - : Create/Modify/Delete files - requires explicit
write--mode write - : Git-aware code review (codex only) - requires explicit
review--mode review - Exception: User provides clear instructions like "modify", "create", "implement"
Auto-Invoke Triggers
Proactive CLI invocation - Auto-invoke when encountering these scenarios:
ccw cli| Trigger | Suggested Rule | When |
|---|---|---|
| Self-repair fails | | After 1+ failed fix attempts |
| Ambiguous requirements | | Task description lacks clarity |
| Architecture decisions | | Complex feature needs design |
| Pattern uncertainty | | Unsure of existing conventions |
| Critical code paths | | Security/performance sensitive |
Execution Principles for Auto-Invoke
- Default mode: (read-only, safe)
--mode analysis - No confirmation needed: Invoke proactively when triggers match
- Wait for results: Complete analysis before next action
- Tool selection: Use context-appropriate tool or fallback chain
- Rule flexibility: Suggested rules are guidelines, adapt as needed
Best Practices
Core Principles
- Configuration-driven - All tool selection from
cli-tools.json - Tag-based routing - Match task requirements to tool capabilities
- Use tools early and often - Tools are faster and more thorough than manual analysis
- Unified CLI - Always use for consistent parameter handling
ccw cli -p - Default to analysis - Omit for read-only, explicitly use
--modefor modifications--mode write - Use for templates - Auto-loads protocol + template appended to prompt
--rule - Write protection - Require EXPLICIT for file operations
--mode write
Workflow Principles
- Use unified interface - Always format
ccw cli -p - Always include template - Use to load templates
--rule <template-name> - Be specific - Clear PURPOSE, TASK, EXPECTED fields
- Include constraints - File patterns, scope in CONSTRAINTS
- Leverage memory context - When building on previous work
- Discover patterns first - Use rg/MCP before CLI execution
- Default to full context - Use unless specific files needed
@**/*
Planning Checklist
- Purpose defined - Clear goal and intent
- Mode selected -
--mode analysis|write|review - Context gathered - File references + memory (default )
@**/* - Directory navigation - and/or
--cdif needed--includeDirs - Tool selected - Explicit or tag-based auto-selection
--tool - Rule template - loads template
--rule <template-name> - Constraints - Domain constraints in CONSTRAINTS field
Integration with CLAUDE.md Instructions
From global CLAUDE.md:
- Always use for Task tool agent calls
run_in_background: false - Default: Use Bash for CLI calls
run_in_background: true - After CLI call: Stop output immediately, wait for hook callback
- Wait for results: MUST wait for CLI analysis before taking write actions
- Value every call: Never waste analysis results, aggregate before proposing solutions
From cli-tools-usage.md:
- Strict cli-tools.json configuration adherence
- Configuration-driven tool selection
- Template system with --rule auto-loading
- Permission framework with single-use authorization
- Auto-invoke triggers for common failure scenarios