Context management - Amazon Q Developer

Context management

Managing context

Context files contain information you want Amazon Q to consider during your conversations. These can include project requirements, coding standards, development rules, or any other information that helps Amazon Q provide more relevant responses.

Adding context

You can add files or directories to your context using the /context add command:

q chat > /context add README.md Added 1 path(s) to profile context.

To add a file to the global context (available across all profiles), use the --global flag:

q chat > /context add --global coding-standards.md Added 1 path(s) to global context.

You can also add multiple files at once using glob patterns:

q chat > /context add docs/*.md Added 3 path(s) to profile context.

Viewing context

To view your current context, use the /context show command:

q chat > /context show Global context: /home/user/coding-standards.md Profile context (terraform): /home/user/terraform-project/README.md /home/user/terraform-project/docs/architecture.md /home/user/terraform-project/docs/best-practices.md

Removing context

To remove files from your context, use the /context rm command:

q chat > /context rm docs/architecture.md Removed 1 path(s) from profile context.

To remove files from the global context, use the --global flag:

q chat > /context rm --global coding-standards.md Removed 1 path(s) from global context.

To clear all files from your context, use the /context clear command:

q chat > /context clear Cleared all paths from profile context.

To clear the global context, use the --global flag:

q chat > /context clear --global Cleared all paths from global context.

Common use cases

Here are some common use cases for context profiles:

Using project rules

Amazon Q supports project-level rules that can define security guidelines and restrictions. These rules are defined in Markdown files in the .amazonq/rules directory of your project.

For example, you can create rules that specify:

  • Which directories Amazon Q should avoid accessing

  • Security requirements for generated code

  • Coding standards and best practices

Project rules can be added to your context using the /context add command:

q chat > /context add .amazonq/rules/*.md Added 3 path(s) to profile context.

You can also add project rules to your global context to apply them across all profiles:

q chat > /context add --global .amazonq/rules/security-standards.md Added 1 path(s) to global context.

For more information about creating and using project rules, see Creating project rules for use with Amazon Q Developer chat in the IDE documentation.