# Commands Reference Complete reference for all Octocode commands with examples and options. ## Core Commands ### `octocode index` Index your codebase for semantic search. ```bash # Basic indexing octocode index # Verbose output octocode index --verbose # Force reindex (ignore cache) octocode index --force # Index specific directory octocode index /path/to/project ``` **What it does:** - Scans all supported files in your project - Extracts code symbols and structure using Tree-sitter - Generates embeddings for semantic search - Builds persisted knowledge-graph relationships (if GraphRAG is enabled) - Stores everything in local LanceDB database - **Safe file discovery** - Prevents infinite recursion from symlinks - **Respects ignore patterns** - Honors .gitignore and .noindex files ### `octocode search` Semantic search across your codebase. ```bash # Basic search octocode search "user authentication" # Multi-query search (NEW!) octocode search "authentication" "middleware" octocode search "jwt" "token" "validation" # Search specific content types octocode search "database connection" --mode code octocode search "API documentation" --mode docs octocode search "configuration" --mode text octocode search "error handling" --mode all octocode search "mcp server" --mode commits # Control result details octocode search "auth" --detail-level signatures # Function signatures only octocode search "auth" --detail-level partial # Smart truncation (default) octocode search "auth" --detail-level full # Complete implementations # Adjust similarity and results octocode search "auth" --threshold 0.7 --max-results 10 # Output formats octocode search "auth" --json # JSON output octocode search "auth" --md # Markdown output # Symbol expansion octocode search "user authentication" --expand ``` **Search modes:** - `all` - Search across all content types, excluding commits (default) - `code` - Search only in code blocks - `docs` - Search only in documentation files - `text` - Search only in plain text files - `commits` - Search git commit history (messages, files, AI descriptions) ### `octocode view` View code signatures and structure. ```bash # View current directory octocode view # View specific files with patterns octocode view "src/**/*.rs" octocode view "**/*.py" octocode view "src/auth/*.ts" # Output formats octocode view --json # JSON format octocode view --md # Markdown format octocode view "src/**/*.rs" --md # Specific files in markdown ``` ### `octocode grep` Structural code search using ast-grep patterns. Finds code by AST structure, not text. ```bash # Find all .unwrap() calls in Rust octocode grep '$FUNC.unwrap()' --lang rust # Find all `new` expressions in JavaScript octocode grep 'new $CLASS($$$ARGS)' --lang javascript # Find println calls in Java octocode grep 'System.out.println($ARG)' --lang java # Search specific paths with context lines octocode grep 'return nil' --lang go --paths 'src/**/*.go' -C 2 # JSON output octocode grep 'puts $ARG' --lang ruby --json ``` **Pattern syntax (ast-grep):** - `$VAR` — matches any single AST node - `$$REST` — matches zero or more nodes in a sequence - `$$$ARGS` — matches zero or more function arguments - Literal code — matches exact structure (e.g. `return 0`, `x = 1`) **Rewrite (refactoring):** ```bash # Preview rewrites (dry run) octocode grep '$FUNC.unwrap()' --lang rust --rewrite '$FUNC.expect("reason")' # Apply rewrites in-place octocode grep '$FUNC.unwrap()' --lang rust --rewrite '$FUNC.expect("reason")' --update-all # Rewrite with path filter octocode grep 'console.log($ARG)' --lang javascript --rewrite 'logger.info($ARG)' --paths 'src/**/*.js' --update-all ``` **Options:** - `--lang ` — Language to search (auto-detected from extensions if omitted) - `--paths ` — File paths or glob patterns to search - `-C, --context ` — Number of context lines around matches - `--rewrite