ai_project_template / fstrent_spec_tasks
Cursor rule1 starsChanged 13 months agoMITView on GitHub
Integration rule for using Claude Code CLI from Cursor
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository40 other files it gives its agents.
- agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/always.mdcCursor rule
- .cursor/rules/atlassian/atlassian_integration.mdcCursor rule
- .cursor/rules/computer_use/computer_use_agent.mdcCursor rule
- .cursor/rules/documentation.mdcCursor rule
- .cursor/rules/github/github_integration.mdcCursor rule
- .cursor/rules/powershell.mdcCursor rule
- .cursor/rules/silicon_valley_personality.mdcCursor rule
- .cursor/rules/virtual_environments_python.mdCursor rule
- .cursor/rules/web_tools/web_tools.mdcCursor rule
- artifacts-builderSkill
- atlassian-integrationSkill
- claude-code-cli-integrationSkill
- computer-use-agentSkill
- deep-researchSkill
- fstrent-code-reviewerSkill
- fstrent-planningSkill
- fstrent-qaSkill
- fstrent-task-managementSkill
- github-integrationSkill
- hanx-database-toolsSkill
- hanx-knowledge-baseSkill
- hanx-mediawikiSkill
- hanx-youtube-researcherSkill
- internal-commsSkill
- mcp-builderSkill
- oracle-apex-developmentSkill
- patent-filing-aiSkill
- Project SetupSkill
- research-methodologySkill
- skill-creatorSkill
- startup-business-formationSkill
- startup-product-developmentSkill
- startup-resource-accessSkill
- startup-vc-fundraisingSkill
- template-skillSkill
- web-toolsSkill
- youtube-rag-storageSkill
- youtube-video-analysisSkill
The file
We split this claude_code_cli.mdc into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 100
When VS Code extension would require multiple permission prompts, use CLI instead.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: 'Integration rule for using Claude Code CLI from Cursor'
globs: []
alwaysApply: false
---
# Claude Code CLI Integration
This rule enables Cursor to leverage Claude Code CLI for operations that benefit from unrestricted system access.
## When to Use Claude Code CLI
**✅ Use Claude Code CLI for**:
- Batch file operations requiring many permission prompts in VS Code (50+ files)
- Complex system-level tasks (package installation, system configuration)
- MCP server interactions requiring full access
- Automation scripts that would be blocked in sandboxed environment
- Operations requiring shell scripting or piping
- Bulk task file creation/updates in fstrent_spec_tasks
- Large-scale refactoring operations
- System-wide configuration changes
**❌ Don't use Claude Code CLI for**:
- Simple file reads/writes (use Cursor's native tools)
- Single file operations
- Interactive debugging sessions
- Tasks requiring IDE context (open files, cursor position)
- Quick edits or minor changes
- Operations that need immediate IDE feedback
## Command Patterns
### Basic Usage
```bash
# Execute Claude Code CLI command
claude-code "Your instruction here"
# With specific file context
claude-code "Analyze this file" --file path/to/file.py
# With directory context
claude-code "Refactor all Python files" --directory src/
# With output capture
claude-code "Generate report" > output.txt
# Dry run first (recommended for destructive operations)
claude-code "Refactor codebase" --dry-run
claude-code "Refactor codebase" --auto-approve # After reviewing dry run
```
### Integration Patterns
#### Pattern 1: Batch File Processing
```bash
# Process multiple files that would require many VS Code permissions
claude-code "Add type hints to all Python files in src/" \
--directory src/ \
--auto-approve
```
#### Pattern 2: System Configuration
```bash
# System-level operations
claude-code "Install and configure development environment" \
--auto-approve
```
#### Pattern 3: MCP Server Interaction
```bash
# Direct MCP operations
claude-code "Use MCP to query database and generate report" \
--mcp-server fstrent_mcp_mysql
```
#### Pattern 4: Pipeline Integration
```bash
# Combine with other CLI tools
claude-code "Extract data from logs" | jq '.' | \
claude-code "Analyze this JSON and generate insights"
```
#### Pattern 5: Context Gathering + Batch Execution
```bash
# Cursor gathers context
echo "Current project structure analysis..." > context.txt
# CLI performs bulk operations
claude-code "Process based on context.txt" \
--file context.txt \
--directory src/
# Cursor validates results
echo "Validating results..."
```
## Best Practices
### 1. Use for Unrestricted Access
When VS Code extension would require multiple permission prompts, use CLI instead.
**Example**: Refactoring 150 Python files
```bash
# VS Code extension: 150+ permission prompts
# CLI: Single command execution
claude-code "Refactor all Python imports according to plan.md" \
--file refactor_plan.md \
--directory src/ \
--dry-run # Review first
# After approval
claude-code "Apply refactoring" \
--file refactor_plan.md \
--directory src/ \
--auto-approve
```
### 2. Capture Context First
```bash
# Cursor reads current state and generates plan
# CLI performs bulk operations
# Step 1: Cursor analyzes
cat > execution_plan.md << EOF
# Execution Plan
- Files to process: $(find src -name "*.py" | wc -l)
- Changes: Update import structure
- Validation: Run tests after
EOF
# Step 2: CLI executes
claude-code "Execute plan" --file execution_plan.md
```
### 3. Verify Before Execution
For destructive operations, validate command before running:
```bash
# Dry run first
claude-code "Preview changes for refactoring" --dry-run
# Review output, then execute
claude-code "Execute refactoring" --auto-approve
```
### 4. Error Handling
```bash
# Capture errors for Cursor to handle
if ! claude-code "Risky operation" 2>error.log; then
echo "Operation failed, analyzing error..."
# Cursor analyzes error.log and decides next steps
cat error.log
fi
```
### 5. Progress Tracking
```bash
# For long operations, provide progress updates
claude-code "Process large dataset with progress indicators" \
--directory data/ \
--verbose
```
## Security Considerations
**⚠️ CRITICAL**: Claude Code CLI has full system access.
### Security Checklist
- ✅ Review commands before execution
- ✅ Use `--dry-run` for destructive operations
- ✅ Avoid passing sensitive data in command line (use files instead)
- ✅ Validate file paths to prevent directory traversal
- ✅ Never use `--auto-approve` for unreviewed operations
- ✅ Use environment variables for sensitive configuration
- ✅ Log all CLI operations for audit trail
- ❌ Never hardcode credentials in commands
- ❌ Never execute commands from untrusted sources
- ❌ Never bypass security checks for convenience
### Safe Command Examples
**✅ SAFE** - Uses file for context, validates paths:
```bash
claude-code "Process files in validated directory" \
--file context.txt \
--directory /validated/path
```
**❌ UNSAFE** - Accepts user input directly:
```bash
# BAD: Could execute arbitrary commands
user_input="$1"
claude-code "$user_input" --auto-approve
```
**✅ SAFE** - Validates and sanitizes input:
```bash
# GOOD: Validates input first
if [[ "$1" =~ ^[a-zA-Z0-9_/-]+$ ]]; then
claude-code "Process validated input" --file "$1"
else
echo "Invalid input"
fi
```
## Tool Selection Matrix
| Task | Use Cursor | Use Claude CLI | Reason |
|------|------------|----------------|--------|
| Read single file | ✅ | ❌ | Faster, no overhead |
| Modify 50+ files | ❌ | ✅ | Avoid permission prompts |
| Interactive debugging | ✅ | ❌ | IDE context needed |
| System package install | ❌ | ✅ | Requires system access |
| MCP database query | Either | Either | Both have MCP access |
| Batch file renaming | ❌ | ✅ | Bulk operation |
| Code review current file | ✅ | ❌ | IDE context better |
| Generate 20 new files | ❌ | ✅ | Avoid repeated prompts |
| Quick typo fix | ✅ | ❌ | Immediate feedback |
| Large-scale refactor | ❌ | ✅ | Batch processing |
| Test single function | ✅ | ❌ | IDE integration |
| Test entire suite | Either | ✅ | CLI can run complete suite |
## Integration with fstrent_spec_tasks
### Task Creation via CLI
```bash
# Create multiple tasks from plan
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
# Review task files, then approve
claude-code "Create task files" \
--file .fstrent_spec_tasks/PLAN.md \
--output-dir .fstrent_spec_tasks/tasks/ \
--auto-approve
```
### Bulk Task Updates
```bash
# Update all pending tasks to new format
claude-code "Update all task files to include new YAML fields" \
--directory .fstrent_spec_tasks/tasks/ \
--dry-run
# After review
claude-code "Apply task updates" \
--directory .fstrent_spec_tasks/tasks/ \
--auto-approve
```
### Documentation Generation
```bash
# Generate documentation from codebase
claude-code "Analyze codebase and generate API documentation" \
--directory src/ \
--output docs/API_DOCUMENTATION.md
# Generate task summaries
claude-code "Generate task completion summary for sprint" \
--directory .fstrent_spec_tasks/tasks/ \
--output docs/SPRINT_SUMMARY.md
```
### Feature File Creation
```bash
# Create feature files from PLAN.md
claude-code "Create feature files for all features in PLAN.md" \
--file .fstrent_spec_tasks/PLAN.md \
--output-dir .fstrent_spec_tasks/features/
```
## Performance Optimization
### Parallel Processing
```bash
# Process file groups in parallel
for group in group1 group2 group3; do
claude-code "Process $group" --directory $group &
done
wait
echo "All groups processed"
```
### Caching Strategy
```bash
# Cache analysis results
if [ ! -f .cache/analysis.json ]; then
claude-code "Analyze codebase structure" > .cache/analysis.json
fi
# Use cached results
claude-code "Refactor based on cached analysis" \
--file .cache/analysis.json
```
### Batch Operations
```bash
# Group related operations
claude-code "Batch process: lint, format, update imports" \
--directory src/ \
--batch-mode
```
## Error Recovery Patterns
### Pattern 1: Graceful Degradation
```bash
# Try CLI first, fall back to Cursor if needed
if ! claude-code "Bulk operation" 2>error.log; then
echo "CLI failed, falling back to Cursor native operations"
# Cursor handles operation in smaller batches
fi
```
### Pattern 2: Retry with Smaller Batches
```bash
# If bulk operation fails, split into chunks
if ! claude-code "Process all 500 files"; then
echo "Breaking into smaller batches..."
for batch in batch_*.txt; do
claude-code "Process batch" --file $batch
done
fi
```
### Pattern 3: Checkpoint and Resume
```bash
# Save progress for resumable operations
claude-code "Process files with checkpoints" \
--directory src/ \
--checkpoint-file .progress.json
# Resume from checkpoint if interrupted
claude-code "Resume from checkpoint" \
--checkpoint-file .progress.json
```
## Common Use Cases
### Use Case 1: Large-Scale Refactoring
```bash
# Refactor 150 Python files to new import structure
# Cursor: Analyze structure, generate plan
# CLI: Execute bulk refactoring
# Step 1: Cursor generates plan
cat > refactor_plan.md << EOF
# Refactoring Plan
- Old: from utils import helper
- New: from src.utils.helpers import helper
- Files: 150
EOF
# Step 2: CLI executes
claude-code "Refactor according to plan" \
--file refactor_plan.md \
--directory src/ \
--dry-run
# Step 3: Review and approve
claude-code "Apply refactoring" \
--file refactor_plan.md \
--directory src/ \
--auto-approve
# Step 4: Cursor validates
echo "Running tests to validate refactoring..."
```
### Use Case 2: System Environment Setup
```bash
# Setup development environment
# CLI handles system-level operations
claude-code "Install Python 3.11, uv, configure virtual environment" \
--auto-approve
claude-code "Install project dependencies from requirements.txt" \
--file requirements.txt
# Cursor validates installation
echo "Validating environment setup..."
```
### Use Case 3: Documentation Generation
```bash
# Generate comprehensive API documentation
# CLI analyzes entire codebase at once
claude-code "Analyze all Python files and generate API docs with examples" \
--directory src/ \
--output docs/API_DOCUMENTATION.md
# Cursor validates formatting
echo "Validating documentation format..."
```
### Use Case 4: Task Automation
```bash
# Automate task file creation for sprint
# CLI creates all tasks from plan
claude-code "Create task files for Sprint 5 features" \
--file .fstrent_spec_tasks/PLAN.md \
--output-dir .fstrent_spec_tasks/tasks/ \
--filter "sprint:5"
# Cursor updates TASKS.md
echo "Updating TASKS.md with new tasks..."
```
## Troubleshooting
### Issue: CLI Not Found
```bash
# Check if CLI is installed
which claude-code
# If not found, install or add to PATH
export PATH="$PATH:/path/to/claude-code"
```
### Issue: Permission Denied
```bash
# Check file permissions
ls -la /path/to/files
# Fix permissions if needed
chmod +x /path/to/files
```
### Issue: Command Hangs
```bash
# Use timeout to prevent hanging
timeout 300 claude-code "Long running operation"
# Check for interactive prompts
claude-code "Operation" --non-interactive
```
### Issue: Unexpected Results
```bash
# Always dry run first
claude-code "Complex operation" --dry-run
# Increase verbosity for debugging
claude-code "Operation" --verbose --debug
```
## Integration with Other Tools
### Git Integration
```bash
# Automated commit with grouped changes
claude-code "Process files and stage changes" \
--directory src/ \
--auto-stage
# Cursor creates commit
git commit -m "Batch refactoring via CLI"
```
### Testing Integration
```bash
# Run tests after CLI operations
claude-code "Refactor code" --directory src/
pytest tests/ -v
```
### CI/CD Integration
```bash
# Use in CI/CD pipelines
claude-code "Generate deployment artifacts" \
--output-dir dist/ \
--production-mode
```
## Monitoring and Logging
### Operation Logging
```bash
# Log all CLI operations
claude-code "Operation" 2>&1 | tee operation.log
# Structured logging
claude-code "Operation" \
--log-level info \
--log-file operations.log
```
### Performance Metrics
```bash
# Track execution time
start_time=$(date +%s)
claude-code "Operation"
end_time=$(date +%s)
echo "Execution time: $((end_time - start_time)) seconds"
```
### Success Rate Tracking
```bash
# Track success/failure rates
claude-code "Operation" && echo "SUCCESS" >> metrics.log || echo "FAILURE" >> metrics.log
```
---
*This rule provides comprehensive guidelines for when and how to use Claude Code CLI from Cursor to leverage unrestricted system access for appropriate tasks while maintaining security and efficiency.*
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

