My Claude Code Setup Kept Crashing During Git Commits

CyberSmith Advanced 1h ago 334 views 0 likes 5 min read

I spent four hours last Thursday fighting with a terminal loop that nearly made me delete my entire .zshrc file. I was trying to migrate a legacy React project to a more modern stack using a mix of new AI tooling, and I thought I had the "perfect" workflow: Claude Code for the heavy terminal lifting and Windsurf for the actual codebase navigation.

My Claude Code Setup Kept Crashing During Git Commits

Everything was smooth until I tried to let Claude Code handle a series of complex refactors across twelve different files. I gave it a high-level instruction to standardize my API response types. It did the work. It actually did it. But the second I told it to commit the changes, the terminal exploded into a recursive loop of shell errors.

The error message looked something like this:
Error: Unexpected token in shell output: 'fatal: not a git repository (or any of the parent directories)'
Current working directory: /Users/dev/projects/legacy-app/src/components/ui

Wait. I was in the root directory. Or I thought I was.

The diagnosis of the context drift

Here is the thing about how to use Claude Code—and this is the part the documentation doesn't explicitly scream at you—it maintains its own sense of state and directory tracking. I had used a few cd commands within the chat session to check some folder structures, and the agent had "drifted."

It was trying to execute git commit from inside /src/components/ui. Obviously, Git failed. But instead of just telling me "Hey, I'm in the wrong folder," the agent tried to "fix" the error by searching for the .git folder, which triggered another shell command, which failed, which triggered another search.

It was a death spiral of AI trying to be too helpful.

I realized I was treating the CLI agent like a magic wand rather than a shell process. To stop the bleeding, I had to kill the process (Ctrl+C three times, because it was stubborn) and restart the session with a hard reset of the working directory.

Swapping between Windsurf and CLI tools

The wild part is that I didn't even need Claude Code for that specific commit. I had the Windsurf editor open right next to it.

For those who haven't tried it, Windsurf's "Flow" state is significantly better at understanding the physical layout of the project because it's integrated into the IDE. While Claude Code is a powerhouse for executing terminal commands and running tests in a loop, Windsurf is where I actually live in the code.

I found that the most stable way to operate is a "Split Brain" approach. I use Windsurf for the structural changes and the "big picture" refactoring because the IDE context is more stable. I save Claude Code for the "destructive" or "verification" tasks—like running a complex grep across the whole repo or executing a series of bash scripts to clean up build artifacts.

If you try to make one tool do everything, you end up with the directory drift I hit.

Why Claude Projects guide-style organization saved my sanity

how to use Claude Code, Windsurf editor, Claude Projects guide

Once I got the git loop sorted, I hit another wall: the AI was starting to forget the specific architectural constraints of my project. It kept suggesting useEffect hooks in places where I had already moved to a custom state management library.

I had to stop and actually organize my context. I started using a dedicated "Project Knowledge" file—essentially a manual Claude Projects guide that I kept in a .claudeproj folder in my root.

Instead of relying on the LLM to remember the whole repo (which, let's be real, it doesn't—it just has a massive window that eventually gets diluted), I created a CONTEXT.md file. This file contained:
1. The exact version of my dependencies (React 18.2, Vite 5.0).
2. A list of "Banned Patterns" (e.g., "Do not use Axios, use the native fetch wrapper in /lib/api.ts").
3. The naming convention for my components.

Now, every time I start a session with Claude Code or a new flow in Windsurf, I point the tool to that file first. "Read CONTEXT.md before you suggest any code."

The difference in accuracy is night and day. I went from 40% hallucinated imports to maybe 5% over the course of a week.

Tool comparison for the actual dev loop

I've spent the last month jumping between these tools. Since everyone asks which one to use when, I mapped out my actual usage patterns:

| Task | Winner | Why? |
| :--- | :--- | :--- |
| Rapid Prototyping | Windsurf | The IDE integration makes jumping between files 10x faster. |
| Terminal Automation | Claude Code | It handles shell pipes and CLI output way better than an IDE plugin. |
| Complex Architecture | Claude Projects | High-level planning and "knowledge" persistence. |
| Debugging a Crash | Claude Code | Ability to run npm test and iterate on the error in real-time. |

The "Aha!" moment with MCP

The real game-changer happened when I integrated the Model Context Protocol (MCP). I stopped manually copy-pasting logs.

I set up a local MCP server that gave the AI direct access to my database schema. Instead of me explaining, "The users table has a uuid and an email," I just let the agent query the schema. The speed of development jumped because I stopped being the "middleman" for information.

When you stop treating AI as a chat box and start treating it as a system with access to your environment, the friction disappears.

Finding the right crowd

Trying to figure this out in a vacuum is exhausting. I spent way too long troubleshooting that Git loop on my own before I realized there are hundreds of us hitting the exact same walls.

That's why I leaned into the PromptCube homepage community. It isn't just about "writing a better prompt." It's about these weird, specific edge cases—like how to prevent a CLI agent from getting lost in your subdirectories or how to structure a project guide so the AI actually follows the rules.

If you're tired of the "generic" AI advice and want to see how people are actually building production apps with these tools, you can join the community. It's where the actual debugging happens, far away from the polished marketing demos.

The fix for my original problem? Simple. Always check your pwd (print working directory) if the AI starts acting erratic. And for heaven's sake, keep a CONTEXT.md file. Your future self will thank you.

Related examples in this direction are worth a look in these real-world AI monetization case studies, with plenty of directly applicable cases.

All Replies (0)

No replies yet — be the first!

Write a Reply

Markdown supported