Authoring Agent System Prompts
Introduction and Context
In our last lesson, we learned how to use Codex to explore a new project and understand its structure. However, every time you start a new chat, the agent "forgets" your specific preferences unless you tell it again. To fix this, we use a file called AGENTS.md.
Think of AGENTS.md as the permanent instruction manual for your repository. It acts as a System Prompt. Every time you launch Codex, it reads this file from your repository root to understand your rules, coding style, and safety boundaries. By keeping these instructions in a file, you ensure that Codex always behaves consistently, no matter who is using it or when the session starts.
As a reminder from our previous work, you can always enter the interactive mode by typing this command in your terminal:
Once inside this interactive view, you are ready to start configuring your agent.
Initializing the Rulebook with /init
You don't have to create the AGENTS.md file by hand from scratch. Codex has a built-in shortcut to help you get started.
Inside the Codex interactive session, you can use the /init command.
When you run this, Codex automatically generates a basic AGENTS.md file in the root directory of your project. In the CodeSignal IDE, you will see this new file appear in your file explorer on the left.
The default file provides a skeleton structure. It often includes placeholders for the project's purpose and basic instructions. This saves you time and ensures the file is named and placed correctly so that Codex can find it later.
Defining Style and Formatting
The first major section you should add to your AGENTS.md is Coding Style. This ensures the AI doesn't write code that looks "out of place" compared to the rest of your project.
Let's start building our file content. We will begin with a simple header and some style rules:
# Agent Instructions: This is the main title of your rulebook.## Coding Style: This sub-header tellsCodexexactly where to look for formatting rules.- The bullet points give clear, simple directions. By specifying
2 spacesanddouble quotes, you prevent the agent from using its own default settings, which might be different from your project's existing code.
Now, let's add one more detail to make the code even cleaner:
- Adding the "trailing comma" rule helps keep your
git diffsclean. When the agent knows these small details, you won't have to manually fix the formatting after the AI finishes its work.
