Skip to content

feat(core): add AGENTS.md to default context filenames#24913

Open
harshpujari wants to merge 5 commits intogoogle-gemini:mainfrom
harshpujari:feat/add-agents-md-default
Open

feat(core): add AGENTS.md to default context filenames#24913
harshpujari wants to merge 5 commits intogoogle-gemini:mainfrom
harshpujari:feat/add-agents-md-default

Conversation

@harshpujari
Copy link
Copy Markdown

Summary

  • Adds AGENTS.md alongside GEMINI.md as a default context file that is automatically discovered
  • Users can override the list via context.fileName in .gemini/settings.json to exclude AGENTS.md if needed
  • Updates documentation to explain the new default behavior and override mechanism

Details

Codebases increasingly use the AGENTS.md standard for AI agent instructions. This change adds AGENTS.md to the default context filename list so it is discovered automatically without requiring manual configuration.

The existing infrastructure already supports multiple filenames — this change simply adds AGENTS.md to the default list. GEMINI.md remains the primary context file (first in the array).

Changes

  • packages/core/src/tools/memoryTool.ts — Added DEFAULT_CONTEXT_FILENAMES array constant, updated default initializer
  • packages/core/src/prompts/snippets.ts — Updated fallback references to use new array constant
  • docs/cli/gemini-md.md — Documented AGENTS.md default discovery and override mechanism
  • Test files updated with new constant and 2 new test cases

Test plan

  • TypeScript compilation passes (core package)
  • All 21 memoryTool tests pass (including 2 new tests)
  • All 42 memoryDiscovery tests pass
  • All 14 promptProvider tests pass
  • Verified user can override defaults to exclude AGENTS.md via context.fileName config

Fixes #12345

🤖 Generated with Claude Code

@harshpujari harshpujari requested review from a team as code owners April 8, 2026 10:17
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Gemini CLI's ability to automatically discover AI agent instructions by integrating the AGENTS.md standard into its default context file discovery mechanism. This change streamlines the process for developers using AGENTS.md by eliminating the need for manual configuration, while also providing clear options for customization through user settings.

Highlights

  • Default Context File Discovery: The AGENTS.md file has been added to the list of default context filenames, allowing it to be automatically discovered and loaded alongside GEMINI.md for AI agent instructions.
  • Customization and Override: Users can now customize the list of context filenames by setting the context.fileName property in their .gemini/settings.json file, providing flexibility to include or exclude AGENTS.md as needed.
  • Documentation Update: The CLI documentation has been updated to clearly explain the new default discovery behavior for AGENTS.md and provide instructions on how to override these settings.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Gemini CLI to discover both GEMINI.md and AGENTS.md files as context sources by default. The changes include documentation updates, modifications to the core configuration and prompt rendering logic, and expanded test coverage. Key feedback highlights a potential concurrency issue due to the use of module-level global state for filename configuration and a bug where an empty array of context filenames could result in 'undefined' being rendered in the system prompt.

let currentGeminiMdFilename: string | string[] = DEFAULT_CONTEXT_FILENAME;
// This variable will hold the currently configured filenames for context files.
// It defaults to DEFAULT_CONTEXT_FILENAMES but can be overridden by setGeminiMdFilename.
let currentGeminiMdFilename: string | string[] = DEFAULT_CONTEXT_FILENAMES;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of a module-level global variable currentGeminiMdFilename for state violates the general rule against global state in concurrent environments. This can lead to race conditions in the a2a-server or when using the SDK, where multiple sessions might attempt to configure different context filenames simultaneously. Consider moving this state into a session-scoped object like the Config instance and passing it to the tools and prompt renderers.

References
  1. Avoid module-level global variables for state like caches to prevent race conditions and memory issues in concurrent environments. Instead, use session-scoped or instance-scoped state and leverage standard cache implementations like LRUCache.

export function renderCoreMandates(options?: CoreMandatesOptions): string {
if (!options) return '';
const filenames = options.contextFilenames ?? [DEFAULT_CONTEXT_FILENAME];
const filenames = options.contextFilenames ?? DEFAULT_CONTEXT_FILENAMES;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If options.contextFilenames is an empty array, the current logic will result in filenames[0] being undefined on line 186, which will be rendered as the string 'undefined' in the system prompt. The fallback should ensure a non-empty array is used.

  const filenames = options.contextFilenames?.length
    ? options.contextFilenames
    : DEFAULT_CONTEXT_FILENAMES;
References
  1. To avoid extra newlines or malformed content from empty variables in template literals, prefer ensuring the variable is never empty over adding conditional rendering logic within the template.

Prevents 'undefined' from being rendered in the system prompt when
contextFilenames is an empty array, since [] is truthy and bypasses
the ?? fallback.
@harshpujari
Copy link
Copy Markdown
Author

The module-level currentGeminiMdFilename state is pre-existing — this PR doesn't introduce it. Refactoring it into session-scoped config (e.g., the Config instance) would be a valuable follow-up but is beyond the scope of this change. Happy to open a separate issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add AGENTS.md to the context filename list by default

1 participant