Skip to content
ONECLICKTOOLINDEPENDENT STUDIO

Running Your AI Agent in the Wrong Project Folder

You gave the agent a clear task and it edited the wrong repo. Why agents end up in the wrong folder with many projects, and how to make it nearly impossible.

By · Oct 19, 2026 · 2 min read

RedditXLinkedInFacebook
A developer bites her thumbnail, staring at two screens of near-identical project folder trees.
On this page · 7 sections
  1. The short answer
  2. Why it happens
  3. Open from the task, always
  4. Make the first prompt a check
  5. If it already happened
  6. Keep reading
  7. Frequently asked questions

You asked the agent to rename the settings screen. It did — beautifully — in the other app. The two repos have the same structure, the same screen names, and you had four terminals open. You picked the wrong one.

Now there's an unwanted change in one repo and none in the other.

Part 7 of No Process — the folder mistake that gets more likely with every project you add.

The short answer#

  • With many similar repos, it's easy to start an agent in the wrong folder — and it will happily do the task there.
  • The agent's working folder decides what it reads, what it edits and where its session is saved.
  • Always open the agent from the task, which knows its folder, instead of from whatever terminal is open.
  • Make the first prompt of each session confirm the project: 'read the state file and tell me which project this is'.

Why it happens#

An agent works where it's started. Its working folder decides:

  • What it reads — the code, the notes, the rules file.
  • What it edits — every change lands there.
  • Where its session is saved — so later you can't find the session where you expect it.

With many projects, it's easy to start in the wrong place: a terminal left open from earlier, a cd you forgot, two repos built from the same template. And the agent won't object — the task makes sense in either repo.

Open from the task, always#

The most reliable fix is the one from the terminal maze: never start an agent from whatever window happens to be open. Start from the task, and let the task decide the folder.

If you do it by hand, a tiny alias per project helps:

alias tip='cd ~/code/tip-split && claude'
alias dino='cd ~/code/dino-buddies && claude'

Typing the project's name to start is much harder to get wrong than trusting the current terminal.

Make the first prompt a check#

Start every session with a prompt that makes the agent confirm where it is:

"Read the state file and tell me in one line which project this is and what the next step is."

If the answer is the wrong project, you've lost five seconds instead of an afternoon. It also doubles as the normal session start from the minimum process.

If it already happened#

Don't panic and don't reset everything. Run git status in the wrong repo, look at the changed files, and revert what doesn't belong there. If some of it is useful for the right project, ask the agent to redo it there — with the state file read first.

Keep reading#

Frequently asked questions

What happens if I start Claude Code in the wrong directory?

It reads and edits files in that directory, and saves the session under that folder. The work lands in the wrong project and the session won't show up where you look later.

How do I undo changes an AI agent made in the wrong repo?

If nothing was committed, git status shows the changed files and git restore can revert them. Review before reverting — some changes might be useful elsewhere.

How can I prevent agents from working in the wrong folder?

Open sessions from the task rather than a random terminal, keep one project per session, and start each session by having the agent read and confirm the project's state file.

Sources

  1. Claude Code overview — Anthropic docs
  2. Common workflows — Claude Code docs

Found this useful? Share it on Reddit or pass it on.

RedditXLinkedInFacebook