GEMINI.md) are a powerful way to provide project-specific instructions, coding standards, and persistent context to Gemini CLI. Instead of repeating instructions in every prompt, define them once in context files.
What Are Context Files?
Context files are Markdown files (default name:GEMINI.md) that contain instructions, preferences, and information about your project. The CLI automatically loads these files and includes their content with every prompt sent to the model.
Think of
GEMINI.md files as persistent system prompts that guide the AI’s behavior for your specific project or workspace.Why Use Context Files?
Consistency
Ensure the AI follows your coding standards and conventions every time
Efficiency
No need to repeat instructions in every prompt
Team Alignment
Share project conventions with all team members using Gemini CLI
Context Awareness
The AI understands your project structure and preferences automatically
Context Hierarchy
Gemini CLI loads context files from multiple locations in a hierarchical manner. All found files are concatenated and sent to the model with every prompt.Global Context
Location:
~/.gemini/GEMINI.mdScope: Provides default instructions for all your projectsUse for:- Personal coding preferences
- General AI behavior guidelines
- Universal tool preferences
Workspace Context
Location:
GEMINI.md files in workspace directories and their parentsScope: Project-level instructions for active workspacesUse for:- Project-specific conventions
- Technology stack preferences
- Architecture guidelines
The CLI footer displays the number of loaded context files, giving you a visual indicator of active context.
Creating Context Files
Global Context File
Create a global context file for all your projects:~/.gemini/GEMINI.md
Project Context File
Create a project-level context file at your project root:GEMINI.md
utils/ # Helper utilities index.ts # Main exports
Component-Specific Context
Create context files in subdirectories for component-specific instructions:src/components/GEMINI.md
Managing Context
Use the/memory command to interact with context files:
View Current Context
See all loaded context:GEMINI.md files currently loaded.
Refresh Context
Reload all context files:Add to Global Context
Append text to your globalGEMINI.md:
~/.gemini/GEMINI.md immediately.
Modular Context with Imports
Break largeGEMINI.md files into smaller, manageable pieces using the @file.md import syntax.
Basic Import
GEMINI.md
Import Paths
Supports both relative and absolute paths:Example Modular Structure
Memory Import Processor
Learn more about the import system and advanced features
Customizing Context File Names
WhileGEMINI.md is the default, you can configure custom filenames in your settings.json.
~/.gemini/settings.json
Best Practices
Start small and iterate
Start small and iterate
Begin with basic instructions and add more as you discover useful patterns:
- Start with critical conventions
- Add more details as you work
- Remove instructions that aren’t helpful
- Refine based on actual usage
Be specific and actionable
Be specific and actionable
✅ Good: “Use async/await instead of Promise.then() for asynchronous operations”❌ Vague: “Write good code”Specific instructions help the model make the right decisions.
Organize by topic
Organize by topic
Use clear sections and headings:
Include examples
Include examples
Examples make instructions clearer:
Version control your context
Version control your context
Commit
GEMINI.md files to your repository:- Share conventions with team
- Track changes over time
- Maintain consistency across environments
Use imports for large projects
Use imports for large projects
Break down context into focused modules:Easier to maintain and update specific sections.
Context File Examples
Backend API Project
GEMINI.md
Database
- Use migrations for schema changes
- Never commit raw SQL in application code
- Use parameterized queries to prevent SQL injection
Security
- Validate all input
- Sanitize output
- Use rate limiting on public endpoints
- Never log sensitive data (passwords, tokens)
Data Science Project
GEMINI.md
Troubleshooting
Context not loading
Context not loading
Check:
- File is named
GEMINI.md(or your configured name) - File is in a recognized location (global, workspace, or accessed directory)
- Use
/memory showto verify loaded content - Try
/memory refreshto reload
Too much context
Too much context
Symptoms: Token limits reached, slow responsesSolutions:
- Break large files into focused modules with imports
- Remove overly verbose instructions
- Use component-specific context files instead of one large file
- Focus on essential conventions only
Imports not working
Imports not working
Check:
- Import paths are correct
- Imported files exist
- Use relative (
./) or absolute (/) paths correctly - No circular imports
AI not following context
AI not following context
Possible causes:
- Instructions too vague
- Conflicting instructions in different files
- Context overridden by specific user prompts
- Make instructions more specific and actionable
- Review all loaded context with
/memory show - Reinforce important instructions in your prompt
Next Steps
How It Works
Understand how context is loaded and processed
Memory Tool
Save persistent memories during sessions
Memory Import Processor
Advanced import syntax and features
Custom Commands
Create reusable command shortcuts