Add structured JSON logging for observability and debugging.
agent --log=debug ./workflow.md 2>debug.jsonl
{"type": "start", "model": "claude-sonnet-4", "provider": "openrouter", "timestamp": "..."}
{"type": "thinking", "content": "Let me analyze this...", "iteration": 1}
{"type": "tool_call", "tool": "run_bash", "args": {...}, "iteration": 1}
{"type": "tool_result", "tool": "run_bash", "success": true, "output": "..."}
{"type": "complete", "iterations": 5, "cost_cents": 2.3, "tokens": 1500}
{"type": "error", "message": "..."}
--log=info - Start, complete, errors--log=debug - + tool calls, thinking--log=trace - + full API payloads