Prevent agent confusion from auto-formatting by formatting in agent context #3754

Closed
opened 2026-02-16 17:41:21 -05:00 by yindo · 2 comments
Owner

Originally created by @gergesh on GitHub (Dec 22, 2025).

Originally assigned to: @thdxr on GitHub.

Description

When agents write code (e.g., in Python) using the write tool, the code is automatically reformatted afterward, changing e.g. single quotes to double quotes. This causes confusion because the code that appears in files is not what agents intended or generated, leading to mismatches and re-read loops.

A possible solution is to modify the formatting workflow so that formatting occurs in the "agent's context" before the content is written to disk. The agent would in later turns see the formatted code. This way, the agent is never surprised by changes that were made after the fact, and will probably even use that style later on.

OpenCode version

1.0.185

Steps to reproduce

  1. Use the write tool or agent to write Python code with single quotes
  2. Observe formatting is changed after code is written, causing confusion
  3. Consider agent context formatting as a solution

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @gergesh on GitHub (Dec 22, 2025). Originally assigned to: @thdxr on GitHub. ### Description When agents write code (e.g., in Python) using the write tool, the code is automatically reformatted afterward, changing e.g. single quotes to double quotes. This causes confusion because the code that appears in files is not what agents intended or generated, leading to mismatches and re-read loops. A possible solution is to modify the formatting workflow so that formatting occurs in the "agent's context" before the content is written to disk. The agent would in later turns see the formatted code. This way, the agent is never surprised by changes that were made after the fact, and will probably even use that style later on. ### OpenCode version 1.0.185 ### Steps to reproduce 1. Use the write tool or agent to write Python code with single quotes 2. Observe formatting is changed after code is written, causing confusion 3. Consider agent context formatting as a solution ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:41:21 -05:00
yindo closed this issue 2026-02-16 17:41:21 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 22, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #2529: Idea to replace edit tool input string with formatted code to prevent agent confusion from formatting changes

Both issues address the core problem of agents being confused when code is auto-formatted after being written, causing mismatches and re-read loops. Issue #2529 proposes a similar solution of modifying the agent's context so the agent sees the formatted code in subsequent turns.

@github-actions[bot] commented on GitHub (Dec 22, 2025): This issue might be a duplicate of existing issues. Please check: - #2529: Idea to replace edit tool input string with formatted code to prevent agent confusion from formatting changes Both issues address the core problem of agents being confused when code is auto-formatted after being written, causing mismatches and re-read loops. Issue #2529 proposes a similar solution of modifying the agent's context so the agent sees the formatted code in subsequent turns.
Author
Owner

@gergesh commented on GitHub (Dec 22, 2025):

Yep that's a duplicate, closing

@gergesh commented on GitHub (Dec 22, 2025): Yep that's a duplicate, closing
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3754