[Feature] Allow workflow scripts to mark agent results as failed (red indicator)
Problem
When using the Workflow tool with agent(), the left-panel status indicators only show red (✗) when an agent experiences a runtime error (stall timeout, API error, user skip, StructuredOutput retry cap exceeded). There is no mechanism to mark an agent as failed based on its logical outcome.
Use Case
I have a deployment/regression workflow that:
- Triggers a CI pipeline
- Polls for completion
- Returns the result (PASSED/FAILED)
When the regression fails, the agent completes successfully (green ✔) because it ran without runtime errors — even though the business outcome is a failure. The workflow then throws to stop execution, which marks the overall workflow as failed, but the individual agent still shows green.
What I've Tried
exit 1in bash — agent handles it gracefully, still returns text- Schema tricks — agent reads the schema and always conforms
throw new Error()— only affects the workflow level, not the agent that already completed- Intentionally calling non-existent tools — agent catches gracefully
- Setting
MAX_STRUCTURED_OUTPUT_RETRIES=1with impossible schemas — unreliable since model reads the schema
Proposed Solutions (any of these would work)
agent(prompt, { failIf: (result) => boolean })— callback that, if returns true, marks the agent as error state in the UIagent(prompt, { assertSuccess: true })combined with the agent calling aReportFailuretool — explicit opt-in failure reporting- Allow
throwinsideagent()to propagate as agent error — if the agent itself throws (via a mechanism like calling a special tool), show red - Post-hoc marking:
markFailed(agentResult)function in workflow scripts that retroactively changes the progress indicator
Expected Behavior
When a workflow agent produces a result that the script determines is a failure, the /workflows left panel should show a red ✗ for that specific agent — not just for the overall workflow.
Environment
- Claude Code CLI (latest)
- macOS
- Using named workflows (
.claude/workflows/)