Perplexity Copilot
A VS Code extension that brings AI-powered coding assistance using Perplexity AI. Features multiple modes similar to GitHub Copilot: Ask, Edit, Plan, and Agent.
Features
🗣️ Ask Mode
- Ask questions about code or general programming topics
- Get context-aware answers based on your current file/selection
- Streaming responses for real-time feedback
✏️ Edit Mode
- Select code and request modifications
- Preview changes in a diff view before applying
- Common operations: refactor, add comments, fix bugs, optimize
📋 Plan Mode
- Generate step-by-step implementation plans
- Break down complex tasks into manageable steps
- Track progress through plan execution
🤖 Agent Mode
- Autonomous coding agent that can read/write files
- Multi-step task execution with confirmation for destructive actions
- Observe → Think → Act workflow
Installation
From Source
- Clone this repository
- Install dependencies:
npm install
- Compile the extension:
npm run compile
- Press
F5 in VS Code to launch the Extension Development Host
From VSIX
- Build the VSIX package:
npm run package
- Install from VSIX in VS Code
Configuration
API Key
Set your Perplexity AI API key using the command palette:
Perplexity Copilot: Set API Key
Or use the welcome prompt when you first activate the extension.
Settings
| Setting |
Description |
Default |
perplexityCopilot.defaultModel |
Default model for AI requests |
llama-3.1-sonar-large-128k-online |
perplexityCopilot.askMode.model |
Override model for Ask mode |
(uses default) |
perplexityCopilot.editMode.model |
Override model for Edit mode |
(uses default) |
perplexityCopilot.planMode.model |
Override model for Plan mode |
(uses default) |
perplexityCopilot.agentMode.model |
Override model for Agent mode |
(uses default) |
perplexityCopilot.agentMode.maxSteps |
Maximum steps for agent |
10 |
perplexityCopilot.planMode.verbosity |
Plan detail level |
normal |
perplexityCopilot.telemetry.enabled |
Enable anonymous telemetry |
false |
Usage
Commands
| Command |
Description |
Keybinding |
Perplexity Copilot: Ask |
Ask a question |
Ctrl+Shift+P A |
Perplexity Copilot: Edit Selection |
Edit selected code |
Ctrl+Shift+P E |
Perplexity Copilot: Generate Plan |
Create implementation plan |
- |
Perplexity Copilot: Start Agent |
Start autonomous agent |
- |
Perplexity Copilot: Open Chat |
Open chat view |
Ctrl+Shift+P C |
Perplexity Copilot: Select Model |
Choose AI model |
- |
Perplexity Copilot: Set API Key |
Configure API key |
- |
Chat Participant
Use @perplexity in VS Code's built-in chat:
@perplexity How do I implement a binary search in TypeScript?
@perplexity /edit Add error handling to this function
@perplexity /plan Create a REST API for user management
@perplexity /agent Create unit tests for the utils module
Right-click on selected code to access:
- Edit with Perplexity - Modify selected code
- Ask Perplexity - Ask questions about the code
Available Models
| Model |
Context |
Best For |
| Sonar Small (Online) |
128K |
Quick questions |
| Sonar Large (Online) |
128K |
General coding tasks |
| Sonar Huge (Online) |
128K |
Complex agent tasks |
| Llama 3.1 8B |
128K |
Fast edits |
| Llama 3.1 70B |
128K |
High-quality code |
Architecture
src/
├── extension.ts # Extension entry point
├── commands.ts # Command implementations
├── chat-participant.ts # VS Code Chat API integration
├── views.ts # UI views and providers
├── core/
│ ├── base-session.ts # Base session class
│ ├── ask-session.ts # Ask mode implementation
│ ├── edit-session.ts # Edit mode implementation
│ ├── plan-session.ts # Plan mode implementation
│ ├── agent-session.ts # Agent mode implementation
│ └── session-manager.ts # Session management
├── infrastructure/
│ ├── perplexity-client.ts # API client
│ ├── editor-adapter.ts # VS Code editor adapter
│ ├── storage-adapter.ts # Storage adapters
│ └── output-adapter.ts # Output channels
└── shared/
├── types.ts # Type definitions
├── ports.ts # Port interfaces
├── prompts.ts # System prompts
├── models.ts # Model registry
└── utils.ts # Utilities
Development
Prerequisites
- Node.js 18+
- VS Code 1.95+
Scripts
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch mode
npm run watch
# Lint
npm run lint
# Package extension
npm run package
Testing
Press F5 to open a new VS Code window with the extension loaded.
Security
- API keys are stored securely using VS Code's SecretStorage
- No code is logged unless explicitly opted-in
- All communication uses HTTPS
License
MIT
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
Acknowledgments