Customize instructions for Gemini in IDX with an AI rules file

You can add context and system prompt information by creating an AI rules file (.idx/airules.md). Gemini in IDX uses your rules as system instructions and context, ensuring that its responses are customized for your use case.

Use the AI rules file to share custom prompts, best practices, and even important context about your project with Gemini to achieve goals like:

  • Influencing Gemini's persona and specializing its expertise.
  • Applying project-wide standards, like coding style, conventions, and technology preferences.
  • Reducing the amount of information you need to share explicitly in code or chat by providing essential context about your project.

The rules you configure are used by Gemini in IDX in chat.

Create and test your AI rules file

To create and test your AI rules file:

  1. Create a new file at .idx/airules.md in your IDX workspace (in the same directory as your dev.nix file). You can use one of the following options:

    • From Explorer (Ctrl-Shift-E), right-click on .idx and select New file. Name the file airules.md and press Enter.
    • From the terminal, use your preferred text editor to open .idx/airules.md.
  2. Add content to the file. You may want to add information about the persona Gemini should use, coding and conversation standards, and context about the project to the file. See Example for an example AI rules file.

  3. Save the file and open Gemini in IDX.

  4. To start using your AI rules, you can do one of the following:

    • Rebuild the workspace by refreshing the page. After you rebuild, Gemini in IDX will use the rules file within chat. Changes to the AI rules file should be reflected in chat immediately.
    • If you don't want to rebuild your workspace, you can ask Gemini to load airules.md. If you make changes to the file during the current session, you may need to re-prompt Gemini to load the rules file again.
  5. Ask questions about your code. Gemini responds using the information you included in the rules file as context.

Example

The following is a basic example of a rules file that you might use for a casual game developed with Next.js:

# Persona

You are an expert developer proficient in both front- and back-end development
with a deep understanding of Node.js, Next.js, React, and Tailwind CSS. You
create clear, concise, documented, and readable TypeScript code.

You are very experienced with Google Cloud and Firebase services and how
you might integrate them effectively.

# Coding-specific guidelines

- Prefer TypeScript and its conventions.
- Ensure code is accessible (for example, alt tags in HTML).
- You are an excellent troubleshooter. When analyzing errors, consider them
  thoroughly and in context of the code they affect.
- Do not add boilerplate or placeholder code. If valid code requires more
  information from the user, ask for it before proceeding.
- After adding dependencies, run `npm i` to install them.
- Enforce browser compatibility. Do not use frameworks/code that are not
  supported by the following browsers: Chrome, Safari, Firefox.
- When creating user documentation (README files, user guides), adhere to the
  Google developer documentation style guide
  (https://developers.google.com/style).

# Overall guidelines

- Assume that the user is a junior developer.
- Always think through problems step-by-step.

# Project context

- This product is a web-based strategy game with a marine life theme.
- Intended audience: casual game players between the ages of 17 and 100.

Next steps

  • Learn how to further control context by excluding files from Gemini in IDX with aiexclude files.