> ## Documentation Index
> Fetch the complete documentation index at: https://docs.initrepo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI Commands Reference

> Complete reference for all InitRepo CLI commands with examples and options

## Command Overview

The InitRepo CLI provides comprehensive commands for code analysis, documentation generation, and safe code modifications. All commands support both human-readable and JSON output formats for seamless AI integration.

### Command Categories

<CardGroup cols={2}>
  <Card title="Analysis Commands" icon="magnifying-glass">
    Deep codebase analysis including structure, complexity, and quality metrics
  </Card>

  <Card title="Generation Commands" icon="document-text">
    Automated documentation and structure generation from code analysis
  </Card>

  <Card title="Modification Commands" icon="wrench">
    Safe code modifications using AST-based operations
  </Card>

  <Card title="Utility Commands" icon="cog">
    Project scaffolding, configuration, and task management
  </Card>
</CardGroup>

## Core Analysis Commands

### `analyze`

Performs comprehensive codebase analysis and creates a `.initrepo/` directory with results.

```bash theme={null}
# Basic analysis
initrepo-cli analyze

# Analysis with JSON output
initrepo-cli analyze --format=json

# Include specific patterns
initrepo-cli analyze --include "src/**/*.js"

# Exclude patterns
initrepo-cli analyze --exclude "**/*.test.js"
```

**Options:**

* `--format`: Output format (text, json)
* `--include`: Include file patterns
* `--exclude`: Exclude file patterns
* `--max-depth`: Maximum directory depth
* `--verbose`: Detailed output

### `generate-structure`

Creates visual project structure documentation.

<Tabs>
  <Tab title="Tree Format">
    ```bash theme={null}
    # Human-readable tree view
    initrepo-cli generate-structure --format=tree

    # Limited depth
    initrepo-cli generate-structure --format=tree --max-depth=3

    # Save to file
    initrepo-cli generate-structure --format=tree > project-structure.txt
    ```
  </Tab>

  <Tab title="JSON Format">
    ```bash theme={null}
    # Machine-readable format
    initrepo-cli generate-structure --format=json

    # Save to file for AI consumption
    initrepo-cli generate-structure --format=json > structure.json

    # Pretty printed
    initrepo-cli generate-structure --format=json | jq '.'
    ```
  </Tab>
</Tabs>

**Options:**

* `--format`: tree, json
* `--max-depth`: Maximum directory depth (default: 5)
* `--output`: Output file path
* `--include-hidden`: Include hidden files and directories

### `analyze-complexity`

Analyzes code complexity and identifies potential issues.

```bash theme={null}
# Basic complexity analysis
initrepo-cli analyze-complexity

# Set complexity threshold
initrepo-cli analyze-complexity --threshold=15

# With recommendations
initrepo-cli analyze-complexity --with-recommendations

# JSON output for AI processing
initrepo-cli analyze-complexity --format=json
```

**Options:**

* `--threshold`: Complexity threshold (default: 10)
* `--with-recommendations`: Include improvement suggestions
* `--format`: text, json
* `--include`: File patterns to analyze
* `--exclude`: File patterns to exclude

### `analyze-imports`

Analyzes import statements and identifies issues.

```bash theme={null}
# Full import analysis
initrepo-cli analyze-imports

# Find unused imports only
initrepo-cli analyze-imports --unused-only

# Check for circular dependencies
initrepo-cli analyze-imports --circular-only

# JSON format for automation
initrepo-cli analyze-imports --format=json
```

**Options:**

* `--unused-only`: Show only unused imports
* `--circular-only`: Show only circular dependencies
* `--format`: text, json
* `--fix`: Automatically fix issues (use with caution)

### `validate-structure`

Validates project structure against best practices.

```bash theme={null}
# Basic validation
initrepo-cli validate-structure

# Strict validation
initrepo-cli validate-structure --strict

# JSON output with score
initrepo-cli validate-structure --format=json
```

**Output includes:**

* Structure score (0-100)
* Best practice violations
* Improvement recommendations
* Compliance status

## Documentation Commands

### `deps`

Analyzes and documents project dependencies.

<AccordionGroup>
  <Accordion title="Basic Usage">
    ```bash theme={null}
    # All dependencies
    initrepo-cli deps

    # Runtime dependencies only
    initrepo-cli deps --type=runtime

    # Development dependencies only
    initrepo-cli deps --type=dev
    ```
  </Accordion>

  <Accordion title="Output Formats">
    ```bash theme={null}
    # Markdown table format
    initrepo-cli deps --format=markdown

    # JSON format
    initrepo-cli deps --format=json

    # Export to file
    initrepo-cli deps --format=json > dependencies.json
    ```
  </Accordion>
</AccordionGroup>

### `find-symbol`

Searches for symbols (functions, classes, variables) in the codebase.

```bash theme={null}
# Find all occurrences of a symbol
initrepo-cli find-symbol "getUserById"

# Find by symbol type
initrepo-cli find-symbol "User" --type=class

# Exact match only
initrepo-cli find-symbol "authenticate" --exact

# JSON output
initrepo-cli find-symbol "validateInput" --format=json
```

**Options:**

* `--type`: Symbol type (function, class, variable, interface)
* `--exact`: Exact matching only
* `--case-sensitive`: Case-sensitive search
* `--format`: text, json

### `get-code`

Extracts code blocks with context.

```bash theme={null}
# Get function with minimal context
initrepo-cli get-code "processPayment"

# Get with full context
initrepo-cli get-code "UserService" --context=full

# JSON format for AI processing
initrepo-cli get-code "validateUser" --context=minimal --format=json
```

**Context levels:**

* `minimal`: Function/class only
* `dependencies`: Include immediate dependencies
* `full`: Include complete context and relationships

## Safe Modification Commands

### `safe-rename`

Safely renames symbols throughout the codebase using AST analysis.

<Steps>
  <Step title="Preview Changes">
    ```bash theme={null}
    # Preview rename operation
    initrepo-cli safe-rename oldFunctionName newFunctionName --dry-run
    ```
  </Step>

  <Step title="Apply Rename">
    ```bash theme={null}
    # Apply the rename
    initrepo-cli safe-rename oldFunctionName newFunctionName

    # With backup
    initrepo-cli safe-rename oldFunctionName newFunctionName --backup
    ```
  </Step>

  <Step title="Verify Changes">
    ```bash theme={null}
    # Find references to new name
    initrepo-cli find-references newFunctionName
    ```
  </Step>
</Steps>

**Options:**

* `--dry-run`: Preview changes without applying
* `--backup`: Create backup before changes
* `--scope`: Limit scope (file, directory, project)
* `--format`: text, json

### `manage-imports`

Manages import statements automatically.

```bash theme={null}
# Remove unused imports
initrepo-cli manage-imports --remove-unused

# Organize imports
initrepo-cli manage-imports --organize

# Both operations
initrepo-cli manage-imports --remove-unused --organize

# Preview changes
initrepo-cli manage-imports --remove-unused --dry-run
```

**Options:**

* `--remove-unused`: Remove unused import statements
* `--organize`: Sort and group imports
* `--dry-run`: Preview changes
* `--backup`: Create backup before changes

## Utility Commands

### `scaffold`

Creates new projects with best practices and templates.

<Tabs>
  <Tab title="Web Projects">
    ```bash theme={null}
    # React application
    initrepo-cli scaffold react my-app

    # Next.js application
    initrepo-cli scaffold nextjs web-app

    # Node.js API
    initrepo-cli scaffold node-api api-server

    # Vue.js application
    initrepo-cli scaffold vue my-vue-app

    # Angular application
    initrepo-cli scaffold angular admin-panel
    ```
  </Tab>

  <Tab title="Backend & APIs">
    ```bash theme={null}
    # Express.js API
    initrepo-cli scaffold express-api backend

    # FastAPI (Python)
    initrepo-cli scaffold fastapi my-api

    # Django application
    initrepo-cli scaffold django web-app
    ```
  </Tab>

  <Tab title="Libraries & Tools">
    ```bash theme={null}
    # TypeScript library
    initrepo-cli scaffold typescript-lib my-lib

    # Python automation
    initrepo-cli scaffold python-automation script

    # React component library
    initrepo-cli scaffold react-components ui-lib
    ```
  </Tab>
</Tabs>

**Options:**

* Project templates are pre-configured with best practices
* Includes package.json, configuration files, and basic project structure
* Ready for immediate development and deployment

### `suggest-refactor`

Provides AI-powered refactoring suggestions.

```bash theme={null}
# All suggestions
initrepo-cli suggest-refactor

# High priority only
initrepo-cli suggest-refactor --min-severity=high

# Specific categories
initrepo-cli suggest-refactor --category=performance

# JSON format
initrepo-cli suggest-refactor --format=json
```

**Categories:**

* `performance`: Performance improvements
* `maintainability`: Code maintainability
* `security`: Security enhancements
* `style`: Code style consistency

### `find-references`

Finds all references to a symbol.

```bash theme={null}
# Find all references
initrepo-cli find-references "calculateTotal"

# Include definitions
initrepo-cli find-references "User" --include-definitions

# JSON output
initrepo-cli find-references "validateInput" --format=json
```

## Global Options

All commands support these global options:

```bash theme={null}
# Common options across all commands
initrepo-cli <command> [options]
  --help          Show help for command
  --version       Show CLI version
  --format        Output format: text, json
  --output        Output to file
  --verbose       Verbose output
  --quiet         Suppress non-error output
  --dry-run       Preview changes without applying (where applicable)
```

## Advanced Usage Examples

### Automated Quality Analysis

```bash theme={null}
#!/bin/bash
# quality-check.sh - Comprehensive quality assessment

echo "🔍 Running automated quality checks..."

# Structure validation
initrepo-cli validate-structure --format=json > validation.json

# Complexity analysis
initrepo-cli analyze-complexity --threshold=15 --format=json > complexity.json

# Import analysis
initrepo-cli analyze-imports --format=json > imports.json

# Generate report
echo "✅ Quality check complete. Check JSON files for results."
```

### CI/CD Integration

```yaml theme={null}
# GitHub Actions workflow
- name: InitRepo Analysis
  run: |
    initrepo-cli validate-structure --format=json > structure.json
    initrepo-cli analyze-complexity --threshold=10 --format=json > complexity.json
    
    # Quality gates
    score=$(jq '.data.score' structure.json)
    if [ "$score" -lt 80 ]; then
      echo "Structure score too low: $score/100"
      exit 1
    fi
```

### AI Assistant Integration

```bash theme={null}
# Generate AI-ready context
initrepo-cli analyze --format=json > project-context.json
initrepo-cli get-code "UserService" --context=full --format=json >> ai-context.json

# Use with AI coding assistants
cat ai-context.json | ai-assistant "Analyze this code structure"
```

## Command Aliases

Common command aliases for faster usage:

```bash theme={null}
# Add to your shell profile (.bashrc, .zshrc)
alias ira="initrepo-cli analyze"
alias irgs="initrepo-cli generate-structure"
alias irac="initrepo-cli analyze-complexity"
alias irai="initrepo-cli analyze-imports"
alias irsr="initrepo-cli safe-rename"
```

## Best Practices

### For Development Workflow

1. **Run analysis regularly**: `initrepo-cli analyze` should be part of your development routine
2. **Use JSON output**: Enable better integration with scripts and AI assistants
3. **Preview before modifying**: Always use `--dry-run` for modification commands
4. **Set appropriate thresholds**: Adjust complexity thresholds based on your project needs

### For Team Collaboration

1. **Standardize configurations**: Use consistent `.initrepoignore` files across team
2. **Integrate with CI/CD**: Automate quality checks in your pipelines
3. **Share JSON outputs**: Use structured outputs for team analysis and reporting
4. **Document decisions**: Use refactoring suggestions to document architectural decisions

## Next Steps

<CardGroup cols={2}>
  <Card title="Advanced Features" icon="rocket" href="/cli/advanced">
    Explore CI/CD integration, team workflows, and automation scripts
  </Card>

  <Card title="Configuration Guide" icon="cogs" href="/platform/configuration">
    Customize CLI behavior for your specific needs
  </Card>
</CardGroup>
