This Visual Studio Code extension allows you to use the unofficial ChatGPT API to generate natural language responses from OpenAI's ChatGPT to your questions, right within the editor.
🤖✨ Supercharge your coding with AI-powered assistance. Automatically write new code from scratch, ask questions, get explanations, refactor code, find bugs and more!
⚠️ ⚠️ **IMPORTANT!**⚠️ ⚠️ Due to breaking changes in ChatGPT on Dec 12., update the extension and read the new instructions on obtaining the tokens!
- Ask general questions or use code snippets from the editor to query ChatGPT via an input box in the sidebar
- Right click on a code selection and run one of the context menu shortcuts
- View ChatGPT's responses in a panel next to the editor
- Ask follow-up questions to the response (conversation context is maintained)
- Insert code snippets from the AI's response into the active editor by clicking on them
To use this extension, install it from the VSCode marketplace or download and install .vsix
file from Releases.
- After the installation is complete, you will need to add your ChatGPT tokens to the extension settings in VSCode. To do this, open the
Settings
panel by going to theCode
menu and selectingPreferences
, thenSettings
. - In the search bar, type
ChatGPT
to filter the settings list. - In the ChatGPT section, enter your session tokens in the top three field
After completing these steps, the extension should be ready to use.
There were som
To use this extension, you will need to authenticate with valid token sfrom ChatGPT. To get a session token:
- Go to https://chat.openai.com/chat and log in or sign up.
- Open the developer tools in your browser.
- Go to the
Application
tab and open theCookies
section. - Copy the value for
__Secure-next-auth.session-token
and paste it into theSession Token
field in the extension settings, and the value forcf_clearance
into theClearance Token
field. - Go to the
Network
tab and select any request. - Copy the value for
user-agent
from theRequest Headers
and paste it into theUser Agent
field in the extension settings.
Yesterday, OpenAI added additional Cloudflare protections that make it more difficult to access the unofficial API. That's why you now need to set three different parameters instead of just the Session Token
. There are also several limitations now (copied from chatgpt-api):
- Cloudflare
cf_clearance
tokens expire after 2 hours, so right now we recommend that you refresh yourcf_clearance
token every ~45 minutes or so. - Your
user-agent
andIP address
must match from the real browser window you're logged in with to the one you're using forChatGPTAPI
. - You must use
node >= 18
. - You should not be using this account while the bot is using it, because that browser window may refresh one of your tokens and invalidate the bot's session.
To use the extension, open a text editor in Visual Studio Code and open the ChatGPT panel by clicking on the ChatGPT icon in the sidebar. This will open a panel with an input field where you can enter your prompt or question. By clicking enter, it will be sent to ChatGPT. Its response will be displayed below the input field in the sidebar (note that it may take some time for it to be calculated).
You can also select a code snippet in the editor and then enter a prompt in the side panel, or right-click and select "Ask ChatGPT". The selected code will be automatically appended to your query when it is sent to the AI. This can be useful for generating code snippets or getting explanations for specific pieces of code.
To insert a code snippet from the AI's response into the editor, simply click on the code block in the panel. The code will be automatically inserted at the cursor position in the active editor.
You can select some code in the editor, right click on it and choose one of the following shortcuts from the context menu:
Ask ChatGPT
: will provide a prompt for you to enter any queryChatGPT: Explain selection
: will explain what the selected code doesChatGPT: Refactor selection
: will try to refactor the selected codeChatGPT: Find problems
: looks for problems/errors in the selected code, fixes and explains themChatGPT: Optimize selection
: tries to optimize the selected code
Ask ChatGPT
is also available when nothing is selected. For the other four commands, you can customize the exact prompt that will be sent to the AI by editing the extension settings in VSCode Preferences.
Because ChatGPT is a conversational AI, you can ask follow-up questions to the response. The conversation context is maintained between queries, so you can ask multiple questions in a row.
To reset the conversation context, click ctrl+shift+p
and select ChatGPT: Reset Conversation
.
Please note that this extension is currently a proof of concept and may have some limitations or bugs. We welcome feedback and contributions to improve the extension.
- This wouldn't be possible without OpenAI's ChatGPT
- The extension makes use of chatgpt-api (by Travis Fischer), which uses ChatGPT unofficial API in order to login and communicate with it.
- It is built on top of mpociot/chatgpt-vscode, which started this project
v0.3
inspired and based on barnesoir/chatgpt-vscode-plugin and gencay/vscode-chatgpt