Hackcat

How to Have Agent Modify Files and Confirm Correct Changes?

Define the changes first, then verify the results; check existing content before retrying after failure.

Clarify Whether to Replace, Append, or Partially Edit

Agent can write text, append content, or perform targeted replacements. Clearly specify the file, the purpose of the modification, and the content to be retained in the request—for example, only fix a certain configuration section without adjusting other parts.

Rewriting the entire file and appending at the end have different effects; avoid vague instructions like "update it" that make the scope unclear.

Verify in Small Scope

Keep a recoverable backup of important files first, then have the Agent explain the changes and perform checks appropriate for the file.

For example, when modifying configurations, require that unrelated configuration items be retained and specify the criteria for verification. If the replacement position is not unique, review the context before modifying; do not let the agent replace all occurrences just because the text is the same.

  1. Confirm the environment and file location are correct.
  2. Specify the behaviors that need to be changed and those that must be preserved.
  3. Review specific modifications in approval mode.
  4. Check differences or run related validations to confirm the results meet the objectives.

Do Not Blindly Retry After Interruption

A lost response does not necessarily mean the file was not written. After reconnecting, first check the existing content before deciding whether to retry, especially for append operations, as repeated execution may cause duplicate entries. If file operations are denied, adjust the scope or obtain proper authorization; do not bypass denial by writing through the terminal. Changes in permission mode will not automatically undo completed modifications.