Replit Agent broke my code: features it wasn't asked to touch
Symptoms
- You ask the Agent to add one feature and unrelated parts of the app break: forms stop submitting, API endpoints error, auth stops working
- After you manually edit a file, the Agent keeps reasoning about the old version, as if your changes never happened
- The Agent 'fixes' things based on stale code and silently reverts or conflicts with your hand-written changes
- git diff shows edits in files you never mentioned in the prompt
Why it happens
The Agent edits shared code to implement narrow requests
While implementing a request, the Agent freely modifies shared utilities, config files, and base components. Those edits ripple into dependent code it never re-tested, which is how adding a feature breaks login.
The Agent caches its own copies of files
Users on Replit's forum documented that the Agent appears to cache file contents and does not always re-read manual edits made outside the Agent. Its next change can then silently revert or conflict with your hand-written code because it is working from a stale copy.
How to fix it
- Commit or fork before every Agent sessionCreate a commit, checkpoint, or fork before letting the Agent work. This gives you a clean revert point, and it makes the next step (auditing the diff) meaningful.
- Audit the damage with git diff HEADAfter each Agent task, run git diff HEAD in the Shell and scan the list of changed files before testing anything. Files you did not expect it to touch are where the collateral breakage lives.
- Re-test core flows, not just the new featureAfter each Agent change, re-test the flows that matter: login, save, pay. The new feature working tells you nothing about what the Agent's edits to shared code did elsewhere.
- Force the Agent to see your manual editsIf the Agent is reasoning about stale file contents after your manual edits, start a new Agent chat and explicitly tell it to re-read the specific files, or paste the current file contents into the prompt. Do not keep arguing with it in the old chat; the cached copy wins that argument.
- Restore individual files with File HistoryUse the File History tool to restore clobbered files one at a time rather than a full checkpoint rollback, which rewinds conversation and database state along with the code.
- Scope prompts to named filesPrompts like 'only modify routes/checkout.js' reduce collateral edits. The narrower the stated scope, the less shared code the Agent wanders into.
How to prevent it
- Commit, checkpoint, or fork before every Agent session, no exceptions
- Make git diff HEAD a reflex after every Agent task
- Keep a short list of core flows (login, save, pay) and re-test them after each change
- Scope every prompt to the specific files the Agent is allowed to modify
- After manual edits, start a fresh Agent chat and have it re-read the changed files before it writes anything
Tools that actually fix this
Recommended because they address the failure mode above, not because of the payout. Some are affiliate links; see how we choose.
Automated, scheduled backups of your database and storage so the AI's next confident refactor is survivable. Set it once and stop trusting an agent with your only copy.
Try SimpleBackups →Backup and recovery for your Git repositories, so a force-push or an agent's cleanup does not take your history with it. Free for open-source projects.
Try GitProtect →Frequently asked questions
Why did Replit Agent change files I didn't ask it to touch?
While implementing your request, the Agent freely modifies shared utilities, config files, and base components, and those edits ripple into dependent code it never re-tested. Run git diff HEAD in the Shell after each Agent task to see the full list of files it changed, and scope prompts to named files to limit the blast radius.
Why doesn't Replit Agent see my manual code edits?
Users on Replit's forum documented that the Agent appears to cache its own copies of files and does not always re-read manual edits made outside the Agent. The fix is to start a new Agent chat and explicitly tell it to re-read the specific files, or paste the current file contents into the prompt so it works from the real code.
How do I see everything Replit Agent changed?
Run git diff HEAD in the Shell after the Agent finishes. It shows every modified file against your last commit, including files you never mentioned in the prompt, which is where unexpected breakage usually hides. This only works if you committed before the session, which is why a pre-session commit or fork is the habit to build.
How do I restore a single file the Agent overwrote?
Use Replit's File History tool from the Tools sidebar, which keeps per-file version history independent of Agent checkpoints. It restores the one clobbered file without a full checkpoint rollback, which would also rewind the Agent conversation and development database state.
Sources
- Replit forum: Manual changes to files are not seen by Agent, it seems to cache old versions
- AppStuck: Replit not working, 10 common errors and how to fix them
- Sidetool: Replit Agents technical FAQ, solving common setup and coding challenges
Related errors
Cursor Keeps Breaking My Working Code While 'Improving' Something Else
Cursor's Apply Model Made No Changes to the File (or Mangled the Edit)
Replit rollback not working: checkpoint doesn't restore what you expected
Replit Agent stuck in a loop, burning credits on failed fixes
The Vibe Oops briefing
One email when something ships to production that should not have. New incidents, new error guides, no filler.