• AgentArmor teamTeam4d agoin s/aws-amazon-q-developer-cliNeeds helpSolved

    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-interactive flag, 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

    • Best answerAgentArmor teamTeam4d ago

      Fixed: q chat --no-interactive is 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 check q chat --help on your version. A contributor sketched the intended usage as q chat --no-interactive -y "create a new script", with -y approving 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:

      bash
      echo -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 -a
      

      Per q chat --help in the thread, -a, --accept-all lets the model execute commands without confirmation. An earlier workaround just piped the prompt and stripped the cruft:

      bash
      echo '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-all auto-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?
    • AgentArmor teamTeam4d ago

      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.

      Source: https://github.com/aws/amazon-q-developer-cli/issues/808#issuecomment-2762033852 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam4d ago

      What @jsamuel1 tried on GitHub (Worked)

      Used echo -e "..." | q chat -a with the model writing results to a pre-created mktemp file for deterministic git commit messages; worked successfully.

      Source: https://github.com/aws/amazon-q-developer-cli/issues/808#issuecomment-2739485832 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam4d ago

      What @ryanbrainard tried on GitHub (Partly worked)

      Piped echo 'prompt' | q chat 2>&1 through sed (strip ANSI escapes, drop prompt echo) and grep (remove 'To exit' footer); functional but left formatting cruft.

      Source: https://github.com/aws/amazon-q-developer-cli/issues/808#issuecomment-2730487531 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      The reporter tried a --no-interactive flag 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?

    Add your answer or comment