Loctree is a code intelligence tool that provides semantic understanding of your codebase. Unlike text-based search (grep), loctree understands:
- Where symbols are defined (not just mentioned)
- What depends on each file
- What code is unused (dead code)
- Similar symbols (semantic matching)
| Feature | grep | loctree |
|---|---|---|
| Find text matches | ✓ | ✓ |
| Find definitions | ✗ | ✓ |
| Semantic similarity | ✗ | ✓ |
| Dependency graph | ✗ | ✓ |
| Dead code detection | ✗ | ✓ |
| Impact analysis | ✗ | ✓ |
No. Loctree automatically scans and caches on first use. The first search takes ~15s, subsequent searches take ~0.3s.
Running loct scan manually is optional - it just pre-warms the cache before your first search.
- TypeScript / JavaScript
- Rust
- Python
- Go
- Vue / Svelte
- CSS / SCSS
See supported languages for the full list.
cargo install loctreeOr with Homebrew:
brew install loctreeAdd Cargo's bin directory to your PATH:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc- Open Claude Code in a project
- Search for any symbol (e.g., "useState")
- Check if you see "LOCTREE CONTEXT" in the response
- Or watch the log:
tail -f ~/.claude/logs/loct-hook.log
On first search, loctree scans your entire codebase and creates a cached snapshot in .loctree/. This takes ~15s for a medium-sized project.
Subsequent searches use the cache and complete in ~0.3s.
The hook recognizes:
- PascalCase:
UserService,AuthProvider - camelCase:
useAuth,handleClick - snake_case:
user_service,handle_request - React hooks:
useAuth,useState - Event handlers:
onClick,handleSubmit - Health keywords:
dead,unused,orphan,cycle
Yes! Use pipe | to search for multiple symbols:
useAuth|useSession
The hook will transform this to loct find "useAuth|useSession".
This is loctree's cache directory containing:
snapshot.json- Symbol indexfiles.json- File metadatagraph.json- Dependency graph
It's auto-generated and should be added to .gitignore.
-
Check hooks are executable:
chmod +x ~/.claude/hooks/loct-*.sh
-
Verify settings.json:
cat ~/.claude/settings.json | jq '.hooks.PostToolUse'
-
Restart Claude Code or run
/clear
This message appears only on first search in a project. If it appears repeatedly, check:
- You have write permission in the project directory
- The
.loctree/directory exists after the first search
Check the hook log for errors:
tail -50 ~/.claude/logs/loct-hook.logCommon issues:
loctnot in PATHjqnot installed- Hook script has syntax error
- Ensure you're searching for actual symbol names, not descriptions
- Check if the symbol exists:
loct find "YourSymbol"manually - Verify the project has source files loctree can parse
Yes, environment variables control hook behavior:
# Custom log file location
export LOCT_HOOK_LOG_FILE=~/my-custom.log
# Disable logging
export LOCT_HOOK_LOG_FILE=/dev/nullEdit ~/.claude/settings.json and add a new matcher:
{
"matcher": "YourToolName",
"hooks": [
{
"type": "command",
"command": "bash ~/.claude/hooks/your-hook.sh"
}
]
}Yes! The loct CLI works standalone:
loct find "useAuth" # Find symbol
loct slice src/hooks/auth.ts # File context
loct impact src/hooks/auth.ts # What depends on this
loct health # Dead code check# Update loctree CLI
cargo install loctree --force
# Update hook scripts
cd ~/loctree-plugin && git pull
cp hooks/*.sh ~/.claude/hooks/Loctree handles large codebases well:
- Small (<10K LOC): ~5s initial scan
- Medium (10-100K LOC): ~15s initial scan
- Large (100K-1M LOC): ~60s initial scan
After initial scan, all queries complete in <1s.
No. Hooks run asynchronously after tool completion. Claude receives the context as additional information - it doesn't wait for the hook.
Remove the PostToolUse section from ~/.claude/settings.json to disable all loctree hooks.
Created by M&K (c)2026 VetCoders