The Memory Import Processor is a feature that allows you to modularize your GEMINI.md files by importing content from other markdown files using the @file.md syntax.
This feature enables you to break down large GEMINI.md files into smaller, more manageable components that can be reused across different contexts. The import processor supports both relative and absolute paths, with built-in safety features to prevent circular imports and ensure file access security.
This feature only supports .md (markdown) files. Attempting to import files with other extensions (like .txt, .json, etc.) will result in a warning and the import will fail.
Use the @ symbol followed by the path to the markdown file you want to import:
# Main GEMINI.md file
This is the main content.
@./components/instructions.md
More content here.
@./shared/configuration.md@./file.md- Import from the same directory@../file.md- Import from parent directory@./components/file.md- Import from subdirectory
@/absolute/path/to/file.md- Import using absolute path
# My GEMINI.md
Welcome to my project!
@./getting-started.md
## Features
@./features/overview.mdThe imported files can themselves contain imports, creating a nested structure:
# main.md
@./header.md
@./content.md
@./footer.md# header.md
# Project Header
@./shared/title.mdThe processor automatically detects and prevents circular imports:
# file-a.md
@./file-b.md
# file-b.md
@./file-a.md <!-- This will be detected and prevented -->The validateImportPath function ensures that imports are only allowed from specified directories, preventing access to sensitive files outside the allowed scope.
To prevent infinite recursion, there's a configurable maximum import depth (default: 10 levels).
If you try to import a non-markdown file, you'll see a warning:
@./instructions.txt <!-- This will show a warning and fail -->Console output:
[WARN] [ImportProcessor] Import processor only supports .md files. Attempting to import non-md file: ./instructions.txt. This will fail.
If a referenced file doesn't exist, the import will fail gracefully with an error comment in the output.
Permission issues or other file system errors are handled gracefully with appropriate error messages.
Processes import statements in GEMINI.md content.
Parameters:
content(string): The content to process for importsbasePath(string): The directory path where the current file is locateddebugMode(boolean, optional): Whether to enable debug logging (default: false)importState(ImportState, optional): State tracking for circular import prevention
Returns: Promise - Processed content with imports resolved
Validates import paths to ensure they are safe and within allowed directories.
Parameters:
importPath(string): The import path to validatebasePath(string): The base directory for resolving relative pathsallowedDirectories(string[]): Array of allowed directory paths
Returns: boolean - Whether the import path is valid
- Use descriptive file names for imported components
- Keep imports shallow - avoid deeply nested import chains
- Document your structure - maintain a clear hierarchy of imported files
- Test your imports - ensure all referenced files exist and are accessible
- Use relative paths when possible for better portability
- Import not working: Check that the file exists and has a
.mdextension - Circular import warnings: Review your import structure for circular references
- Permission errors: Ensure the files are readable and within allowed directories
- Path resolution issues: Use absolute paths if relative paths aren't resolving correctly
Enable debug mode to see detailed logging of the import process:
const result = await processImports(content, basePath, true);