Docs

Using Alter Ego in coding agents

Claude Code, ChatGPT Codex and the Work mode of ChatGPT can all use your memory. One short line at the start of a chat makes sure the model uses it.

How it works

Alter Ego is a connector, so in these tools the model itself decides when to call it. In claude.ai and in the regular ChatGPT chat, loading your memory with start and adding a journal line with log happen by themselves. In coding agents and in Work mode the model is focused on the task at hand. For a short question or a quick code change it may go straight to the answer and leave out start and log.

Name Alter Ego at the beginning of the chat and say what you expect. That gives the model a clear instruction to load your memory and keep your journal. If it still skips a step, a short reminder in the chat is enough.

The opening line

Begin the chat with one short line that mentions Alter Ego and says what you expect. You can copy this one.

Use Alter Ego for this chat: start, and log after every answer.

Add your task straight after it, in the same message. To work on a client or project, name it: Use Alter Ego for this chat, open the context Acme, and log after every answer.

Per tool

ChatGPT Codex

Type @ and pick the Alter Ego chip in the message box. The chip tells Codex that this chat uses the connector. Then write your opening line and your task.

ChatGPT Work mode

Mention Alter Ego with the @Alter Ego chip in your first message, followed by the opening line.

Claude Code

Add the connector once with your Alter Ego connector URL, then start a session with the opening line. Claude Code lists connected servers with /mcp, so you can check that Alter Ego is available. The docs cover adding any remote MCP server.

Automatic journaling with hooks (optional)

Instead of relying on the model to call log, Claude Code and Codex can save every question and answer to your journal themselves. This uses MCP tool hooks on your own device. It is off until you run the command below yourself. Each hook calls record_turn once per message. Before a line is stored, secrets such as API keys, tokens and passwords are masked and long lines are cut at 400 characters, so a pasted key does not end up in your storage. Lines go to the journal of the context the chat opened with open_context, or to the general journal.

Install

Run one command in your own terminal. It adds the Alter Ego hooks to your Claude Code and Codex configuration (the tools you have installed), leaves everything else as it is, and can be run again safely. Nothing is installed besides the hook entries. You can read the script first: install-hooks.sh and install-hooks.ps1.

macOS and Linux (needs python3)

curl -fsSL https://alterego.cafeboon.com/install-hooks.sh | sh

Windows (PowerShell)

irm https://alterego.cafeboon.com/install-hooks.ps1 | iex

Restart Claude Code afterwards. For Codex, register the connector as alter_ego (codex mcp add alter_ego --url https://alterego.cafeboon.com/mcp, then codex mcp login alter_ego) and trust the hooks in Codex. The Claude Code hooks expect the connector to be called claude.ai Alter Ego in /mcp. If yours has another name, add --server "NAME" (shell: sh -s -- --server "NAME") or -Server NAME (PowerShell).

Remove

Add --uninstall to the shell command (curl -fsSL https://alterego.cafeboon.com/install-hooks.sh | sh -s -- --uninstall), or on Windows run & ([scriptblock]::Create((irm https://alterego.cafeboon.com/install-hooks.ps1))) -Uninstall. Only the Alter Ego hook entries are removed. --claude or --codex (-Claude, -Codex) limits it to one tool.

By hand: Claude Code

Prefer to edit the file yourself? Add this to the hooks section of your Claude Code settings.json, next to any hooks you already have. The last hook records the result of each subagent.

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "mcp_tool",
            "server": "claude.ai Alter Ego",
            "tool": "record_turn",
            "input": {
              "turn_id": "claude-${session_id}",
              "role": "user",
              "message": "${prompt}"
            },
            "timeout": 30,
            "onFailure": "continue"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "mcp_tool",
            "server": "claude.ai Alter Ego",
            "tool": "record_turn",
            "input": {
              "turn_id": "claude-${session_id}",
              "role": "assistant",
              "message": "${last_assistant_message}"
            },
            "timeout": 30,
            "onFailure": "continue"
          }
        ]
      }
    ],
    "SubagentStop": [
      {
        "matcher": ".",
        "hooks": [
          {
            "type": "mcp_tool",
            "server": "claude.ai Alter Ego",
            "tool": "record_turn",
            "input": {
              "turn_id": "claude-${session_id}-subagent",
              "role": "assistant",
              "message": "${last_assistant_message}"
            },
            "timeout": 30,
            "onFailure": "continue"
          }
        ]
      }
    ]
  }
}

The same hook also loads Alter Ego into the chat. On your first message in a chat, the answer of record_turn is added to what the model sees (Claude Code adds the output of a UserPromptSubmit hook to the context): your rules, profile, contexts and playbooks when they are short, otherwise an instruction to call start. On every later message it adds one line asking the model to finish with log. So the model no longer has to remember either, also in a chat that was already running when you installed the hooks. There is nothing more to install, and Claude.ai, ChatGPT and Gemini, which have no hooks, keep using the instructions of the connector.

Lines are labelled Claude Code or Codex. A prompt can be missed when a session has only just started and the connector is not connected yet.

Session files (privacy)

With the hooks on, Alter Ego also keeps every chat as a file in your own storage, next to the journal of its context: sessions/YYYY-MM-DD-<chat id>.md (in the general folder when the chat has no context). It holds the full text of each question and answer, with the results of subagents, not only the short journal line. Before saving, secrets such as API keys, tokens and passwords are masked, text the coding agent injects is removed, and each message is cut at 20,000 characters. A session file stops growing at 1.5 MB. The files live only in your storage, Alter Ego keeps no copy. A question is saved together with its answer, so a chat costs one write per answer. The hook only carries the last message of a turn, so tool output and files the agent read are not included. This happens only when you installed the hooks. To stop it, remove them with the uninstall command above, and delete the files you do not want to keep.

Per chat and optional

In coding agents you do not need to put this in account settings, custom instructions or project files (in chat apps an optional standing instruction does the same job). The opening line works per chat, so you choose for each conversation whether your memory is part of it. Your rules and profile still load from Alter Ego itself once the chat starts.

Quick questions without the line are fine too. Use it whenever a chat should read your memory and write to your journal.

More

  • Get started for adding the connector in Claude, ChatGPT and Gemini.
  • Tools for what start, open_context and log do.
  • Troubleshooting if the assistant does not use Alter Ego.
  • Teach it once for saving rules, contexts and playbooks.