Connect with us
Active Currencies 10006
Market Cap $1,136,819,108,398.90
Bitcoin Share 43.97%
24h Market Cap Change $-3.62

How to Use ChatGPT Extension in VS Code: A Comprehensive Guide

5min Read

Dive into this comprehensive guide to discover how to seamlessly integrate and use the ChatGPT extension in Visual Studio Code, enhancing your programming experience instantly.

Share this article

ChatGPT, powered by OpenAI’s GPT-3 language model, has emerged as a revolutionary tool for developers. By integrating ChatGPT in VS Code, you can improve your coding efficiency and streamline your workflow. 

Collection of top AI tools to use for different tasks.

In this ultimate guide, we’ll walk you through the steps to set up, configure, and use ChatGPT in VS Code while showcasing its diverse features and capabilities to enhance your coding experience.

Installation and Configuration of ChatGPT in VS Code

OpenAI – Image via Pixabay

Install ChatGPT extension 

To get started with ChatGPT in VS Code, you’ll need to install the ChatGPT extension. Launch VS Code and proceed to the Extensions Marketplace by following these steps:

  • Search for “ChatGPT” and click the “Install” button.
  • Upon successful installation, you will find the ChatGPT icon displayed on the left sidebar of VS Code.

Configure ChatGPT with API key

After installing the ChatGPT extension, you’ll need to set up an API key to access the GPT-3 language model. Follow these steps to configure ChatGPT with your API key:

  • To access the settings in VS Code, click on the gear icon located in the bottom left corner of the interface. Utilize the search bar to filter the settings list by typing “ChatGPT.” Locate the ChatGPT settings and input your OpenAI API key in the designated field.

Obtaining the session token

To use the ChatGPT extension, you’ll need to authenticate with a valid session token. Follow these steps to obtain a session token:

  • Go to and log in or sign up.
  • Open the developer tools in your browser (e.g Chrome, Firefox).
  • Navigate to the Application tab and open the Cookies section.
  • Copy the value for __Secure-next-auth.session-token and save it.

Once you have the session token, add it to the ChatGPT settings in VS Code.

Using the ChatGPT extension 

After successfully installing and configuring the ChatGPT extension, you can start using it to enhance your coding experience. Here are some key features and use cases:

  • In VS Code, open a text editor and locate the ChatGPT icon in the sidebar. By clicking on the icon, a panel will appear, presenting an input field where you can enter your prompt or question.
  • Press enter to send your query to ChatGPT. The artificial intelligence (AI’s) response will be displayed in the sidebar (please note that it may take some time for the response to be calculated).
  • To utilize ChatGPT in VS Code, you have multiple options. You can either select a code snippet in the editor and provide a prompt in the side panel, or you can right-click and choose “Ask ChatGPT.” When you send your query to the AI, the selected code will be automatically appended.
  • Simply click on the code block displayed in the panel to insert a code snippet from the AI’s response into the editor. The code will then be inserted at the current cursor position in the active editor.

Explore some of these handy AI programming tools to enhance your overall productivity!

Refactoring and explaining code with ChatGPT

ChatGPT in VS Code can also help you refactor or explain selected code. To use this feature:

  • Select the code in the editor.
  • Perform a right-click on the selected code, and from the context menu, select one of the following options:
    • Ask ChatGPT: Provides a prompt for 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: Looks for problems/errors in the selected code and fixes them.
    • ChatGPT Optimize selection: Tries to optimize the selected code.

What you can do with ChatGPT in VS Code

VS Code – Image via VS Code

Here are some of the ways you can use ChatGPT in VS Code to enhance your coding experience:

  • Code completion: ChatGPT can suggest code completions as you type, making your coding process more efficient.
  • Commenting: ChatGPT can suggest comments for your code, improving the readability and maintainability of your projects.
  • Email composition: If you use VS Code for email composition, ChatGPT can suggest text for your emails, saving you time and effort.
  • Text editing: ChatGPT can suggest text edits based on your current file and past writing history, helping you write more effectively.

Best practices for using ChatGPT

To get the most out of ChatGPT, follow these best practices:

  • ChatGPT should be utilized as a complement to your existing coding skills rather than a substitute for them.
  • Review ChatGPT’s suggestions carefully before accepting them.
  • Use ChatGPT to save time and increase efficiency, but don’t rely on it completely.
  • Regularly update your settings to ensure ChatGPT is working optimally.

Troubleshooting common ChatGPT issues

If you encounter issues while using ChatGPT in VS Code, consider the following solutions:

  • Ensure that ChatGPT is properly set up and enabled in VS Code’s settings if suggestions aren’t appearing.
  • Check the ChatGPT configuration and API key validity if suggestions are irrelevant to your code.
  • Report any instances of inappropriate or offensive text suggestions to ChatGPT’s support team immediately.


Contextual conversations – Image via Pixabay

ChatGPT in VS Code is a powerful tool that can significantly enhance your coding workflow. With its AI-powered natural language responses, contextual conversations, code refactoring, and code snippet insertion, it’s an essential resource for any programmer. 

Install the ChatGPT extension today and experience the power of AI-driven coding assistance.


Diya is an enthusiastic individual with a zeal to learn new things. She’s a Content Writer and Copywriter who turned her passion for writing poetry into a profession. She has written for various niches under the sun with experience and expertise in writing for topics related to AI and crypto. As a Content Writer at AMBCrypto, Diya tries to offer valuable insights into these subjects to help you keep up with the rapid technological advancements.
Read the best crypto stories of the day in less than 5 minutes
Subscribe to get it daily in your inbox.