GEMINI.md) are a powerful feature for providing instructional context to the Gemini model. Instead of repeating instructions in every prompt, you can define them once in a context file.
What are GEMINI.md Files?
GEMINI.md files are Markdown documents that contain:- Project-specific instructions
- Coding style guides
- Architecture documentation
- Component-specific guidelines
- Development conventions
- Any relevant background information
Context Hierarchy
The CLI uses a hierarchical system to source context files, loading them in the following order:Global Context
Location:
~/.gemini/GEMINI.mdScope: Provides default instructions for all your projects across your entire system.Use for: Personal coding preferences, general development practices, favorite librariesEnvironment & Workspace Context
Location: Searched in configured workspace directories and their parent directoriesScope: Provides context relevant to the projects you are currently working on.Use for: Multi-project context, shared team conventions
The CLI footer displays the number of loaded context files, giving you a quick visual indicator of the active context.
Example GEMINI.md File
Here’s a comprehensive example for a TypeScript project:Using the /memory Command
Interact with loaded context files using the/memory command:
/memory show
/memory show
Displays the full, concatenated content of the current hierarchical memory.Use this to inspect the exact instructional context being provided to the model.
/memory refresh
/memory refresh
Forces a re-scan and reload of all GEMINI.md files from all configured locations.Use this after modifying context files to immediately apply changes.
/memory add <text>
/memory add <text>
Appends your text to your global
~/.gemini/GEMINI.md file.Use this to add persistent memories on the fly.Modularizing Context with Imports
Break down large GEMINI.md files into smaller, manageable components using the@file.md syntax:
- Supports both relative and absolute paths
- Can reference files in parent directories
- Helps organize large context files
- Makes context reusable across projects
Memory Import Processor
Learn more about the import syntax and advanced features
Customizing the Context File Name
WhileGEMINI.md is the default filename, you can configure alternative names in your settings.json:
Single custom name:
Best Practices
Be Specific
Provide clear, actionable instructions rather than vague guidance. “Use 2 spaces for indentation” is better than “follow good coding practices.”
Use Hierarchy
Place general instructions in global GEMINI.md, project conventions in the root, and component-specific rules in subdirectories.
Include Examples
Show examples of preferred code patterns, naming conventions, and API usage. The model learns better from examples.
Keep It Current
Update context files as your project evolves. Use
/memory refresh to reload after changes.Test Coverage
Include testing requirements and patterns so the model knows to write tests for new features.
Document Architecture
Explain your project structure, key components, and how they interact. This helps the model make better suggestions.
Advanced Usage Patterns
Component-Specific Instructions
Place GEMINI.md files in subdirectories to provide context for specific components:Team Conventions
Share context files across your team by committing them to version control:Multi-Language Projects
Provide language-specific context in different sections:Configuration Settings
Control context file behavior with these settings:The name(s) of context files to load
Maximum number of directories to search for memory files
Controls how
/memory refresh loads GEMINI.md files. When true, include directories are scanned; when false, only the current directory is used.Additional directories to include in the workspace context
Troubleshooting
Context files not loading
Context files not loading
- Check the file name matches your
context.fileNamesetting - Verify file locations are within searched paths
- Use
/memory showto see what’s currently loaded - Run
/memory refreshto force a re-scan - Check the footer indicator for loaded context count
Too much context loaded
Too much context loaded
- Reduce
context.discoveryMaxDirssetting - Use
.geminiignoreto exclude directories - Be more specific about which directories to scan
- Remove or rename unused GEMINI.md files
Context changes not reflected
Context changes not reflected
Always run
/memory refresh after modifying GEMINI.md files to reload the context.Related Resources
Settings Reference
Configure context file behavior
.geminiignore
Exclude files from context
Custom Commands
Automate common prompts
Memory Tool
Save persistent memories