Gemini CLI Creating Corrupted Files with Binary Data and Invisible Characters
Summary
Gemini CLI is systematically corrupting TypeScript files by embedding binary data, invisible Unicode characters, and invalid text encoding, causing thousands of TypeScript compilation errors and making files unreadable in VS Code.
Environment
OS: macOS Project: TypeScript monorepo with Turborepo + pnpm TypeScript Version: 5.8.3 Version: 1.102.0-insider (Universal) Commit: b68fa590ef54bc8f07dd79cd3175bf78e0113d4c Date: 2025-06-27T05:03:40.827Z Electron: 35.5.1 ElectronBuildId: 11727614 Chromium: 134.0.6998.205 Node.js: 22.15.1 V8: 13.4.114.21-electron.0 OS: Darwin arm64 24.5.0 Gemini CLI: 0.1.5. .... also happening in 0.1.7
Problem Description
Primary Issue Gemini CLI is creating files that appear normal but contain severe corruption:
Binary data embedded in text files - VS Code displays warning: "The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding" Thousands of invisible Unicode characters appended to otherwise valid code Invalid character encoding causing TS1127 compilation errors
### Impact Thousands of TypeScript compilation errors (TS1127 "Invalid character") Build failures across entire monorepo Files become unreadable in VS Code due to encoding corruption Development completely blocked until files are manually recreated
### Affected Files All files created by Gemini CLI in firebase directory:
index.ts - Severe corruption: Binary/unsupported encoding, unreadable in VS Code mfa.ts - Invisible character corruption: Thousands of invisible Unicode characters monitoring.ts - Invisible character corruption: TS1127 errors validation.ts - Previously corrupted, manually fixed firebaseConfig.ts - Previously corrupted, manually fixed
Reproduction Steps
- Use Gemini CLI to create or edit any TypeScript file
- File appears normal in CLI output
- Open file in VS Code - shows encoding warning or appears corrupted
- Run TypeScript compilation - generates thousands of TS1127 errors
- Check file size - significantly larger than expected due to invisible content
Expected Behavior Files should contain only visible ASCII/UTF-8 characters Files should end with single newline character only No binary data, invisible characters, or encoding corruption TypeScript compilation should succeed without character-based errors
Actual Behavior Files contain embedded binary data making them unreadable Massive amounts of invisible Unicode characters appended Invalid text encoding preventing normal editing TypeScript parser fails with TS1127 "Invalid character" errors
Evidence File Size Comparison VS Code Error Message TypeScript Compilation Errors
Workaround Delete corrupted files completely (copying preserves corruption) Manually recreate files with clean content Avoid using Gemini CLI until issue is resolved
Investigation Notes Pattern: Corruption occurs specifically in TypeScript files Scope: Systematic corruption across multiple files in same directory Severity: Project-breaking - prevents compilation and development Detection: Files appear normal in CLI but fail in actual development environment
Requested Fix Immediate: Prevent binary data embedding in text files Character validation: Ensure only valid UTF-8 characters in output File ending: Proper file termination without invisible padding Encoding verification: Validate text encoding before file creation
Business Impact Development completely blocked due to build failures Loss of work requiring manual file recreation Trust issues with AI-generated code due to corruption Time waste debugging invisible character issues instead of actual development Priority: Critical - Blocks all development work Category: File I/O, Text Encoding, Code Generation Reproducibility: 100% - Every file created by Gemini CLI is corrupted
This bug represents a fundamental issue with Gemini CLI's file creation mechanism that makes it unsuitable for professional development until resolved.
attempted to reproduce this bug on Gemini CLI v0.1.5 and v0.1.7 but I couldn’t replicate the file corruption issue. Files opened cleanly in VS Code, contained only visible ASCII/UTF-8 content, and TypeScript compiled without TS1127 errors. Is there a specific command, file path pattern, or system locale setting that might be triggering this?
Thanks for attempting to reproduce this! The corruption seems to be triggered by specific conditions. Here are the key factors that might be necessary to replicate:
Environment Specifics
- macOS (my environment - may be OS-specific)
- TypeScript monorepo with Turborepo + pnpm workspaces
- Large project context (15+ packages, complex dependency graph)
- Extended CLI sessions (corruption appeared after multiple file operations)
Reproduction Conditions
The corruption doesn't happen immediately - it manifested after:
- Multiple file creation/editing operations in the same CLI session
- Working with TypeScript files specifically (.ts, .tsx)
- Creating files in nested package directories like firebase
- Long-running CLI sessions (30+ minutes of active use)
Specific Commands That Triggered Issues
Example commands that preceded corruption:
- Creating multiple TypeScript interface files
- Editing existing Firebase authentication modules
- Generating cross-platform implementation files
- Creating index.ts barrel exports
- I did notice some corruptions would happen after attempting to build
File Patterns Affected
- All occurred in firebase directory
- TypeScript files with JSDoc comments
- Files with import/export statements
- Barrel export files (index.ts)
System Details That Might Matter
- Terminal: macOS Terminal (zsh)
- Text Editor: VS Code with TypeScript extensions
- Node Version: [your version]
- pnpm Version: [your version]
- System Locale: en_US.UTF-8
Suggested Reproduction Approach
Try creating a similar monorepo structure and:
- Run extended CLI session (30+ minutes)
- Create 5-10 TypeScript files in sequence
- Focus on Firebase/authentication related files
- Check file integrity after each batch of operations
- The corruption might be related to memory management during extended sessions or specific character encoding handling in complex TypeScript projects.
Exact Project Structure
*****/ ├── pnpm-workspace.yaml ├── turbo.json ├── package.json └── packages/ ├── services/ │ ├── package.json │ └── src/ │ └── firebase/ │ ├── auth.ts │ ├── auth-implementations.ts │ ├── validation.ts │ ├── mfa.ts ← CORRUPTED │ ├── monitoring.ts ← CORRUPTED │ └── index.ts ← SEVERELY CORRUPTED ├── types/ │ └── src/ │ ├── auth.ts │ ├── tauri.ts │ └── index.ts └── config/ └── src/ ├── firebaseConfig.ts ← PREVIOUSLY CORRUPTED └── index.ts
The following below was produced by my Github Copilot agent:
Critical File Content Pattern The corruption specifically affected files with this pattern:
JSDoc headers with multi-line comments Multiple export statements Import statements from monorepo packages (@pomona/types, @pomona/config) TypeScript interfaces and type definitions Most Severe Example: index.ts This file became completely unreadable in VS Code with the exact error:
"The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding"
Expected content was simple barrel exports:
But file became ~15KB instead of ~100 bytes due to invisible corruption.
Monorepo Configuration That Might Matter pnpm-workspace.yaml:
TypeScript Project References across 6+ packages with complex dependency graph.
Session Characteristics Duration: 2+ hours of continuous CLI usage File Operations: 15+ TypeScript files created/modified Pattern: Corruption appeared in batch - multiple files corrupted simultaneously Trigger Point: Seemed to happen after requesting "barrel export" index.ts file Hypothesis The corruption might be triggered by:
Memory accumulation during long CLI sessions Complex import resolution in monorepo context Specific character encoding handling when generating barrel exports Buffer overflow when processing multiple interconnected TypeScript files This suggests testing with a similar monorepo structure + extended session + barrel export generation might be key to reproduction.
Just for clarification did the model switch during use
Possibly, yes. It seems to switch from 2.5 pro to 2.5 flash because of "congestion". However, in my sessions today I was only working in Pro, in a fresh terminal and these issues still continued. It seems to be so corrupted that the model could not even read it in order to create a new file with the previous file as reference.
this same problem exist on the Gemini Web GUI as well. so annoying...
Hello! As part of our effort to keep our backlog manageable and focus on the most active issues, we are tidying up older reports.
It looks like this issue hasn't been active for a while, so we are closing it for now. However, if you are still experiencing this bug on the latest stable build, please feel free to comment on this issue or create a new one with updated details.
Thank you for your contribution!