You're hunting for every .unwrap() call in a Rust codebase because you're finally migrating to proper error handling. You grep for it. You get 47 results.
Twelve are in comments (// don't unwrap here). Eight are in strings ("call unwrap() to extract"). Three are variable names (let unwrap_result = ...). The actual method calls you wanted? Buried in the noise.
Text search finds characters, not meaning. It can't tell a method call from a comment, a variable from a string literal, Rust from Ruby. It just matches bytes.
Octocode 0.14.0 fixes this. Structural search — AST-powered pattern matching that actually understands your code. Think grep that knows what it's looking at. No extra tools to install. No config files to fight. Just octocode grep and you're matching structure, not strings.
Why Text Search Falls Short
Text search treats code like any other text file. It doesn't understand that $VAR.unwrap() should match an actual method call on a Result or Option — not a substring hiding in a documentation comment.
Structural search knows the difference. It works on the Abstract Syntax Tree — the same representation your compiler uses — so patterns match actual code structures, not character sequences.
You find what you're looking for. Not false positives. Not noise. Just the code that matters.
Meet octocode grep
# Find all unwrap() calls in Rust
octocode grep '$VAR.unwrap()' --lang rust
# Find constructor patterns in JavaScript
octocode grep 'new $CLASS($$$ARGS)' --lang javascript
# Find error handling patterns in Go
octocode grep 'if err != nil { $$$ }' --lang go
Pattern syntax is simple:
$VAR— any single AST node (expression, identifier, whatever)$$$ARGS— zero or more nodes (function arguments, statement blocks)- Literal code — exact structure match
13 languages supported: Rust, JavaScript, TypeScript, Python, Go, Java, C/C++, PHP, Ruby, Lua, Bash, CSS, JSON.
The Rewrite Capability
Here's where it gets interesting. Structural search isn't just for finding — it's for refactoring.
# Preview: Replace unwrap() with expect() across your codebase
octocode grep '$FUNC.unwrap()' \
--lang rust \
--rewrite '$FUNC.expect("reason")'
# Apply the changes in-place
octocode grep '$FUNC.unwrap()' \
--lang rust \
--rewrite '$FUNC.expect("reason")' \
--update-all
The --rewrite template uses metavariables from your search pattern. $FUNC in the rewrite gets replaced with whatever matched $FUNC in the search. Surgical refactoring — precise, automated, and safe.
Why this matters for AI: When Claude or Cursor suggests "we should replace all these unwrap calls with proper error handling," it can now actually do it — not just describe the change, but generate the exact command to make it happen.
Built for AI Agents (No Extra Setup)
Structural search is exposed as an MCP tool called structural_search. Your AI assistant can use it directly:
{
"name": "structural_search",
"description": "AST-based structural code search using ast-grep patterns"
}
Other AST search tools need separate installation and configuration. Octocode's structural search works immediately. No sg CLI to install. No rule files. No YAML. The pattern goes right in the query.
AI agents work best with fewer moving parts. Every external dependency is a failure point. Every config file is friction. Structural search in Octocode is just... there. Ready.
What Else Is New in 0.14.0
Unified Search Architecture
We rewrote the search system from scratch. Branch-aware delta indexing means searching feature branches now properly merges results with the main index — you see what's in your current branch plus relevant context from main. The unified architecture also brings test coverage where there wasn't any before.
More Embedding Models
Added support for MPNet and JinaBERT QK embeddings — high-performance models that punch above their weight class. For teams watching API costs, these give you quality search results with smaller, faster models.
MCP Server Improvements
- Enhanced tool schemas — Better structured outputs for AI consumption
- Automatic repository indexing — The MCP server can now trigger indexing automatically when it detects unindexed repositories
- Improved transport layer — Migrated to the official
rmcpSDK for better stability
Reliability at Scale
- Strict structured LLM outputs — JSON mode with validation ensures AI responses parse correctly
- Automatic retries — Batch operations retry on transient failures
- Better batch processing — Improved memory efficiency for large codebases
Clear Commands Get More Power
The clear command now supports targeted cleanup:
# Clear just the commit index
octocode clear --mode commits
# Clear just GraphRAG data
octocode clear --mode graphrag
Try It Now
Update to 0.14.0:
# Homebrew
brew upgrade octocode
# Or reinstall with the universal installer
curl -fsSL https://raw.githubusercontent.com/Muvon/octocode/master/install.sh | sh
Then try structural search on your codebase:
# Find patterns worth refactoring
octocode grep 'console.log($ARG)' --lang javascript
# Check for error handling gaps
octocode grep '$VAR.unwrap()' --lang rust
# Find constructor injection patterns
octocode grep 'new $CLASS($$$)' --lang typescript
FAQ
What makes structural search different from regex?
Regex matches characters. Structural search matches AST nodes. $VAR.unwrap() finds actual method calls, not comments containing that string, not variable names that happen to include "unwrap", not documentation examples. It understands code structure because it parses the code the same way your compiler does.
Do I need to install anything else?
No. Structural search is built into Octocode 0.14.0. No separate CLI tools, no configuration files, no YAML rule definitions. The octocode grep command works immediately after upgrading.
Can I use this with Claude, Cursor, or other AI assistants?
Yes. Structural search is exposed as an MCP tool. Any MCP-compatible assistant can call it directly. The tool schema includes the pattern language, so AI assistants understand how to construct valid queries.
What languages are supported?
Rust, JavaScript, TypeScript, Python, Go, Java, C/C++, PHP, Ruby, Lua, Bash, CSS, and JSON. The underlying engine uses Tree-sitter grammars, so adding new languages is straightforward if you need one not on the list.
How does --rewrite work?
The rewrite template uses metavariables from your search pattern. If your search is $FUNC.unwrap() and matches result.unwrap(), then $FUNC captures result. The rewrite $FUNC.expect("reason") becomes result.expect("reason"). Run with --update-all to apply changes in-place, or without it to preview first.
Is this safe to run on production code?
Always preview changes before applying them. Structural search is precise, but precision doesn't mean the transformation is semantically correct for your use case. Review the --rewrite output, run your tests, commit to git first. The tool is surgical — you're still responsible for knowing what the surgery should accomplish.
What's the performance like?
Fast. AST parsing happens via Tree-sitter, which is designed for editor responsiveness. Searching a 100,000-line codebase takes seconds, not minutes. Search is parallelized across files and incremental indexing means subsequent searches are faster.
How does this fit with Octocode's other features?
Structural search complements semantic search and GraphRAG. Use semantic search when you know what you're looking for but not where ("how does authentication work?"). Use structural search when you know the pattern ($USER.auth($TOKEN)). Use GraphRAG when you need to understand relationships between files. Together they cover the full spectrum of code exploration.
What's Next
We're building toward one thing: make codebases fully understandable to AI. Structural search is the latest piece, but there's more coming.
Multi-file refactoring patterns. Cross-language symbol tracking. Deeper MCP integration so AI assistants can not just find code but transform it with confidence.
If you're using Octocode, upgrade to 0.14.0 and try octocode grep on your codebase. If you're not using it yet — grab it here. It's open source, runs locally, and it's what we use every day to build Octomind.
Octocode is open source (Apache 2.0) and available at github.com/Muvon/octocode. Built by Muvon.



