When a coding agent summarizes a patch, it might get the information from an ordinary git diff --stat. The model determines that it needs information about the changed files. The software around it, the agent harness, makes the call and returns the data. The distinction becomes visible when another program drives the agent through a programmatic interface.

From a model request to a command result

Consider the request “Summarize the current changes.” The harness prepares the context with the task and available tools. If the model picks the shell, it returns a structured request for that tool. The harness checks its tool policy and the runtime starts the command in the working directory with the configured permissions. Command output and exit status become a tool result. The harness puts that result into the next request to the model, which can answer or ask for another call. If the command lacks access, the denial itself can inform the next step. How Anthropic separates sessions, the harness, and the sandbox

The same loop works for external tools. For an MCP call, the relevant client contacts a server in place of starting a shell command. For a skill, the harness can load the procedure into context. Any call that follows still goes through the tool execution and permission layers. MCP tool execution · Claude Agent SDK capabilities

How a program observes the loop

Codex CLI has a non-interactive mode. For example, a parent process can request a summary and read one JSON object per line of standard output.

codex exec --sandbox read-only --json "Summarize the working-tree diff."

This is a documented interface example. The commands the model actually selects depend on the request and available context. In the Codex stream, thread.started provides a session identifier, item.* events describe individual items such as command executions, and turn.completed or turn.failed reports the turn outcome. The consumer can read the final event together with the process exit status. If the process ends before emitting a final event, the consumer can record an interrupted run. Codex non-interactive mode

Claude Code has its own stream-json format. A Python or TypeScript application can also use the Claude Agent SDK for message objects and tool approval callbacks. Event schemas depend on the interface. An orchestrator that supports both clients can map their events to a few states the application needs, such as started, result available, and failed, and keep the original stream for diagnosis. Run Claude Code programmatically · Claude Agent SDK overview