Auto-Prompt Codex or Claude for Each Session

Looking to auto-prompt your codex or claude for each session to load instructions for the given codebase? You can wrap the codex command with a small shell script.

Minimal wrapper script

#!/usr/bin/env bash

AGENTS="/path/to/your/project/AGENTS.md"
REAL_CODEX="/path/to/the/real/codex"

USER_PROMPT="$*"

FINAL_PROMPT="${USER_PROMPT}

Apply the instructions in ${AGENTS} for this codebase."

exec "$REAL_CODEX" "$FINAL_PROMPT"

Override your default codex command

To make this your default CLI command, save the wrapper as ~/bin/codex, make it executable, and ensure ~/bin comes before the real Codex binary in your PATH.

mkdir -p ~/bin
nano ~/bin/codex
chmod +x ~/bin/codex

# Put this in ~/.bashrc or ~/.zshrc
export PATH="$HOME/bin:$PATH"

Before you do that, run which codex and copy that result into REAL_CODEX inside the script, otherwise the wrapper can call itself recursively.

But now we can’t skip that prompt, and also we can’t resume, so let’s expand our shell script to include those:

Expanded wrapper script

#!/usr/bin/env bash

AGENTS="/path/to/your/project/AGENTS.md"
REAL_CODEX="/path/to/the/real/codex"

if [ "$1" = "resume" ]; then
  exec "$REAL_CODEX" "$@"
fi

if [ "$1" = "skip" ]; then
  shift
  exec "$REAL_CODEX" "$@"
fi

USER_PROMPT="$*"

FINAL_PROMPT="${USER_PROMPT}

Apply the instructions in ${AGENTS} for this codebase."

exec "$REAL_CODEX" "$FINAL_PROMPT"

Usage

  • code adds your codebase instructions, but no “title” for the session
  • codex fix this bug adds your codebase instructions, and adds “fix this bug” as the session title
  • codex resume works unchanged
  • codex skip fix this bug runs without the injected prompt

Leave a Reply

Your email address will not be published. Required fields are marked *