Context management and profiles
Understanding profiles and context
Profiles allow you to switch between sets of contexts that give you unique ways for Amazon Q Developer CLI to interact with you and your systems. Context files contain information like development rules, project details, or coding standards that Amazon Q uses to provide more relevant and tailored responses.
There is always a default profile, which contains a global context and workspace context:
-
Global context: Files that are applied to all profiles
-
Workspace context: Files specific to the current profile
When you add new profiles, they will have their own unique workspace context, allowing you to specify patterns of files that make that profile behave and interact in ways unique to your workflow and processes.
For example, you might create:
-
A "terraform" profile with infrastructure-as-code guidelines
-
A "python" profile with Python coding standards
-
A "java" profile with Java best practices
By switching profiles, you can quickly change the context that Amazon Q uses to provide responses without having to manually specify these files in each conversation.
Managing profiles
You can manage profiles using either the /profile
command or the /context profile
commands.
Using the /profile command
The /profile
command allows you to view and switch between different context profiles in the Amazon Q Developer CLI.
When you run the /profile
command without arguments, it displays a list of available profiles:
q chat > /profile Available profiles: * default dev prod staging
The asterisk (*) indicates the currently active profile.
To switch to a different profile, specify the profile name:
q chat > /profile set dev Switched to profile: dev
Managing context
Context files are markdown files that 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.
Working with multiple projects
If you work on multiple projects with different requirements, you can create a profile for each project:
q chat > /profile create project-a Created profile: project-a > /context add ./project-a/README.md ./project-a/docs/*.md Added 4 path(s) to profile context. > /profile create project-b Created profile: project-b > /context add ./project-b/README.md ./project-b/docs/*.md Added 3 path(s) to profile context.
You can then switch between profiles as you move between projects:
q chat > /profile project-a Switched to profile: project-a
Different development roles
You can create profiles for different roles you perform:
q chat > /profile create backend-dev Created profile: backend-dev > /context add backend-standards.md api-docs/*.md Added 4 path(s) to profile context. > /profile create devops Created profile: devops > /context add infrastructure/*.md deployment-guides/*.md Added 5 path(s) to profile context.