Claude Code CLI Integration Skill
Purpose: Enable Claude Code extension to orchestrate its own CLI for operations requiring unrestricted system access, bypassing VS Code extension permission limitations.
Version: 1.0.0
Auto-Invoke: False (manual activation or SubAgent triggers)
Overview
This Skill enables Claude Code (VS Code extension) to leverage Claude Code CLI for:
- Batch file operations without permission prompts (50+ files)
- System-level configuration and package installation
- Complex workflows requiring both IDE context and system access
- Automation scripts that would be blocked in sandboxed environment
Key Innovation: Self-orchestration - Claude Code extension commands its own CLI for unrestricted operations while maintaining IDE context awareness.
When to Use This Skill
✅ Use Claude Code CLI for:
- Batch operations: 50+ files requiring individual permission prompts
- System access: Package installation, environment configuration
- Automation: Scripts that need unrestricted file system access
- Performance: Bulk processing where speed matters
- Task automation: Bulk task file creation/updates in fstrent_spec_tasks
❌ Don't use Claude Code CLI for:
- Single files: Use extension's native file operations
- Interactive debugging: Requires IDE integration
- Quick edits: Immediate IDE feedback needed
- Small batches: <10 files (permission prompts acceptable)
Decision Framework
Strategy Selection
The Skill uses three strategies based on task characteristics:
Strategy A: Extension Native (Fast Path)
Criteria:
- Files: <10
- System access: No
- IDE context: Critical
- Time: <30 seconds
Example: Code review, quick edit, single file refactor
Strategy B: CLI (System Path)
Criteria:
- Files: >10
- System access: Yes
- Permission prompts: >5
- Performance critical: Yes
Example: Refactor 150 files, system setup, bulk task creation
Strategy C: Hybrid (Complex Path)
Criteria:
- Context gathering: Extension
- Bulk execution: CLI
- Validation: Extension
- Multi-step workflow: Yes
Example: Complex refactoring with validation, system setup with testing
Command Patterns
Basic Usage
# Simple command
claude-code "Your instruction here"
# With file context
claude-code "Analyze this file" --file path/to/file.py
# With directory context
claude-code "Refactor all Python files" --directory src/
# Dry run first (recommended)
claude-code "Refactor codebase" --dry-run
claude-code "Refactor codebase" --auto-approve # After review
Integration Patterns
Pattern 1: Batch File Processing
# Extension: Analyze structure
# CLI: Process all files at once
claude-code "Add type hints to all Python files in src/" \
--directory src/ \
--auto-approve
Pattern 2: System Configuration
# CLI handles system-level operations
claude-code "Install Python 3.11, uv, configure virtual environment" \
--auto-approve
Pattern 3: Context Gathering + Execution
# Extension: Generate plan
cat > execution_plan.md << EOF
# Refactoring Plan
- Pattern: old → new
- Files: 150
- Validation: Run tests
EOF
# CLI: Execute bulk operation
claude-code "Execute refactoring according to plan" \
--file execution_plan.md \
--directory src/ \
--dry-run
# Extension: Validate results
pytest tests/ -v
Workflow Examples
Example 1: Large-Scale Refactoring
Task: Refactor 150 Python files to new import structure
Steps:
- Extension: Analyze current import structure
- Extension: Generate refactoring plan
- CLI: Execute bulk refactoring (dry run)
- User: Review changes
- CLI: Apply refactoring
- Extension: Run tests to validate
Command Sequence:
# Step 1-2: Extension analyzes and creates plan
cat > refactor_plan.md << EOF
# Import Refactoring Plan
- Old: from utils import helper
- New: from src.utils.helpers import helper
- Files: 150
EOF
# Step 3: CLI dry run
claude-code "Refactor according to plan" \
--file refactor_plan.md \
--directory src/ \
--dry-run
# Step 5: CLI applies
claude-code "Apply refactoring" \
--file refactor_plan.md \
--directory src/ \
--auto-approve
# Step 6: Extension validates
pytest tests/ -v
Result:
- Time saved: ~90 minutes (vs manual approval)
- Permission prompts: 1 (vs 150+)
- Success rate: 100%
Example 2: System Setup
Task: Setup Python project with dependencies and MCP servers
Steps:
- Extension: Generate project plan
- CLI: Install system packages
- CLI: Create project structure
- CLI: Install dependencies
- Extension: Configure IDE settings
- Extension: Validate setup
Command Sequence:
# Step 2: System setup
claude-code "Install Python 3.11, uv, virtual environment" \
--auto-approve
# Step 3: Project structure
claude-code "Create project structure: src/, tests/, docs/" \
--auto-approve
# Step 4: Dependencies
claude-code "Install dependencies from requirements.txt" \
--file requirements.txt
# Step 6: Extension validates
python --version && pytest --version
Result:
- Setup time: ~15 minutes (vs ~60 manual)
- Configuration: 100% accurate
- MCP servers: All configured
Example 3: Task Automation
Task: Create task files for all features in PLAN.md
Steps:
- Extension: Read PLAN.md, identify features
- CLI: Generate all task files at once
- Extension: Update TASKS.md with new entries
- Extension: Validate task file structure
Command Sequence:
# Step 2: CLI generates all tasks
claude-code "Read PLAN.md and create task files for all features" \
--file .fstrent_spec_tasks/PLAN.md \
--output-dir .fstrent_spec_tasks/tasks/ \
--dry-run
# After review
claude-code "Create task files" \
--file .fstrent_spec_tasks/PLAN.md \
--output-dir .fstrent_spec_tasks/tasks/ \
--auto-approve
# Step 3: Extension updates TASKS.md
# Step 4: Extension validates
Result:
- Tasks created: 20+ (in minutes)
- Manual effort saved: ~2 hours
- Consistency: 100%
Security Considerations
Critical Security Rules
✅ Always:
- Review commands before execution
- Use
--dry-runfor destructive operations - Validate file paths (prevent directory traversal)
- Use files for sensitive data (not command line)
- Log all CLI operations for audit trail
❌ Never:
- Use
--auto-approvewithout reviewing dry-run - Hardcode credentials in commands
- Execute commands from untrusted sources
- Bypass security checks for convenience
Safe Command Patterns
✅ SAFE:
# Uses file for context, validates paths
claude-code "Process files" \
--file context.txt \
--directory /validated/path
❌ UNSAFE:
# Command injection risk
user_input="$1"
claude-code "$user_input" --auto-approve
✅ SAFE (with validation):
# Validates input first
if [[ "$1" =~ ^[a-zA-Z0-9_/-]+$ ]]; then
claude-code "Process" --file "$1"
else
echo "Invalid input"
fi
Tool Selection Matrix
| Task | Extension | CLI | Reason |
|---|---|---|---|
| Read single file | ✅ | ❌ | IDE context better |
| Modify 50+ files | ❌ | ✅ | Avoid permission prompts |
| Interactive debug | ✅ | ❌ | IDE integration needed |
| System install | ❌ | ✅ | System access required |
| Batch rename | ❌ | ✅ | Bulk operation |
| Code review | ✅ | ❌ | IDE context needed |
| Generate 20 files | ❌ | ✅ | Avoid repeated prompts |
| Quick typo fix | ✅ | ❌ | Immediate feedback |
| Test suite | Either | ✅ | CLI runs complete suite |
Integration with fstrent_spec_tasks
Task Creation Automation
# Create multiple tasks from PLAN.md
claude-code "Read PLAN.md and create task files" \
--file .fstrent_spec_tasks/PLAN.md \
--output-dir .fstrent_spec_tasks/tasks/
Bulk Task Updates
# Update all task files with new YAML fields
claude-code "Add priority field to all tasks" \
--directory .fstrent_spec_tasks/tasks/ \
--dry-run
# After review
claude-code "Apply task updates" \
--directory .fstrent_spec_tasks/tasks/ \
--auto-approve
Documentation Generation
# Generate sprint summaries
claude-code "Generate sprint summary from completed tasks" \
--directory .fstrent_spec_tasks/tasks/ \
--output docs/SPRINT_SUMMARY.md
Performance Optimization
Parallel Processing
# Process multiple directories in parallel
claude-code "Process models" --directory src/models &
claude-code "Process views" --directory src/views &
claude-code "Process controllers" --directory src/controllers &
wait
echo "All processing complete"
Caching Strategy
# Cache expensive analysis
if [ -f .cache/analysis.json ]; then
analysis=$(cat .cache/analysis.json)
else
claude-code "Analyze codebase" > .cache/analysis.json
fi
# Use cached results
claude-code "Refactor based on analysis" \
--file .cache/analysis.json
Incremental Processing
# Only process changed files
changed_files=$(find src -newer .last_run -name "*.py")
echo "$changed_files" | while read file; do
claude-code "Process file" --file "$file"
done
date > .last_run
Error Handling
Graceful Degradation
Level 1: Retry with adjusted parameters
if ! claude-code "Process files"; then
claude-code "Process files" --verbose
fi
Level 2: Break into smaller batches
if ! claude-code "Process all 500 files"; then
for batch in batch1 batch2 batch3; do
claude-code "Process batch" --pattern "$batch"
done
fi
Level 3: Fall back to extension native
if ! claude-code "Critical operation" 2>error.log; then
echo "Falling back to extension native operations"
# Extension handles with user approval
fi
Activation
Manual Activation
"Use Claude Code CLI to process all these files"
"Leverage CLI for batch operation"
SubAgent Activation
The claude-code-orchestrator SubAgent automatically activates for:
- Batch operations (>10 files)
- System-level tasks
- Complex multi-step workflows
- Tasks requiring >5 permission prompts
Success Metrics
Quantitative
- ✅ 80% reduction in permission prompts
- ✅ 3x faster execution for 50+ file operations
- ✅ <5 second response time for CLI commands
- ✅ 95%+ success rate for strategy decisions
Qualitative
- ✅ Batch processing without interruption
- ✅ System-level automation from VS Code
- ✅ Intelligent workflow orchestration
- ✅ Security-first command execution
Troubleshooting
Issue: CLI Not Found
# Check installation
which claude-code
# Add to PATH if needed
export PATH="$PATH:/path/to/claude-code"
Issue: Permission Denied
# Check permissions
ls -la /path/to/files
# Fix if needed
chmod +x /path/to/files
Issue: Command Hangs
# Use timeout
timeout 300 claude-code "Operation"
# Use non-interactive mode
claude-code "Operation" --non-interactive
Related Resources
Files
- Rule:
.cursor/rules/fstrent_spec_tasks/claude_code_cli.mdc(Cursor version) - Agent:
.cursor/rules/fstrent_spec_tasks/agents/claude_code_orchestrator.mdc(Cursor version) - SubAgent:
.claude/agents/claude-code-orchestrator.md(Claude Code version) - Rules:
.claude/rules/claude_code_cli_integration.md(Claude Code version) - Documentation:
docs/20251028_212220_Cursor_CLAUDE_CODE_CLI_INTEGRATION_GUIDE.md
Related Skills
fstrent-task-management- Task lifecycle managementfstrent-planning- Project planning and PRD creationweb-tools- Browser automation and web scrapingcomputer-use- Desktop automation and GUI control
SubAgents
claude-code-orchestrator- Intelligent CLI orchestration agent
Version: 1.0.0
Created: 2025-10-28
Status: Production Ready
Testing: Pending real-world validation