{"slug": "my-claude-code-setup-kept-crashing-during-git-commits", "title": "My Claude Code Setup Kept Crashing During Git Commits", "summary": "A developer's Claude Code setup crashed during Git commits due to context drift, where the AI agent attempted to run git commands from a subdirectory, causing a recursive loop of shell errors. The developer resolved the issue by killing the process and adopting a 'Split Brain' approach, using Windsurf for structural changes and Claude Code for verification tasks, and creating a CONTEXT.md file to maintain project context.", "body_md": "# My Claude Code Setup Kept Crashing During Git Commits\n\n`.zshrc`\n\nfile. 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](/en/tags/claude%20code/)for the heavy terminal lifting and Windsurf for the actual codebase navigation.\n\nEverything was smooth until I tried to let [Claude](/en/tags/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.\n\nThe error message looked something like this:`Error: Unexpected token in shell output: 'fatal: not a git repository (or any of the parent directories)'`\n\n`Current working directory: /Users/dev/projects/legacy-app/src/components/ui`\n\nWait. I was in the root directory. Or I thought I was.\n\n### The diagnosis of the context drift\n\nHere 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`\n\ncommands within the chat session to check some folder structures, and the agent had \"drifted.\"\n\nIt was trying to execute `git commit`\n\nfrom inside `/src/components/ui`\n\n. 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`\n\nfolder, which triggered another shell command, which failed, which triggered another search.\n\nIt was a death spiral of AI trying to be too helpful.\n\nI 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`\n\nthree times, because it was stubborn) and restart the session with a hard reset of the working directory.\n\n### Swapping between Windsurf and CLI tools\n\nThe wild part is that I didn't even need Claude Code for that specific commit. I had the [Windsurf editor](/en/) open right next to it.\n\nFor 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.\n\nI 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.\n\nIf you try to make one tool do everything, you end up with the directory drift I hit.\n\n### Why Claude Projects guide-style organization saved my sanity\n\nOnce 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`\n\nhooks in places where I had already moved to a custom state management library.\n\nI had to stop and actually organize my context. I started using a dedicated \"Project Knowledge\" file—essentially a manual [Claude Projects guide](/en/category/workflows/) that I kept in a `.claudeproj`\n\nfolder in my root.\n\nInstead 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`\n\nfile. This file contained:\n\n1. The exact version of my dependencies (React 18.2, Vite 5.0).\n\n2. A list of \"Banned Patterns\" (e.g., \"Do not use Axios, use the native fetch wrapper in /lib/api.ts\").\n\n3. The naming convention for my components.\n\nNow, 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.\"\n\nThe difference in accuracy is night and day. I went from 40% hallucinated imports to maybe 5% over the course of a week.\n\n### Tool comparison for the actual dev loop\n\nI've spent the last month jumping between these tools. Since everyone asks which one to use when, I mapped out my actual usage patterns:\n\n| Task | Winner | Why? |\n\n| :--- | :--- | :--- |\n\n| Rapid Prototyping | Windsurf | The IDE integration makes jumping between files 10x faster. |\n\n| Terminal Automation | Claude Code | It handles shell pipes and CLI output way better than an IDE plugin. |\n\n| Complex Architecture | Claude Projects | High-level planning and \"knowledge\" persistence. |\n\n| Debugging a Crash | Claude Code | Ability to run `npm test`\n\nand iterate on the error in real-time. |\n\n### The \"Aha!\" moment with [MCP](/en/tags/mcp/)\n\nThe real game-changer happened when I integrated the Model Context Protocol (MCP). I stopped manually copy-pasting logs.\n\nI 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.\n\nWhen you stop treating AI as a chat box and start treating it as a system with access to your environment, the friction disappears.\n\n### Finding the right crowd\n\nTrying 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.\n\nThat's why I leaned into the [PromptCube homepage](/en/) 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.\n\nIf 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.\n\nThe fix for my original problem? Simple. Always check your `pwd`\n\n(print working directory) if the AI starts acting erratic. And for heaven's sake, keep a `CONTEXT.md`\n\nfile. Your future self will thank you.\n\n[Next crewai-go v0.4. →](/en/threads/6728/)\n\n[these real-world AI monetization case studies](https://tanyan888.com/), with plenty of directly applicable cases.\n\n## All Replies （0）\n\nNo replies yet — be the first!", "url": "https://wpnews.pro/news/my-claude-code-setup-kept-crashing-during-git-commits", "canonical_source": "https://promptcube3.com/en/threads/6800/", "published_at": "2026-08-18 14:28:59+00:00", "updated_at": "2026-08-18 14:42:06.658867+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "artificial-intelligence"], "entities": ["Claude Code", "Windsurf", "React", "Vite"], "alternates": {"html": "https://wpnews.pro/news/my-claude-code-setup-kept-crashing-during-git-commits", "markdown": "https://wpnews.pro/news/my-claude-code-setup-kept-crashing-during-git-commits.md", "text": "https://wpnews.pro/news/my-claude-code-setup-kept-crashing-during-git-commits.txt", "jsonld": "https://wpnews.pro/news/my-claude-code-setup-kept-crashing-during-git-commits.jsonld"}}