Adding workspace context to Amazon Q Developer chat in the IDE - Amazon Q Developer

Adding workspace context to Amazon Q Developer chat in the IDE

When you chat with Amazon Q in the integrated development environment (IDE), you can add @workspace to your question to automatically include your entire codebase as context. Amazon Q uses your code and the configuration of your application to provide more referenced answers about the projects in your workspace.

With workspace context, Amazon Q has enhanced capabilities, including locating files, understanding how code is used across files, and generating code that leverages multiple files, including files that aren’t opened. After you ask a question that includes @workspace, the context of your workspace is maintained throughout your conversation, meaning you can ask follow up questions without adding @workspace again.

Setup

Before you continue, make sure you have the latest version of your IDE installed. You can then complete the following setup steps.

Enable indexing

To use your workspace as context, Amazon Q creates a local index of your workspace repository, including code files, configuration files, and project structure. During indexing, non-essential files like binaries or those specified in .gitignore files are filtered out.

It can take 5 to 20 minutes to index a new workspace. During this time, you can expect elevated CPU usage in your IDE. After initial indexing, the index is incrementally updated when you make changes to your workspace.

The first time you add workspace context, you must enable indexing in your IDE. Complete the following steps to enable indexing:

  1. Add @workspace to your question in the Amazon Q chat panel.

  2. Amazon Q prompts you to enable indexing. Choose Settings to be redirected to Amazon Q settings in your IDE. You can also choose Open Settings from the Amazon Q task bar.

  3. Select the box under Amazon Q: Local Workspace Index.

Configure indexing (optional)

No configuration is necessary for the indexing process, however you can choose to specify the number of threads dedicated to indexing. If you increase the number of threads used, indexing will complete faster, and it will use more of your CPU. To update the indexing configuration, specify the number of threads in Amazon Q settings under Amazon Q: Local Workspace Index Threads.

Ask questions with workspace context

To add your workspace as context to your conversation with Amazon Q, open the workspace you want to ask questions about, and then add @workspace to your question in the chat panel.

If you want to start chatting about a different workspace, open the workspace, and then open a new chat tab. Include @workspace in your question to add the new workspace as context.

You can ask Amazon Q about any file in your workspace, including unopened files. Amazon Q can explain files, locate code, and generate code across files, in addition to existing conversational coding capabilities.

Following are example questions you can ask Amazon Q that leverage workspace context in the chat:

  • @workspace where is the code that handles authorization?

  • @workspace what are the key classes with application logic in this project?

  • @workspace explain main.py

  • @workspace add auth to this project

  • @workspace what third-party libraries or packages are used in this project, and for what purpose?

  • @workspace add unit tests for function <function name>