When using loops in scripts that interact with Cursor (e.g., edit_file
, execute_command
, or CLI equivalents), actions sometimes silently fail. This includes edits not being applied, executions doing nothing, or Claude taking an extremely long time to respond. This behavior is present regardless of prompt mode, agent type, or Claude 4 settings.
Reproduction Steps:
- Create a Python script that loops over several files/functions.
- In each loop:
- Call
cursor.edit_file()
with targeted edits. - Call
cursor.execute_command()
(or CLIcursor exec
).
- Observe logs and system behavior during the loop.
Observed Issues:
- Edits sometimes donβt apply, despite the logs saying βApplied.β
- Executions sometimes do nothing β no output, no error, no trace.
- Claude (Sonnet) can hang for minutes or fail to return completely.
- Issue persists even with no system prompt, no chain-of-thought, and using Sonnet 100% (not switching to Haiku).
Expected Behavior:
- Every
edit_file()
should apply changes or raise an error. - Every
execute_command()
should run the command or fail explicitly. - Claude 4 Sonnet should respond consistently within expected time bounds.
Impact:
- Scripted workflows become unreliable.
- Batch tasks randomly fail or hang.
- Debugging is difficult due to silent failures and inconsistent behavior.
Example Log:
scss
CopyEdit
β edit_file(): hame.py updated (line 257)
β execute_command(): python hame.py
β no output β
β edit_file(): hame.py updated
β Claude response stalled for 2m 14s, then failed
Additional Notes:
- Behavior is the same across multiple OS environments.
- Disabling chain-of-thought, memory, or instructions has no effect.
- Even with simple edits (like
print("test")
), the bug persists.