
Take control of your code with Amazon Q Developer’s new context features
March 11, 2025In this blog post, I dive into the powerful new features of Amazon Q Developer that empower developers to take full control of their development workflow. These features, currently available in Visual Studio Code, allow you to leverage workspace context, explicit context, prompt libraries, and project rules to streamline your software projects, maintain coding standards, and boost your overall productivity. Developers working in other IDEs can expect support for these capabilities to come soon as well. Whether you’re an experienced developer or just starting out, these features will transform the way you approach your development tasks.
Background
For the past year, Amazon Q Developer has supported workspace context in the integrated development environment (IDE). This powerful feature allows Amazon Q Developer to automatically ingest and index all your code files, configurations, and project structure, giving the AI-powered assistant comprehensive context across your entire application.
By adding the @workspace
modifier to your question, Amazon Q Developer can automatically include the most relevant chunks of your workspace code as additional context. This allows the assistant to provide more thorough and accurate responses, even for questions that require understanding the broader codebase, rather than just the current file.
To illustrate this, I will use code from the AWS CDK Immersion Day Workshop. In the following example, I ask Amazon Q Developer, “Which resources are deployed by the workshop stack?” Typically, the assistant would only have the current file open in the IDE as context to answer this question. However, by adding @workspace
, Amazon Q Developer can include additional files to provide a more complete response, describing all the resources in the project, such as AWS Lambda functions, an Amazon API Gateway, and an Amazon DynamoDB table.
With this additional context, Amazon Q Developer can provide a more comprehensive answer, explaining the various resources that make up the workshop stack.
Context Transparency
Amazon Q Developer can’t review every file in a large project–that would take too long. The assistant determines relevance based on an index that is updated periodically. While this works great in most cases, there are times when I want to know which files Amazon Q picked. The new context transparency feature, gives me the insight I need.
Amazon Q Developer now includes the context information directly in the response, listing each file that was added. The context transparency feature allows me to see exactly which files the assistant used to formulate its answer. In the following example, you can see that Q Developer included four files from my project.
By expanding the context section, you can easily see the files that Amazon Q Developer used to provide the previous response, giving you greater insight into the assistant’s decision-making process.
Explicit Context
While Amazon Q Developer typically does a great job of picking the best files to augment the context, there are times when I want more control. The new explicit context feature allows me to choose individual files and folders that I want to add to the context.
By typing @
in the chat, Amazon Q Developer displays a user interface that lets you select the specific files and folders you want to include. This provides the assistant with access to the exact information that you know it needs to answer your question.
Let’s return to the prior example. While Q Developer properly identified all the resources in the stack, it did not include lib/hitcounter.ts
where the DynamoDB table is defined. While the answer is correct, I want Q. Developer to see the source of the HitCounter
. In the following example, I explicitly add the lib
folder to the context because I know that is where the resources are defined.
Rather than allowing Q to choose the files, I can explicitly identify files and folders that I want to add to the context. In the following image you see that Q again answered my question correctly. However, with the source code to both files, Q was able to include additional information missing from the prior example. Notice that the HitCounterHandler
now includes additional information about the runtime and version.
With the ability to explicitly define the context, I can tailor the information Amazon Q Developer uses to provide the most relevant and accurate response for my specific needs.
Prompt Library
In addition to controlling the context, Amazon Q Developer now allows you to build a library of common prompts. These prompts are stored as Markdown files in my ~/.aws/amazonq/prompts
folder, making it easy to reuse them across multiple conversations and projects.
For example, let’s say you want to add a diagram to the README file for your project. While Amazon Q Developer’s /doc
feature can already generate an infrastructure diagram, you may have other types of diagrams, like an Entity-Relationship (ER) diagram or a sequence diagram, that you use frequently. By storing these prompts in your library, you can easily add them to the context without having to retype the prompt each time. In the following example, I will create a sequence diagram.
In the prior image, you can see that I have again added the lib
folder to the context in addition to a saved prompt named “Create Sequence Diagram”. Note that I can combine multiple modifiers adding additional context and prompts as needed. The stored prompt for “Create Sequence Diagram” is shown below.
Create a sequence diagram using Mermaid that shows the sequence of calls between resources. Ignore supporting resources like IAM policies and security group rules.
Amazon Q Developer uses the prompt, and the two source code files in the lib
folder to create the following sequence diagram.
The prompt library saves me time and reduces the chances of making mistakes when generating common artifacts, allowing me to focus on more complex and creative aspects of my development workflow.
Project Rules
The last feature we’ll explore is “Project Rules.” Similar to the prompt library, these rules are stored as Markdown files. Unlike the prompt library, which is specific to your user profile, project rules are stored in the .amazonq/rules
folder of your project. Therfore, they are applied to all developers that share the project source code.
These rules allow you to enforce coding standards and best practices across your team. For example, you could have a rule that all Python code uses type hints, or that all Java code uses Javadocs comments. By storing these rules in your project, you can drive consistency across developers, regardless of their experience level.
To illustrate this, imagine that a junior developer asks Q to “Add an S3 bucket to the stack” as shown in the following image. This prompt is too simple and does not include our best practices.
Despite the vague prompt, you might notice that Q Developer’s response mentions the “best practices” stored in “the rules file”. You might also notice that Q has added cdk.md
to the context even though I did not include any modifiers in my prompt. This is the power of the project rule. It adds additional context to the prompt, even when the developer forgets to add it manually. .amazonq/rules/cdk.md
includes the following text. In addition, context transparency makes it clear that the rule was included so the developer is aware.
All S3 Buckets must have encryption enabled, enforce SSL, and block public access. All DynamoDB Tables must have encryption enabled.
All SNS Topics must have encryption enabled and enforce SSL.
All SQS Queues must enforce SSL.
Project rules empower you to maintain consistency and best practices across your entire development team, helping to improve the overall quality and maintainability of your codebase.
Conclusion
The new features in Amazon Q Developer give you powerful tools to simplify your software development workflow. By leveraging workspace context, explicit context, prompt libraries, and project rules, you can ensure your AI assistant has the information it needs to provide accurate and helpful responses, while also enforcing best practices and standards across your team.
To get started with these features, visit the Amazon Q Developer Getting Started guide and explore the full range of capabilities that can help you create impressive software more efficiently.
