Amazon Q Developer CLI Cheatsheet - AWS Official AI Coding Agent Full Reference

Amazon Q Developer CLI is AWS official terminal AI coding agent, aimed at developers who live in the AWS ecosystem and want the model to understand and edit a local repo while connecting to AWS services/docs. It stands out by deep AWS integration (explaining and acting on AWS resources) and supports both q one-line queries and agent mode. This sheet covers install/login, chat/one-line queries, and agent execution.

AI CLI·25 commands·Last updated 2026-08-23
amazon-qq-cliawsaicliagentCoding Agent

Install & Auth 5

brew install amazon-q
Install Q CLI on macOS via Homebrew
q --version
Show installed version
q login
Sign in with AWS Builder ID / IAM Identity Center
q logout
Sign out of the current session
q config list
Show current config (profile/region)

Chat & Query 5

q chat
Start the interactive chat REPL
q "write a quicksort in Python"
One-line query, print mode (no REPL)
q "explain this error: $(cat error.log)"
One-shot query with pipe/variable
q /doc
Generate doc comments for current code
q /test
Generate unit tests for selected code

Agent Mode 5

Inside q chat, type /q
Enter autonomous agent mode for multi-step tasks
Describe the full requirement in agent
Cross-file edits, run commands, self-check
/clear
Clear conversation history
Ctrl+C
Interrupt current generation/execution
q chat --help
Show all chat options

AWS Integration 5

q "generate an IAM policy for this Lambda"
Generate resource policies with AWS context
q "explain this CloudFormation template"
Decode IaC templates
q "migrate this EC2 user-data to SSM"
Migration advice and rewrite
q config set region us-east-1
Set the target region
q /help
List available slash commands

Tips 5

One-line q "..." fits scripts/CI
Print mode pipes directly
q login before chat
Make sure AWS identity is ready
Use /doc /test to skip boilerplate
One-click docs and tests
Agent mode for multi-step refactor
/q autonomously edits across files
Best with AWS context
Q knows AWS resources better than general models

Command Examples

Ask one question in print mode and pipe the answer on

q "Write a quicksort in Python"

Without chat, Q never opens a REPL — the command just runs and exits. This is the basic shape for piping Q into a shell pipeline or a CI step.

Feed a whole error log in and have it explained

q "Explain this error output: $(cat error.log)"

The substitution happens before Q starts, so the log contents never land in your shell history. These logs usually carry internal hostnames and account ids, so read them before pasting them anywhere.

Switch to agent mode, then hand over a cross-file requirement

q chat /q Generate an IAM policy for this Lambda

The three lines are: open the REPL, switch to autonomous mode, state the requirement. Agent mode genuinely edits files and runs commands, so make sure the workspace is clean before you start.

Set the region first, then have Q read your IaC template

q config set region us-east-1 q "Explain this CloudFormation template"

q config list reads back your current profile and region. With the wrong region, the resource names and advice Q produces point at a different part of your infrastructure.

Common Pitfalls

  • Print mode writes the answer straight to stdout. If your script splices broad repository context into the prompt, check you are not handing over .env files or credential material along with it.
  • Launching q chat without a valid q login leaves Q with a partial AWS picture. Log in first, then confirm the profile and region with q config list.
  • q config set region only changes a default; it does not verify where your resources actually live. Confirm the region before asking Q for an IAM policy, or the policy will point at the wrong targets.
  • Agent mode (/q) edits files across the tree and executes commands. Run it only in a clean, revertible workspace — never against a production repo or on unpushed local edits.
  • Ctrl+C stops the current step but leaves every modified file on disk, so check the diff before retrying. The same caution applies to /doc and /test output: generated docs and tests need human review, since models often write assertions that assert nothing or duplicate cases you already have.

Tips

  • Amazon Q Developer CLI is AWS-official; when discussing AWS resources (Lambda/IAM/CloudFormation/EC2) it fits cloud context better than general coding agents — great for cloud-native teams.
  • One-line q "..." uses print mode and pipes straight into scripts/CI; for complex multi-step work, enter q chat then /q to switch to agent mode.
  • Prereq: q login with AWS Builder ID or IAM Identity Center; manage profile/region via q config.
  • /doc and /test are hidden efficiency wins — run them against code to fill in docs and unit tests without writing by hand.

FAQ

When should I use q "..." versus q chat?

Putting a quoted prompt straight after q gives you print mode: one question, one answer, no REPL, and the output can be piped straight into another process, which is what you want in scripts and CI. q chat opens an interactive REPL for follow-up questions — worth it only when the task is genuinely conversational.

What does /q do inside q chat, and why switch to it for a refactor?

/q flips the session from Q&A into autonomous agent mode: you state the full requirement and it edits across files, runs commands, and checks its own work. A single question never needs it. For a multi-step refactor it beats spelling out file by file which files to touch.

Why is Q more reliable than a general-purpose model when I ask about AWS resources?

What Q tells you depends on the AWS context it is running in, and that context is decided by profile and region. Set the target with q config set region, read it back with q config list, and only then ask about IAM policies or templates — with the wrong region you get syntactically valid advice aimed at the wrong part of your infrastructure.

How do the slash commands like /doc and /test actually work?

They act on the code you currently have open inside q chat: /doc writes documentation comments, /test generates unit tests for the selected code. They save you leaving the conversation to write it by hand, but you still need to read the generated code before committing it. Run /help to see the other slash commands available in the session.

How do I stop a task that goes wrong or hangs, and start over?

Ctrl+C interrupts whatever is being generated or executed right now and leaves you inside q chat. When the conversation has grown too long, /clear wipes the history so you can restate the requirement. An interrupt can leave a half-written file behind, so check the workspace before retrying.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Aug 23, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us