VS Code Integration
Use ctx with Visual Studio Code for enhanced code intelligence.
Overview
While ctx is primarily a CLI tool, it integrates well with VS Code through:
- Terminal integration - Run ctx commands directly
- Tasks - Automated indexing and auditing
- Extensions - Use with AI coding assistants
Terminal Commands
Open the integrated terminal (Ctrl+`` ) and run ctx commands:
# Index the workspace
ctx index
# Search for symbols
ctx search "handleRequest"
# Get context for current work
ctx smart "what I'm working on"VS Code Tasks
Configure Tasks
Create .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "ctx: Index",
"type": "shell",
"command": "ctx index",
"group": "build",
"problemMatcher": []
},
{
"label": "ctx: Index (Watch)",
"type": "shell",
"command": "ctx index --watch",
"isBackground": true,
"problemMatcher": []
},
{
"label": "ctx: Audit",
"type": "shell",
"command": "ctx audit",
"group": "test",
"problemMatcher": []
},
{
"label": "ctx: Search",
"type": "shell",
"command": "ctx search \"${input:searchQuery}\"",
"problemMatcher": []
},
{
"label": "ctx: Smart Context",
"type": "shell",
"command": "ctx smart \"${input:taskDescription}\" --dry-run",
"problemMatcher": []
}
],
"inputs": [
{
"id": "searchQuery",
"type": "promptString",
"description": "Symbol to search for"
},
{
"id": "taskDescription",
"type": "promptString",
"description": "Task description for smart context"
}
]
}Run Tasks
- Press
Ctrl+Shift+P(orCmd+Shift+Pon macOS) - Type "Tasks: Run Task"
- Select a ctx task
Keyboard Shortcuts
Add to .vscode/keybindings.json:
[
{
"key": "ctrl+shift+i",
"command": "workbench.action.tasks.runTask",
"args": "ctx: Index"
},
{
"key": "ctrl+shift+a",
"command": "workbench.action.tasks.runTask",
"args": "ctx: Audit"
}
]With GitHub Copilot
Use ctx to provide context to Copilot Chat:
- Run
ctx smart "your task"to get relevant files - Open those files in VS Code
- Ask Copilot about them with full context
Workflow Example
# Get files for your task
ctx smart "add caching to database queries" --dry-run
# Open the suggested files
code src/db/queries.rs src/cache.rs
# Now Copilot has the right context!With Continue.dev
Continue is an open-source AI coding assistant that can use ctx.
Configure Continue
Add to .continue/config.json:
{
"contextProviders": [
{
"name": "ctx",
"params": {
"command": "ctx smart"
}
}
]
}Usage
In Continue chat:
@ctx add user authentication- Get relevant files for the task
Code Lens Integration
While ctx doesn't provide a VS Code extension directly, you can use the output in your workflow:
Find Callers
# Find what calls a function
ctx query callers handleRequest
# Output shows file:line references
# Ctrl+click in terminal to navigateImpact Analysis
# See what would be affected by changes
ctx query impact validateInput
# Review affected files before modifyingWorkspace Settings
Add to .vscode/settings.json:
{
"terminal.integrated.env.osx": {
"PATH": "${env:PATH}:/usr/local/bin"
},
"files.watcherExclude": {
"**/.ctx/**": true
}
}Auto-Index on Save
Create a task that runs on folder open:
{
"label": "ctx: Auto Index",
"type": "shell",
"command": "ctx index",
"runOptions": {
"runOn": "folderOpen"
},
"presentation": {
"reveal": "silent"
}
}Or use the watch mode:
{
"label": "ctx: Watch",
"type": "shell",
"command": "ctx index --watch",
"isBackground": true,
"runOptions": {
"runOn": "folderOpen"
}
}Tips
- Use watch mode - Run
ctx index --watchin a terminal for auto-updates - Leverage terminal links - File:line output is clickable
- Create snippets - Save common ctx commands as VS Code snippets
- Use tasks - Automate common workflows
- Combine with AI - Use ctx output to provide context to AI assistants
Troubleshooting
ctx command not found
- Ensure ctx is in your PATH
- Restart VS Code
- Check terminal profile settings
Slow indexing
- Add large directories to
.contextignore - Use
.gitignorepatterns - Enable watch mode for incremental updates