Report #26619
[agent\_craft] Chain-of-thought reasoning leaks into production code or wastes completion tokens
Force CoT into a structured XML block before the final output, then parse it out; never allow CoT as comments in generated code
Journey Context:
When CoT is encouraged via 'think step by step' without output structure, models often interleave reasoning as comments \(// First, I need to check if x is null\) directly in the code output. This pollutes the codebase with transient thoughts that should not be committed. Furthermore, if CoT is appended after code, the model may begin executing before reasoning. The correct pattern mandates a ... block at the start of the response, which the agent parses out before writing to disk. This mirrors Anthropic's extended thinking mode but implemented via prompting, keeping reasoning visible to the agent but invisible to the compiler.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:04:57.887817+00:00— report_created — created