SuperAPI AI Directory

chatgpt-vscode

chatgpt-vscode is a Visual Studio Code extension that allows you to ask OpenAI's ChatGPT questions and get natural language answers within the editor through the unofficial ChatGPT API. It provides a sidebar input box, right-click code menu, response panel, follow-up questions, and code insertion features, and requires configuring a ChatGPT session token in the settings.

Open website

About this tool

Purpose

chatgpt-vscode is a Visual Studio Code extension designed to let developers use ChatGPT directly inside the editor to generate natural language answers without switching to a browser. It communicates with OpenAI's ChatGPT through the unofficial ChatGPT API.

Main capabilities

  • Ask questions in the sidebar input box, or use code snippets in the editor to query ChatGPT.
  • Right-click a code selection to run context menu shortcut actions:
    • Ask ChatGPT: prompts you to enter any query.
    • ChatGPT: Explain selection: explains what the selected code does.
    • ChatGPT: Refactor selection: attempts to refactor the selected code.
    • ChatGPT: Find problems: finds problems or errors in the selected code, fixes them, and explains.
    • ChatGPT: Optimize selection: attempts to optimize the selected code.
  • View ChatGPT's response in a panel next to the editor.
  • Ask follow-up questions about the response (maintaining conversation context).
  • Click a code snippet in the AI response to insert it at the cursor position in the active editor.

How to use

  1. Install the extension from the VSCode Marketplace, or download and install the .vsix file from Releases.
  2. After installation, you need to add the ChatGPT session token in the VSCode extension settings: open the settings panel (Code menu → Preferences → Settings), search for ChatGPT, and enter the session token in the SESSION_TOKEN field.
  3. To get the session token: visit https://chat.openai.com/chat and log in or sign up; open the browser developer tools; go to the Application tab and open the Cookies section; copy the value of __Secure-next-auth.session-token and save it.
  4. To use the extension: open a text editor, click the ChatGPT icon in the sidebar to open the panel, enter a prompt or question in the input box, and press Enter to send. The response will be displayed below the input box (it may take some time to compute).
  5. You can select a code snippet and then enter a prompt in the side panel, or right-click and select "Ask ChatGPT"; the selected code will be automatically appended to the query.
  6. To insert a code snippet, simply click the code block in the panel, and the code will be automatically inserted at the cursor position in the active editor.
  7. Ask ChatGPT is also available when nothing is selected. The prompts for the other four commands can be customized by editing the extension settings in VSCode Preferences.
  8. Since ChatGPT is a conversational AI, you can ask follow-up questions, and the conversation context is maintained between queries. To reset the conversation context, press ctrl+shift+p and select ChatGPT: Reset Conversation.

Use cases

Suitable for developers who need quick explanations, refactoring suggestions, problem finding, code optimization, or generated code snippets while writing code.

Limitations

This extension is currently a proof of concept and may have some limitations or bugs. It uses the unofficial ChatGPT API for login and communication.