GC-301a · Module 1

Conditional Includes & Dynamic Configuration

3 min read

Static GEMINI.md files cover 80% of configuration needs. The remaining 20% requires dynamic behavior — instructions that activate based on branch, environment, or task context. Conditional includes let you maintain multiple instruction sets and activate the right one at runtime. The pattern is straightforward: keep a base GEMINI.md with universal rules and use /memory add or environment-aware shell commands in custom commands to layer context-specific instructions on top.

Branch-aware configuration is the most common conditional pattern. Your main branch GEMINI.md might say "all changes require tests." A feature/experimental branch might relax that to "tests preferred but not required for spike work." The mechanism is manual — you maintain branch-specific GEMINI.md variants and switch between them, or you use custom commands that detect the current branch and inject appropriate rules via shell execution (!{git branch --show-current}).

[command]
name = "context-load"
description = "Load branch-aware configuration context"
prompt = """
Current branch: !{git branch --show-current}
Repository: !{basename $(git rev-parse --toplevel)}
Changed files: !{git diff --name-only HEAD~3 2>/dev/null || echo "fresh branch"}

Apply the following context-aware rules:
- If on a release/* branch: strict mode — no TODO comments, all functions documented
- If on a feature/* branch: standard mode — TODOs allowed, documentation preferred
- If on main: review mode — suggest changes only, do not modify files directly

Acknowledge which mode is active and proceed.
"""

Do This

  • Build branch-aware custom commands that inject context-specific rules at session start
  • Use shell execution (!{...}) in commands to detect environment and adapt behavior
  • Keep a single base GEMINI.md with universal rules and layer conditionals on top

Avoid This

  • Maintain multiple GEMINI.md files on different branches — they drift and conflict at merge time
  • Hardcode environment-specific rules in the base GEMINI.md — they apply everywhere
  • Skip conditional patterns because they require extra setup — the payoff is immediate for multi-environment teams