---
title: "Marking Relayed Mid-Turn Messages Synthetic in Claude Code"
term: "Synthetic Mid-Turn Message Marking"
description: "From Claude Code 2.1.332 on Opus 4.8+, SDK and claude -p mid-turn messages count as user input without feature flags; mark relayed text isSynthetic: true."
tags:
  - agent-design
  - instructions
  - automation
  - claude
aliases:
  - isSynthetic mid-turn messages
  - relayed text isSynthetic flag
  - SDKUserMessage isSynthetic provenance
applies_to: "claude-code@2.x"
last_reviewed: 2026-11-28
maturity: emerging
status: current
---

# Marking Relayed Mid-Turn Messages Synthetic in Claude Code

> Without fetched feature flags, Claude Code 2.1.332 counts Opus 4.8+ SDK and `claude -p` mid-turn messages as user input; mark relayed text `isSynthetic: true`.

When an Agent SDK or `claude -p` harness injects non-human text as a user message mid-turn, send it as its own message with `isSynthetic: true`, `origin` unset, and `client_composed: true` ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkmessageorigin)). Claude Code 2.1.332 (November 25, 2026) "Changed SDK and `claude -p` mid-turn messages to count as the user’s where feature flags aren’t fetched, as on clouds or with telemetry off, from Opus 4.8 on; mark relayed text `isSynthetic: true`" ([changelog 2.1.332](https://code.claude.com/docs/en/changelog#2-1-332)). Apply this contract to relayed non-human text only; direct human prompts and host-declared scheduled runs use separate `origin` fields.

## When feature flags are not fetched

Claude Code skips fetching feature flags from Anthropic in three session classes ([environment variables reference](https://code.claude.com/docs/en/env-vars#features-that-need-feature-flag-fetching)):

- Sessions disabling fetching through `CLAUDE_CODE_DISABLE_FEATURE_FLAGS`, `DISABLE_TELEMETRY`, `DO_NOT_TRACK`, or `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`, using the documented values for each variable
- Third-party provider sessions on Amazon Bedrock, Claude Platform on AWS, Google Cloud's Agent Platform, or Microsoft Foundry, unless a host sets `CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`
- Claude apps gateway sessions

Two other setups start without fetched flags on every run: clean CI containers without flags saved by an earlier session, and sessions authenticating with `ANTHROPIC_AUTH_TOKEN` to a non-Anthropic `ANTHROPIC_BASE_URL` with no API key ([environment variables reference](https://code.claude.com/docs/en/env-vars#first-session-after-an-install-or-upgrade)).

For `DISABLE_TELEMETRY` and `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`, "any non-empty value including `0` turns the behavior on" ([environment variables reference](https://code.claude.com/docs/en/env-vars#variables)). Setting `DISABLE_TELEMETRY=0` or `false` still disables flag fetching; unset the variable to remove that opt-out. `DO_NOT_TRACK=0` leaves telemetry on ([variables reference](https://code.claude.com/docs/en/env-vars#variables)).

## The three-field contract for relayed text

For text the user did not write (such as a fetched page or another agent's output), each field enforces one part of the provenance boundary:

- `isSynthetic: true` marks the message as non-user input, and Claude Code assigns it the `unclassified` origin kind on v2.1.223 and later ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkmessageorigin)).
- Leaving `origin` unset avoids a silent fallback to user authority. Callers may set only `{ kind: "human" }` or the declared scheduled-run `task-notification` kind, and must leave every other kind (such as `peer` or `channel`) to Claude Code and Anthropic servers: "If you set one of those kinds, Claude reads the message as the user's by default" ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkmessageorigin)).
- `client_composed: true` delivers relayed text verbatim. "Claude Code then doesn't expand `@path` mentions, and doesn't run text that starts with `/` as a command" ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkusermessage)). This field requires TypeScript Agent SDK v0.3.280 or later and Claude Code v2.1.248 or later.

Each caller message class carries a distinct field combination ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkmessageorigin)):

| Message class | `isSynthetic` | `origin` | `client_composed` |
|---|---|---|---|
| Relayed non-human text | `true` | Unset | `true` |
| Direct human prompt | Unset | `{ kind: "human" }` | Unset |
| Host-declared scheduled run | Unset | `{ kind: "task-notification", subkind: "scheduled-trigger", fireReason: "scheduled" }` | Not specified |

Declared scheduled runs also require `CLAUDE_CODE_HOST_SCHEDULED_RUN=1` in `env`, with neither `CLAUDECODE` nor `CLAUDE_CODE_CHILD_SESSION` set; otherwise Claude Code ignores the declaration ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#declare-a-scheduled-run)).

## Turn timing and reply attribution

In streaming SDK sessions, `priority` sets mid-turn timing. With `'next'` or `priority` omitted, "Claude reads the message in the same turn, as soon as the tool calls it is running finish" ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkusermessage)). With `'later'`, Claude Code holds the message for a new turn. Headless CLI runs send structured streaming input through `claude -p --input-format stream-json --output-format stream-json --verbose` ([CLI reference](https://code.claude.com/docs/en/cli-reference#cli-flags)).

Setting `isSynthetic: true` changes `user_message_uuid` echoes. A regular message owns its turn for the whole run. On a synthetic message, "the turn answers that message at first. If Claude Code picks up a regular message of yours between tool calls, the turn answers the picked-up message from then on" ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#user_message_uuid)). Echoing a synthetic message's `uuid` requires Agent SDK v0.3.265 or later; earlier versions echo nothing on synthetic turns.

## Why it works

Instruction-hierarchy training targets a root cause of prompt injection: "LLMs often consider system prompts (e.g., text from an application developer) to be the same priority as text from untrusted users and third parties" ([Wallace et al., 2024](https://arxiv.org/abs/2404.13208v1)). The hierarchy sets explicit precedence where "system messages take precedence over user messages, and user messages take precedence over third-party content" ([Wallace et al., 2024](https://arxiv.org/abs/2404.13208v1)).

When a harness injects a fetched page or another agent's output as an unmarked mid-turn message on Opus 4.8+ without fetched flags, Claude Code 2.1.332 counts that text as user input ([changelog 2.1.332](https://code.claude.com/docs/en/changelog#2-1-332)). Setting `isSynthetic: true` keeps it out of the human channel (`unclassified`), and `client_composed: true` blocks slash-command execution and `@path` expansion on the same payload ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkmessageorigin)).

## When this backfires

- Marking genuine human mid-turn input as synthetic removes human provenance. Checks requiring `{ kind: "human" }` fail, including the `ultracode` workflow keyword ([TypeScript SDK reference, origin](https://code.claude.com/docs/en/agent-sdk/typescript#sdkmessageorigin)) and `'now'` backgrounding of active shell, subagent, or MCP calls on Claude Code v2.1.286+ ([TypeScript SDK reference, priority](https://code.claude.com/docs/en/agent-sdk/typescript#sdkusermessage)).
- Setting `isSynthetic: true` on host-declared scheduled runs violates the scheduled-run contract, which requires `task-notification` with `subkind: "scheduled-trigger"` and no `isSynthetic` ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#declare-a-scheduled-run)).
- Setting `isSynthetic: true` without `client_composed: true` leaves untrusted relayed text able to trigger leading `/` commands or `@path` file expansion ([TypeScript SDK reference](https://code.claude.com/docs/en/agent-sdk/typescript#sdkmessageorigin)).
- Relying on `isSynthetic: true` alone leaves tool execution exposed. Anthropic's Agent SDK guide states: "Defense in depth is still good practice though. For example, if an agent processes a malicious file that instructs it to send customer data to an external server, network controls can block that request entirely" ([secure deployment guide](https://code.claude.com/docs/en/agent-sdk/secure-deployment)).
- Lower-priority signals carry an over-refusal cost. Wallace et al. note: "A key risk is that our models learn to never follow lower-priority instructions; in reality, we only want models to ignore lower-priority instructions when they conflict with higher-priority ones" ([Wallace et al., 2024](https://arxiv.org/abs/2404.13208v1)).
- Harnesses that keep external data inside tool results and send only human text as user messages have no relayed user messages to classify. Adding synthetic routing there adds complexity without closing an active path.

## Example

An orchestrator running the TypeScript Agent SDK on Amazon Bedrock (where feature flags are not fetched) relays another agent's output mid-turn while the main agent runs tools.

**Before** — unmarked relay counts as user input on Opus 4.8+ and leaves `/` command and `@path` expansion enabled:

```typescript
const relayed: SDKUserMessage = {
  type: "user",
  message: { role: "user", content: workerReportText },
  parent_tool_use_id: null,
};
```

**After** — marked synthetic, verbatim, and with `origin` unset:

```typescript
const relayed: SDKUserMessage = {
  type: "user",
  message: { role: "user", content: workerReportText },
  parent_tool_use_id: null,
  isSynthetic: true,
  client_composed: true,
};
```

Setting `isSynthetic: true` with `origin` unset lets Claude Code assign `unclassified` instead of treating the text as user-authored, and `client_composed: true` stops any leading `/` or `@path` token in `workerReportText` from running or expanding.

## Key Takeaways

- Audit SDK and `claude -p --input-format stream-json` senders before upgrading to Claude Code 2.1.332 on Opus 4.8+ in cloud-provider, gateway, CI-container, or telemetry-off deployments.
- Send relayed non-human text as its own message with `isSynthetic: true`, `origin` unset, and `client_composed: true`, and never set a reserved `origin` kind such as `peer`.
- Keep human steering on `{ kind: "human" }` and declared scheduled runs on `task-notification` without `isSynthetic`, because mixing classes breaks human-only checks and `user_message_uuid` attribution.
- Pair `isSynthetic: true` with permission rules, sandboxing, and network controls; the flag signals provenance to the runtime and model and does not confine tool execution.

## Related

- [Non-Human Event Provenance Markers to Block Fabricated Approvals](../../security/non-human-event-provenance-markers.md) — harness-emitted non-human provenance markers for background task notifications and transcripts
- [Authority Confusion: Untrusted Context Must Not Authorize Side Effects](../../security/authority-confusion-untrusted-context.md) — dispatch-layer separation between untrusted context and action authorization
- [Authority Disclaimers Read as Permission to Skip a Step](../anti-patterns/authority-disclaimers-read-as-skip-permission.md) — how an unbounded non-user-authority note can trigger over-refusal in delegated steps
- [Steering Running Agents: Mid-Run Redirection and Follow-Ups](steering-running-agents.md) — mid-turn redirection and queued follow-up mechanics across agent harnesses
- [Claude Agent SDK](../../tools/claude/agent-sdk.md) — overview of the Claude Code runtime exposed as a TypeScript and Python library
