The Amp CLI has two new flags: --stream-json and --stream-json-input.
They can be used together with the --execute flag to turn on structured JSON output and input, respectively.
Here is an example:
$ amp --execute "what is 2+2?" --stream-json
This would print something like the following on stdout:
{"type":"system","subtype":"init","cwd":"/Users/mrnugget/work/amp","session_id":"T-2775dc92-90ed-4f85-8b73-8f9766029e83","tools":["oracle","..."],"mcp_servers":[]}
{"type":"user","message":{"role":"user","content":[{"type":"text","text":"what is 2+2?"}]},"parent_tool_use_id":null,"session_id":"T-2775dc92-90ed-4f85-8b73-8f9766029e83"}
{"type":"assistant","message":{"type":"message","role":"assistant","content":[{"type":"text","text":"2 + 2 equals 4."}],"stop_reason":"end_turn","usage":{"input_tokens":12783,"cache_creation_input_tokens":367,"cache_read_input_tokens":12416,"output_tokens":8,"max_tokens":224000,"service_tier":"standard"}},"parent_tool_use_id":null,"session_id":"T-2775dc92-90ed-4f85-8b73-8f9766029e83"}
{"type":"result","subtype":"success","duration_ms":2906,"is_error":false,"num_turns":1,"result":"2 + 2 equals 4.","session_id":"T-2775dc92-90ed-4f85-8b73-8f9766029e83"}
Structured input can be provided on stdin with the --stream-json-input flag:
$ echo '{
"type": "user",
"message": {
"role": "user",
"content": [
{
"type": "text",
"text": "what is 2+2?"
}
]
} …