Write tool destroys sibling files when path contains parentheses (Next.js route groups)

Resolved 💬 2 comments Opened Feb 8, 2026 by igornumeriano Closed Mar 9, 2026

Bug Description

The Write tool destroys all sibling files and directories when writing to a path that contains parentheses — specifically Next.js App Router route groups like (dashboard), (marketing), and (auth).

Steps to Reproduce

  1. Have a Next.js 15 project with route groups:

``
apps/web/
├── app/
│ ├── (dashboard)/painel/page.tsx
│ ├── (marketing)/page.tsx
│ ├── (auth)/entrar/page.tsx
│ └── api/...
├── server/...
├── components/...
├── lib/...
├── package.json
├── next.config.ts
└── tsconfig.json
``

  1. Use the Write tool to write/overwrite files inside (dashboard) or (marketing) directories, e.g.:
  • apps/web/app/(dashboard)/painel/page.tsx
  • apps/web/app/(dashboard)/cobranca/page.tsx
  • apps/web/app/(dashboard)/agentes/page.tsx
  • apps/web/app/(marketing)/page.tsx
  1. After the Write operations complete, ALL other files in apps/web/ are gone — only the explicitly written page.tsx files survive.

Expected Behavior

Writing to apps/web/app/(dashboard)/painel/page.tsx should only create/overwrite that single file, leaving all other files untouched.

Actual Behavior

The Write tool appears to recreate the parent directory tree when the path contains parentheses, destroying all sibling files and directories. The entire apps/web/ directory was wiped except for the 6 page.tsx files that were explicitly written.

Files destroyed (~50+ files):

  • package.json, next.config.ts, tsconfig.json, postcss.config.mjs
  • middleware.ts, app/layout.tsx, app/globals.css
  • All components/ui/*.tsx (7 shadcn components)
  • All server/services/*.ts (7 service files)
  • All server/trpc/**/*.ts (router, init, 3 routers)
  • All lib/*.ts (trpc client, utils)
  • All app/api/**/*.ts (6 API routes)
  • All auth page files
  • Dashboard and marketing layouts

Impact

  • Token cost: The conversation ran out of context (Opus 4.6 full context window exhausted ~200k tokens) trying to recover. A continuation session was needed to rebuild all files from memory, debug type errors, and verify the build. Estimated total cost: 500k-1M+ input/output tokens on Opus.
  • Time cost: Several hours of work lost and had to be reconstructed.
  • Data loss: All files had to be reconstructed from the AI's memory of reading them earlier in the conversation. Some nuances may have been lost.

Environment

  • Claude Code version: Latest (as of 2026-02-08)
  • Model: Claude Opus 4.6
  • OS: macOS (Darwin 24.5.0)
  • Next.js: 15.5.12
  • Monorepo: Turborepo + pnpm

Workaround

None known. The parentheses in Next.js route group directory names (dashboard), (marketing), (auth) seem to confuse the Write tool's path handling.

Additional Context

This is a critical bug as Next.js App Router's route groups (using parentheses) are an extremely common pattern. Any project using route groups is at risk of catastrophic file loss when the Write tool is used.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗