To turn CodeGPT into a repository-aware coding companion inside Visual Studio Code, developers must solve two fundamental requirements: providing model access through custom API keys (Bring Your Own Key / BYOK) and grounding responses in their project through local codebase indexing. Once configured, CodeGPT uses semantic search and multi-profile agents to explain complex logic across files and execute surgical refactoring directly within the editor.
This guide details how to configure custom providers, build workspace vector context, and orchestrate code explanations and refactorings using CodeGPT's built-in tools.
1. Connecting Custom API Keys (BYOK & Custom Endpoints)
CodeGPT operates on a hybrid model: new users receive a limited free tier (30 monthly interactions), but serious development typically relies on Bring Your Own Key (BYOK) or team subscriptions. Using BYOK grants unlimited interactions through CodeGPT, with API token consumption billed directly by your LLM provider.
Step-by-Step Provider Setup
- Install and Sync: Install the official CodeGPT: AI Coding Agents & Chat extension (published by
DanielSanMedium) from the VS Code Marketplace. Open the CodeGPT sidebar and log in using Google, GitHub, or email to sync your account. - Access Provider Settings:
- In the CodeGPT chat sidebar, click the Manage Models button and switch to the Providers tab.
- Alternatively, open the VS Code Command Palette (
Ctrl+Shift+Pon Linux/Windows,Cmd+Shift+Pon macOS) and runCodeGPT: Set API KEY.
- Select Your AI Provider:
- CodeGPT provides native connectors for OpenAI, Anthropic, Google AI Studio, DeepSeek, Mistral, Cohere, Groq, Cerebras, Perplexity, and local engines like Ollama and LM Studio.
- Paste the secret API key generated from your provider console (such as OpenAI's platform settings or Anthropic's console).
- Enter your Organization ID if required by your account.
- Configuring Custom OpenAI-Compatible Endpoints:
- If you use self-hosted inference, internal enterprise gateways, or specialized aggregators (like OpenRouter or vLLM), select Custom under the provider list.
- Enter your target Model Name (e.g.,
cognitivecomputations/dolphin3.0-mistral-24b:freeor your custom fine-tuned model tag). - Enter your API Key.
- Input the full Custom Link (the
/chat/completionsHTTP endpoint). - Click Connect.
- Critical Post-Configuration Step: When using the BYOK plan, you must explicitly select an active model from the chat interface's model selector before sending prompts. Attempting to submit prompts without a selected model triggers a "You must select a model first" error.
2. Indexing Local Workspace Context (Augmented Context)
By default, an AI model in an IDE only knows what you paste into the chat window or the code you currently highlight. To assist with cross-file explanations and safe refactoring, CodeGPT offers Codebase Indexing (Augmented Context).
Highlighting vs. Codebase Indexing
- Highlighting / Snippets: Best for isolated functions, quick syntax questions, or one-off explanations where project-wide context is unnecessary.
- Codebase Indexing: Essential when changes impact multiple modules, interface definitions exist in separate directories, or you need the AI to follow project architectural conventions.
How to Create the Workspace Index
- In the CodeGPT extension sidebar, locate the main menu and click the Codebase button under Augmented Context.
- Click Create Codebase Index.
- Select your project folder from the folder selection dialog.
- CodeGPT parses your project files and builds a local vector index.
- Once indexing completes, the assistant automatically enables the Semantic Search Tool.
Injecting Context into Conversations
CodeGPT provides three primary ways to reference workspace files during conversations:
- Semantic Search Tool (Automatic): When questions require understanding how modules connect, CodeGPT autonomously queries the semantic index to pull relevant definitions into the context window.
- Direct Mentions & Add Context: Click
+Add Contextand select#Filesto pin specific files into the current prompt, or type@in the chat to reference active editor buffers. - Auto Current File: Under CodeGPT Settings (
⚙️icon), toggle the option to automatically attach the currently active editor file to every prompt.
3. Explaining Code Across the Workspace
Deciphering legacy code or unfamiliar architectural patterns requires both local syntax inspection and repository-wide context.
Recommended Profile Mode: Search Mode
CodeGPT provides three pre-configured profile modes in the chat dropdown:
- Chat Mode: Standard conversational mode with no file system tools enabled.
- Search Mode (Recommended for Explanation): A read-only exploration mode. It activates the Semantic Search and Read File tools to inspect workspace hierarchy, imports, and definitions without making unintended changes.
- Agent Mode: Full read/write/terminal execution mode for active coding.
Workflow for Code Explanation
- Select Code: In the VS Code editor, highlight the function, class, or tricky block of logic you want to understand.
- Execute
/Explain:- Open the CodeGPT chat interface, type
/Explain, and pressEnter. - Alternatively, right-click the selected code in the editor and choose Explain CodeGPT from the context menu.
- Open the CodeGPT chat interface, type
- Repository-Aware Synthesis: Because the codebase is indexed, CodeGPT traces where parameters originate, how called helpers are implemented elsewhere in your repository, and which edge cases the implementation handles.
- Follow-Up Inquiries: In Search Mode, ask specific questions like:
- "Where is this handler called across the workspace?"
- "Explain how authentication middleware impacts this route handler."
4. Refactoring Code with Full Workspace Awareness
Refactoring without context often breaks call signatures, introduces naming mismatches, or violates project linting standards. CodeGPT enables safe refactoring through structured slash commands and progressive tool permissions.
Refactoring Workflow
- Isolate Target Code: Highlight the code snippet or block targeted for modernization, cleanup, or performance optimization.
- Trigger
/Refactor:- In the CodeGPT chat input, type
/Refactorfollowed by specific constraints (for example:/Refactor convert callback chain to async/await and extract validation logic), then pressEnter. - Alternatively, right-click and choose Refactor CodeGPT.
- In the CodeGPT chat input, type
- Review and Application:
- In Search or Chat Mode: CodeGPT outputs a structured diff and clean replacement block in the chat panel. Click the Insert code button (the arrow icon in the top right of the code block) to insert the replacement directly into your active VS Code document.
- In Agent Mode: CodeGPT invokes its internal
Edit Filetool to apply modifications directly to disk. If Auto-Approve is disabled in Settings, CodeGPT prompts you to inspect and approve the change before writing.
Practical Tips for Reliable Refactoring
- Progressive Escalation: Start in Search Mode to ask CodeGPT what dependencies will be affected by refactoring the selected component. Once the plan is sound, switch to Agent Mode to execute file updates or run terminal commands (e.g., test suites).
- Run Terminal Verification: In Agent Mode, ask CodeGPT to run your project's unit test runner (such as
npm testorpytest) via itsRun Terminal Commandinternal tool to confirm that behavior has not regressed. - Maintain Clean Indexes: After significant refactoring or pulling upstream branches, trigger a re-index from the Codebase menu to keep the semantic vector store synchronized with your current workspace files.