Skip to content

feat: expose final_message step output for defense-in-depth review workflows#1355

Open
stanley1208 wants to merge 1 commit into
anthropics:mainfrom
stanley1208:feat/expose-final-message-output
Open

feat: expose final_message step output for defense-in-depth review workflows#1355
stanley1208 wants to merge 1 commit into
anthropics:mainfrom
stanley1208:feat/expose-final-message-output

Conversation

@stanley1208
Copy link
Copy Markdown

Closes #1317.

Adds a final_message step output containing the agent's final text response, pulled from the last message in the SDK stream.

The use case the issue describes is read-only review workflows: run the AI job with contents: read only, then post the response from a separate job that has pull-requests: write. Right now you can't really do that. The only way to get the response text is to parse execution_file, which has no documented format. The openai/codex-action repo solves it with a final-message output, which is what the issue references.

Usage

- uses: anthropics/claude-code-action@vX
  id: review
  with:
    anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

- name: Post review
  env:
    REVIEW: ${{ steps.review.outputs.final_message }}
  run: gh pr review --comment --body "$REVIEW"

A note on naming

The issue uses final-message (kebab-case) because that's what codex-action uses. I went with final_message (snake_case) to match the other outputs in this repo (execution_file, structured_output, session_id). Easy to swap if you'd rather match codex-action.

How it works

A small helper called extractFinalAssistantMessage in base-action/src/run-claude-sdk.ts walks the message stream backwards, finds the last assistant message, and joins its text blocks. If the last action was a tool call (no text), the output is undefined. The intent is that "final message" should mean what the agent actually said.

Wired through both layers (the standalone base-action and the parent action). Added 10 unit tests for the edge cases: empty stream, multiple text blocks, text + tool_use mixed, tool-only last message, malformed content.

Checks

Ran bun test (10 new pass, no regressions), bun run typecheck, and bun run format:check.

Adds a final_message output containing the agent's final text response.
The use case is read-only review workflows where the AI job runs with
contents:read only, and a separate job with pull-requests:write posts
the response (defense-in-depth).

Today the only way to get this text is parsing execution_file, which
has no documented format. Follows the same pattern as
openai/codex-action's final-message output that anthropics#1317 references.

Includes 10 unit tests for the extraction helper.

Closes anthropics#1317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: expose final assistant message as step output (like codex-action's final-message)

1 participant