AutoPilot AI
AutoPilot AI is a VS Code extension that adds a sidebar chat assistant for coding tasks. It can answer general questions, explain selected code, refactor snippets, generate documentation, and apply generated code into the active editor.
Features
- Sidebar chat view inside VS Code (
AutoPilot AI activity bar item)
- OpenAI-backed chat with API-key sign-in flow
- Context-aware prompting:
none: no editor context for general questions
selection: selected code context when relevant
file: current file context for file-wide questions
- Hybrid request routing:
- Heuristic classifier
- Optional mini-model router for ambiguous requests
- Task-aware response depth:
- Selection-based editor actions:
- Explain selection
- Refactor selection
- Document selection
- "Apply Code" button on generated code blocks to insert/replace in editor
Requirements
- VS Code
^1.100.0
- Node.js 20+
- An OpenAI Project API key (for example
sk-proj-...)
Getting Started
- Clone and install dependencies:
npm install
- Compile:
npm run compile
- Run extension in development:
- Press
F5 in VS Code to launch the Extension Development Host.
- In the extension UI, click Sign In and provide:
- OpenAI Project API key (stored in VS Code global state)
Commands
The extension contributes these commands:
autopilot-searchbar.search — Open AutoPilot AI
autopilot-searchbar.logout — Logout
autopilot-searchbar.explainSelection — Explain with AutoPilot AI
autopilot-searchbar.refactorCode — Refactor Code with AutoPilot AI
autopilot-searchbar.documentSelection — Document It with AutoPilot AI
autopilot-searchbar.applyCode — Apply Code from AutoPilot AI
Selection commands are also available in the editor context menu when text is selected.
Extension Settings
This extension contributes the following settings:
autopilot.apiKey (string): API key field (primary sign-in uses secure global state flow).
autopilot.enableAiRouter (boolean, default true): Enables mini-model request classification when heuristics are uncertain.
autopilot.routerModel (string, default gpt-4o-mini): Model used for the lightweight request router.
How Context Routing Works
For normal chat messages, the extension plans each request before sending it to the main model:
- Detect intent/context need (
none / selection / file)
- Detect response depth (
quick / normal / deep)
- Build minimal prompt payload
- Send to OpenAI
This reduces unnecessary token usage and improves latency versus always attaching full-file context.
Development Scripts
npm run compile — Build extension
npm run watch — Build in watch mode
npm run package — Production bundle
npm run lint — Lint source
npm run check-types — Type-check only
npm run test — Run extension tests
Packaging and Publishing
1. Prepare package.json
Ensure at least the following are set:
name
displayName
publisher
version
engines.vscode
2. Create a VSIX package
npx vsce package
This generates a file like:
autopilot-ai-<version>.vsix
3. Publish to Visual Studio Marketplace
- Create/manage publisher: https://marketplace.visualstudio.com/manage
- Create Azure DevOps PAT with Marketplace publish permissions
- Publish:
npx vsce publish -p <YOUR_PAT>
Troubleshooting
- If authentication fails, verify you are using a valid OpenAI Project API key.
- If responses are empty due to token limits, ask a narrower question or reduce file/selection size.
- If network errors occur, check proxy/firewall settings in your environment.
Security Notes
- API key is read from VS Code global state in this extension.
- Review your organization policy before using personal or shared keys.
License
See LICENSE (add one before marketplace publish if missing).