# Codex
> What a Codex session materialises, the trust Codex needs before it runs the guard, and how a session starts there.
Source: https://ivar.run/docs/providers/codex

import { File, Files, Folder } from 'fumadocs-ui/components/files';

Setup is harness-agnostic — see the [quickstart](/docs/quickstart) for creating
a hall and opening your first session. This page covers what is specific to
Codex once you're there.

For the end-to-end flow with this harness across repos, see [Use Codex with multiple repositories](/docs/with/codex).

## What `ivar sync` writes

A Codex hall carries its config at the hall root, and its skills under
`.agents/skills`:

<Files>
  <Folder name=".codex" defaultOpen>
    <File name="config.toml" />
    <File name="hooks.json" />
  </Folder>
  <Folder name=".agents" defaultOpen>
    <Folder name="skills" defaultOpen>
      <Folder name="ivar-explore">
        <File name="SKILL.md" />
      </Folder>
      <Folder name="ivar-plan">
        <File name="SKILL.md" />
      </Folder>
    </Folder>
  </Folder>
  <File name="AGENTS.md" />
</Files>

- `.codex/config.toml` is Codex's project config — model, sandbox — and `ivar`
  owns only the `[mcp_servers.<hall>-<name>]` tables it marks with a
  `# managed by ivar (hall: <hall>)` comment. Your own keys, comments and
  servers survive every sync. See [MCP servers](/docs/reference/mcp).
- `.codex/hooks.json` carries the hooks. `ivar` owns the handlers whose command
  it wrote and leaves yours alone.
- `.agents/skills/` carries every skill from both roots — the hall's committed
  skills and your personal ones — materialised under its bare id. It is
  gitignored because each child is a derived symlink back into `.ivar/`. It is
  not `.codex/skills`, which is Codex's own system-skill cache.
- `AGENTS.md` is the provider-native instructions file Codex reads at startup.

Codex has no project-level slash commands: it reads custom prompts only from
`$CODEX_HOME/prompts`, a directory every hall on the machine shares. `ivar`
writes no `/ivar-*` commands for Codex, so its workflows reach it as skills.

## Start a session

```sh
ivar session start --provider codex
```

This launches `codex` in the session's view directory. To continue the last
Codex conversation, `ivar session start --resume` runs `codex resume --last`.

## Trust Codex before the first session

Codex loads a project's `.codex/` only when it trusts the project, and it
starts without the guard and says nothing when it does not. So `ivar session
start` checks first and refuses to launch when:

- Codex does not trust the hall root. Run `codex` in the hall once and trust the
  folder when it asks.
- The guard hook is missing from `.codex/hooks.json`. Run `ivar sync`.
- Codex has not trusted the guard hook as it is now. Review and trust it in
  Codex. A hook's trust lapses when `ivar` changes the guard hook, so repeat
  this after an `ivar` upgrade that rewrites it.
- A `.codex/config.toml` or `.codex/hooks.json` sits in a directory between the
  session and the hall root. Codex would load it over the hall's own config,
  outside the guard.

`IVAR_CODEX_BYPASS_HOOK_TRUST=1` makes `ivar session start` pass
`--dangerously-bypass-hook-trust` to Codex. That skips Codex's hook review for
every hook, yours and any that arrive with a cloned hall repo, so it is
opt-in. It does not skip the project trust.

## The guard

The read-only guard for repos you haven't promoted is a `PreToolUse` hook in
`.codex/hooks.json` that runs `ivar guard --provider codex` before each tool
call. A denial is a JSON verdict with `permissionDecision: "deny"` and a
reason, which Codex shows the model as a blocked call. Codex reads
`.codex/config.toml` and `hooks.json` from every directory between its working
directory and the project root, so the guard also denies writes to those names
anywhere but a promoted worktree, and the session's own `.codex/` is read-only.
See [Guards](/docs/guide/guards).

## Memory hooks

`ivar sync` also writes the memory hooks into `.codex/hooks.json`:
`ivar memory brief --provider codex` on `SessionStart`, and, while capture is
on, `ivar memory capture --provider codex` on `SessionStart`,
`UserPromptSubmit`, `PostToolUse` and `SessionEnd`.

When `memory.capture` is `false` in `ivar.json`, `ivar sync` writes no
capture hook; while capture is on, `ivar doctor` reports a missing one as
`provider.capture_hook_missing`. See [Hall memory](/docs/guide/memory).

## Add it to an existing hall

The [quickstart](/docs/quickstart) covers `ivar init`. If
the hall already exists with a different provider, add Codex alongside it:

```text
  > Add Codex to this hall alongside the current provider.
  ● Bash(ivar provider add codex)
  ● Codex is registered, with its config and skills materialised.
```

**Run it by hand:**

```sh
ivar provider add codex
```



## Where `ivar-explore` comes from

It is a skill materialised into `.agents/skills/ivar-explore/`, so Codex loads
it from your request; there is no slash command to type.

```text
  > I want to understand how billing works before we change it.
  ● Bash(ivar session start)
  ● I'm in a discovery session: every repo is mounted read-only on its default branch.
```
