fx ask
fx ask runs one noninteractive request and exits. Connect an account, then run it from your project directory:
fx ask "explain what this repository does"Pass a prompt to fx ask
Pass the prompt as command arguments. In a shell script, printf can send generated prompt text to fx ask through standard input (stdin):
printf "summarize src/core\n" | fx askUse --image <path> to attach an image. Repeat the flag to attach multiple images.
fx ask --image ./ui.png "describe this interface"See Vision for supported formats and image routing.
Choose the model
Use --model for one request:
fx ask --model <model-id> "Review this change"Add --effort high or --fast if the model supports them.
The flags do not change your saved defaults. Set FX_PROVIDER when the request should use another provider or a custom connection.
For AI Gateway, --provider-order sets a routing preference and --provider-strict prevents fallback outside it. See AI Gateway routing.
Use fx ask in scripts
For shell scripts and CI, redirect standard output (stdout) to receive raw assistant Markdown. Progress and diagnostics remain on standard error (stderr).
Use --json when a program needs structured fields instead of Markdown:
fx ask --json "summarize the current changes"The command returns one JSON object:
{
"output": "Assistant Markdown",
"final_output": "Final assistant response",
"exit_code": 0,
"model": "provider/model-id",
"resolved_provider": "bedrock",
"session_id": "session-id",
"steps": 1,
"usage": {
"input_tokens": 1200,
"output_tokens": 450
},
"tool_calls": [
{
"name": "read_file",
"status": "success"
}
]
}
Failures use a nonzero exit_code and can include an error field. Tool calls always include name and status; some tools include additional result fields.
output includes the assistant text produced during the request. final_output contains the completed final response, or an empty string when no final response completed.
resolved_provider identifies the AI Gateway provider that served the last model request. It is null when the provider does not report routing.
usage.input_tokens and usage.output_tokens sum the counts reported by main-agent completions, including usage recorded before an error. A count is null when no completion reported it; reported zero remains 0. These totals exclude subagent, helper-model, and provider-tool usage. Use fx usage for recorded local usage and costs.
In a script, check the command's exit status before using the reply. This example needs jq:
#!/bin/sh
result=$(mktemp)
trap 'rm -f "$result"' EXIT
if fx ask --json --no-save "Summarize this repository without editing files" > "$result"; then
jq -r '.final_output' "$result"
else
status=$?
cat "$result" >&2
exit "$status"
fi
Add --no-save for a run that should not create a session. In JSON output, session_id is an empty string. --no-save cannot be combined with --resume.
Continue a session with fx ask
Use --resume last to continue the latest session for the current workspace:
fx ask --resume last "now add tests"You can pass a session ID instead of last. See Sessions to inspect sessions or recover an interrupted response.
Handle permissions in noninteractive runs
Saved permission rules apply to fx ask. In a terminal, actions that require approval can prompt on stderr.
With --json or --quiet, add --prompt-permissions to allow those prompts. This requires terminal input; piped or redirected input cannot receive approval prompts.
In auto mode, a security concern holds the action and returns guidance to the agent without asking you for approval. --full-access disables fx permission checks for the run.
An interrupted run exits with code 130. See Troubleshooting when a run ends before the tool executes.
Run fx ask --help for the complete flag reference.