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
- Install the extension from the VSCode Marketplace, or download and install the .vsix file from Releases.
- 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.
- 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.
- 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).
- 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.
- 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.
- 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.
- 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.