How to run Amazon Q Developer CLI (q chat) non-interactively in scripts?
The Amazon Q Developer CLI (
q chat) only ran interactively, with no--no-interactiveflag, so piping a prompt or using it in bash scripts and CI/CD pipelines just stayed in the chat loop. Is there a way to run it non-interactively, and was the feature officially added? No specific CLI version or OS was given in the March 2025 thread.Originally asked on GitHub: https://github.com/aws/amazon-q-developer-cli/issues/808
5 answers
Fixed:
q chat --no-interactiveis now a supported feature. A contributor reported that PR #878 added the flag plus the requested non-interactive behavior — output to STDOUT, no prompt echoing, and no(To exit, press Ctrl+C or Ctrl+D again or type /quit)footer; removing colors/styling was still follow-up work. The issue was closed as completed in September 2025, though the thread doesn't show a confirmed invocation of the shipped flag, so checkq chat --helpon your version. A contributor sketched the intended usage asq chat --no-interactive -y "create a new script", with-yapproving tool uses.Before the flag landed, a contributor used this working pattern for a deterministic result — asking the model to write to a pre-created temp file instead of parsing stdout:
bashecho -e "Based on the staged git changes, generate a descriptive git commit message and write it to $TEMP_FILE. Feel free to use appropriate gitmoji/emoji icons. Include what was changed and why. Don't include any markdown formatting or code blocks.\n\nPrompt: $PROMPT" | q chat -aPer
q chat --helpin the thread,-a, --accept-alllets the model execute commands without confirmation. An earlier workaround just piped the prompt and stripped the cruft:bashecho 'write me a script...' | q chat 2>&1 | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | sed '/^> /d' | grep -v 'To exit'Security note:
-a/--accept-allauto-approves tool use. A contributor pointed out that model responses are non-deterministic, so a prompt can unexpectedly trigger a mutative tool call that then runs without confirmation.Did this work for you?What @hayemaxi tried on GitHub (Worked)
A contributor reported that PR #878 added
q chat --no-interactive, writing to STDOUT, removing prompt echoing, and removing the exit footer; color/styling removal was still pending.Did this work for you?What @jsamuel1 tried on GitHub (Worked)
Used
echo -e "..." | q chat -awith the model writing results to a pre-createdmktempfile for deterministic git commit messages; worked successfully.Did this work for you?What @ryanbrainard tried on GitHub (Partly worked)
Piped
echo 'prompt' | q chat 2>&1through sed (strip ANSI escapes, drop prompt echo) and grep (remove 'To exit' footer); functional but left formatting cruft.Did this work for you?What a GitHub user tried on GitHub (Didn't work)
The reporter tried a
--no-interactiveflag and piping input/output for script automation; the flag didn't exist and the CLI only ran interactively.Source: https://github.com/aws/amazon-q-developer-cli/issues/808 (opens external site)
Did this work for you?
Related questions
- Ghostty support for Amazon Q Developer CLI: version and autocomplete fix?
- Amazon Q CLI autocomplete popover renders at wrong position in Ghostty on macOS
- Amazon Q CLI slows down zsh startup and every prompt on macOS: workaround?
- Amazon Q CLI failing with InternalServerException "trouble responding right now" — still open?
- Does amazon-q-developer-cli support MCP resources? resource:// URIs aren't read