{
  "@context": "https://schema.org",
  "@id": "https://aggr.aymericbeaumet.com/items/ampcode-com/2025-09-09-streaming-json/#webpage",
  "@type": [
    "WebPage",
    "ArchiveComponent"
  ],
  "articleBody": "The Amp CLI has two new flags: `--stream-json` and `--stream-json-input`.\n\nThey can be used together with the `--execute` flag to turn on structured JSON output and input, respectively.\n\nHere is an example:\n\n```shell-session\n$ amp --execute \"what is 2+2?\" --stream-json\n```\n\nThis would print something like the following on stdout:\n\n```\n{\"type\":\"system\",\"subtype\":\"init\",\"cwd\":\"/Users/mrnugget/work/amp\",\"session_id\":\"T-2775dc92-90ed-4f85-8b73-8f9766029e83\",\"tools\":[\"oracle\",\"...\"],\"mcp_servers\":[]}\n{\"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\"}\n{\"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\"}\n{\"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\"}\n```\n\nStructured input can be provided on stdin with the `--stream-json-input` flag:\n\n```shell-session\n$ echo '{\n  \"type\": \"user\",\n  \"message\": {\n    \"role\": \"user\",\n    \"content\": [\n      {\n        \"type\": \"text\",\n        \"text\": \"what is 2+2?\"\n      }\n    ]\n  }\n}' | amp -x --stream-json --stream-json-input\n```\n\nIf `--stream-json-input` is set, the Amp CLI will process user messages as soon as they are received on stdin and exit as soon as stdin is closed and the agent has ended its turns.\n\nCombined with `amp threads continue [thread]`, multi-turn conversations can even happen across multiple invocations of the CLI:\n\n```shell-session\n$ amp -x \"what is 2+2?\" --stream-json\n...\n$ amp threads continue -x \"and now add 7 to that\" --stream-json\n...\n{\"type\":\"result\",\"result\":\"11.\", \"subtype\":\"success\",\"duration_ms\":2906,\"is_error\":false,\"num_turns\":2,\"session_id\":\"T-2775dc92-90ed-4f85-8b73-8f9766029e83\"}\n```\n\nSee the [Manual](https://ampcode.com/manual#cli-streaming-json) for more details and the [Appendix](https://ampcode.com/manual/appendix#stream-json-output) for the full schema.\n",
  "authors": [],
  "captured_at": "2026-10-04T12:50:30.804479567+00:00",
  "category": "programming",
  "content_html": "<p>The Amp CLI has two new flags: <code>--stream-json</code> and <code>--stream-json-input</code>.</p>\n<p>They can be used together with the <code>--execute</code> flag to turn on structured JSON output and input, respectively.</p>\n<p>Here is an example:</p>\n<pre><code class=\"language-shell-session\"><span class=\"code-snippet\" data-language=\"Shell-session\">$ amp --execute &quot;what is 2+2?&quot; --stream-json\n</span></code></pre>\n<p>This would print something like the following on stdout:</p>\n<pre><code><span class=\"code-snippet\">{&quot;type&quot;:&quot;system&quot;,&quot;subtype&quot;:&quot;init&quot;,&quot;cwd&quot;:&quot;/Users/mrnugget/work/amp&quot;,&quot;session_id&quot;:&quot;T-2775dc92-90ed-4f85-8b73-8f9766029e83&quot;,&quot;tools&quot;:[&quot;oracle&quot;,&quot;...&quot;],&quot;mcp_servers&quot;:[]}\n{&quot;type&quot;:&quot;user&quot;,&quot;message&quot;:{&quot;role&quot;:&quot;user&quot;,&quot;content&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;text&quot;:&quot;what is 2+2?&quot;}]},&quot;parent_tool_use_id&quot;:null,&quot;session_id&quot;:&quot;T-2775dc92-90ed-4f85-8b73-8f9766029e83&quot;}\n{&quot;type&quot;:&quot;assistant&quot;,&quot;message&quot;:{&quot;type&quot;:&quot;message&quot;,&quot;role&quot;:&quot;assistant&quot;,&quot;content&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;text&quot;:&quot;2 + 2 equals 4.&quot;}],&quot;stop_reason&quot;:&quot;end_turn&quot;,&quot;usage&quot;:{&quot;input_tokens&quot;:12783,&quot;cache_creation_input_tokens&quot;:367,&quot;cache_read_input_tokens&quot;:12416,&quot;output_tokens&quot;:8,&quot;max_tokens&quot;:224000,&quot;service_tier&quot;:&quot;standard&quot;}},&quot;parent_tool_use_id&quot;:null,&quot;session_id&quot;:&quot;T-2775dc92-90ed-4f85-8b73-8f9766029e83&quot;}\n{&quot;type&quot;:&quot;result&quot;,&quot;subtype&quot;:&quot;success&quot;,&quot;duration_ms&quot;:2906,&quot;is_error&quot;:false,&quot;num_turns&quot;:1,&quot;result&quot;:&quot;2 + 2 equals 4.&quot;,&quot;session_id&quot;:&quot;T-2775dc92-90ed-4f85-8b73-8f9766029e83&quot;}\n</span></code></pre>\n<p>Structured input can be provided on stdin with the <code>--stream-json-input</code> flag:</p>\n<pre><code class=\"language-shell-session\"><span class=\"code-snippet\" data-language=\"Shell-session\">$ echo &#39;{\n  &quot;type&quot;: &quot;user&quot;,\n  &quot;message&quot;: {\n    &quot;role&quot;: &quot;user&quot;,\n    &quot;content&quot;: [\n      {\n        &quot;type&quot;: &quot;text&quot;,\n        &quot;text&quot;: &quot;what is 2+2?&quot;\n      }\n    ]\n  }\n}&#39; | amp -x --stream-json --stream-json-input\n</span></code></pre>\n<p>If <code>--stream-json-input</code> is set, the Amp CLI will process user messages as soon as they are received on stdin and exit as soon as stdin is closed and the agent has ended its turns.</p>\n<p>Combined with <code>amp threads continue [thread]</code>, multi-turn conversations can even happen across multiple invocations of the CLI:</p>\n<pre><code class=\"language-shell-session\"><span class=\"code-snippet\" data-language=\"Shell-session\">$ amp -x &quot;what is 2+2?&quot; --stream-json\n...\n$ amp threads continue -x &quot;and now add 7 to that&quot; --stream-json\n...\n{&quot;type&quot;:&quot;result&quot;,&quot;result&quot;:&quot;11.&quot;, &quot;subtype&quot;:&quot;success&quot;,&quot;duration_ms&quot;:2906,&quot;is_error&quot;:false,&quot;num_turns&quot;:2,&quot;session_id&quot;:&quot;T-2775dc92-90ed-4f85-8b73-8f9766029e83&quot;}\n</span></code></pre>\n<p>See the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://ampcode.com/manual#cli-streaming-json\">Manual</a> for more details and the <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://ampcode.com/manual/appendix#stream-json-output\">Appendix</a> for the full schema.</p>\n",
  "content_markdown": "The Amp CLI has two new flags: `--stream-json` and `--stream-json-input`.\n\nThey can be used together with the `--execute` flag to turn on structured JSON output and input, respectively.\n\nHere is an example:\n\n```shell-session\n$ amp --execute \"what is 2+2?\" --stream-json\n```\n\nThis would print something like the following on stdout:\n\n```\n{\"type\":\"system\",\"subtype\":\"init\",\"cwd\":\"/Users/mrnugget/work/amp\",\"session_id\":\"T-2775dc92-90ed-4f85-8b73-8f9766029e83\",\"tools\":[\"oracle\",\"...\"],\"mcp_servers\":[]}\n{\"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\"}\n{\"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\"}\n{\"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\"}\n```\n\nStructured input can be provided on stdin with the `--stream-json-input` flag:\n\n```shell-session\n$ echo '{\n  \"type\": \"user\",\n  \"message\": {\n    \"role\": \"user\",\n    \"content\": [\n      {\n        \"type\": \"text\",\n        \"text\": \"what is 2+2?\"\n      }\n    ]\n  }\n}' | amp -x --stream-json --stream-json-input\n```\n\nIf `--stream-json-input` is set, the Amp CLI will process user messages as soon as they are received on stdin and exit as soon as stdin is closed and the agent has ended its turns.\n\nCombined with `amp threads continue [thread]`, multi-turn conversations can even happen across multiple invocations of the CLI:\n\n```shell-session\n$ amp -x \"what is 2+2?\" --stream-json\n...\n$ amp threads continue -x \"and now add 7 to that\" --stream-json\n...\n{\"type\":\"result\",\"result\":\"11.\", \"subtype\":\"success\",\"duration_ms\":2906,\"is_error\":false,\"num_turns\":2,\"session_id\":\"T-2775dc92-90ed-4f85-8b73-8f9766029e83\"}\n```\n\nSee the [Manual](https://ampcode.com/manual#cli-streaming-json) for more details and the [Appendix](https://ampcode.com/manual/appendix#stream-json-output) for the full schema.\n",
  "dateCreated": "2026-10-04T12:50:30.804479567+00:00",
  "date_created": "2025-09-09T00:00:00+00:00",
  "date_modified": "2025-09-09T00:00:00+00:00",
  "date_published": "2025-09-09T00:00:00+00:00",
  "description": "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?\"…",
  "external_url": "https://ampcode.com/news/streaming-json",
  "git": {
    "commit": "ebb0941c5c06a2ab2377342d607535262a3e969e",
    "path": "items/ampcode-com/2025/09/2025-09-09-streaming-json.md",
    "permalink": "https://github.com/aymericbeaumet/aggr-instance/blob/ebb0941c5c06a2ab2377342d607535262a3e969e/items/ampcode-com/2025/09/2025-09-09-streaming-json.md"
  },
  "id": "urn:aggr:item:e8424a0aa50b615845e2a3bb0d610dbc1e0ebc00",
  "isBasedOn": {
    "@id": "https://ampcode.com/news/streaming-json"
  },
  "mainEntity": {
    "@id": "https://ampcode.com/news/streaming-json",
    "@type": "CreativeWork",
    "archivedAt": {
      "@id": "https://aggr.aymericbeaumet.com/items/ampcode-com/2025-09-09-streaming-json/#webpage"
    },
    "dateModified": "2025-09-09T00:00:00+00:00",
    "datePublished": "2025-09-09T00:00:00+00:00",
    "headline": "Streaming JSON",
    "timeRequired": "PT2M",
    "url": "https://ampcode.com/news/streaming-json",
    "wordCount": 294
  },
  "name": "Archived snapshot: Streaming JSON",
  "preview": null,
  "reading_minutes": 2,
  "replicated_at": null,
  "source": "ampcode-com",
  "source_name": "Amp News",
  "summary": "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?\" } ] } }' | amp -x --stream-json --stream-json-input If --stream-json-input is set, the Amp CLI will process user messages as soon as they are received on stdin and exit as soon as stdin is closed and the agent has ended its turns. Combined with amp threads continue [thread], multi-turn conversations can even happen across multiple invocations of the CLI: $ amp -x \"what is 2+2?\" --stream-json ... $ amp threads continue -x \"and now add 7 to that\" --stream-json ... {\"type\":\"result\",\"result\":\"11.\", \"subtype\":\"success\",\"duration_ms\":2906,\"is_error\":false,\"num_turns\":2,\"session_id\":\"T-2775dc92-90ed-4f85-8b73-8f9766029e83\"} See the Manual for more details and the Appendix for the full schema.",
  "tags": [],
  "temporalCoverage": "2026-10-04T12:50:30.804479567+00:00",
  "title": "Streaming JSON",
  "url": "https://aggr.aymericbeaumet.com/items/ampcode-com/2025-09-09-streaming-json/",
  "word_count": 294
}