codex

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 27 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package codex is the OpenAI Codex module (CLI, IDE extension and desktop app share one store). Sessions ("threads") are append-only JSON-lines rollouts under $CODEX_HOME/sessions/YYYY/MM/DD/rollout-<local time>-<id>.jsonl. Codex also keeps SQLite indexes; hopsesh never touches them: Codex finds a copied-in rollout by id and indexes it itself. A rollout Codex has compressed (<name>.jsonl.zst) reads as <name>.jsonl: the machine's filesystem shows it so (see host.compressedFS).

Index

Constants

View Source
const NewCloudEnvs = "" /* 197-byte string literal not displayed */

NewCloudEnvs says why codex lists no cloud environment where the user made one.

Variables

View Source
var ErrBusy = errors.New("the Codex session is working right now; let it finish (or stop it with Esc), then try again")

ErrBusy means Codex is in the middle of a turn in that thread.

View Source
var ErrInApp = errors.New("hopsesh never closes the app, which holds every thread")

ErrInApp means the Codex app holds the thread: its one shared app-server runs every app thread, so ending that process would close them all.

View Source
var ErrSharedServer = errors.New("the session is held by a shared Codex app-server that other sessions use too; quit it in the Codex window that has it open")

ErrSharedServer means a shared Codex app-server (a daemon serving several clients) holds the thread.

View Source
var ErrStillRunning = errors.New("the Codex session did not exit in time; quit it yourself (Ctrl+C twice, or /quit), then try again")

ErrStillRunning means a stopped thread's process did not exit in time.

Functions

This section is empty.

Types

type Module

type Module struct{}

Module is the Codex module.

func New

func New() *Module

New returns the module.

func (*Module) Account

func (m *Module) Account(ctx context.Context, h agent.Host, in agent.Install) (agent.Account, error)

Account identifies the Codex login on a machine through Codex itself (account/read). On this machine it also takes the account and user ids from auth.json's public identity (never its tokens), the same ids Codex records as a session's creator; elsewhere, or when Codex keeps its login in the keyring, ChatGPT logins are keyed by a hash of the email. An API key or another provider has no identity to compare.

func (*Module) AfterInstall

func (m *Module) AfterInstall(ctx context.Context, h agent.Host, in agent.Install, key agent.SessionKey, p agent.Placement) error

AfterInstall makes Codex's own session lists show a session hopsesh installed, under its name. Codex lists sessions from an index it fills once, so a rollout added later stays out of `codex resume` and the app until Codex reads it by id; hopsesh asks `codex app-server` to (thread/read), and to record the name (thread/name/set). Codex not installed here is not an error: it finds the session by id when resumed.

func (*Module) Bundle

func (m *Module) Bundle(_ context.Context, h agent.Host, in agent.Install, s agent.Summary) (agent.Bundle, error)

Bundle is the rollout, plus the rollout a forked thread's history starts in.

func (*Module) CanImport

func (m *Module) CanImport(from agent.ID) bool

CanImport reports that Codex's importer reads Claude Code sessions.

func (*Module) ChangeDir added in v0.6.2

func (m *Module) ChangeDir(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, p agent.DirPlan) error

ChangeDir asks a one-shot `codex app-server` to resume the thread in the new folder, then reads the rollout back: Codex must have recorded the folder.

func (*Module) CheckApp added in v0.4.0

func (*Module) CheckApp(in agent.Install, key agent.SessionKey, o agent.ResumeOptions) error

func (*Module) CloudURL added in v0.4.0

func (m *Module) CloudURL(_ string, id agent.SessionID) string

CloudURL is the task's page.

func (*Module) ContextCapacity added in v0.4.0

func (m *Module) ContextCapacity(ctx context.Context, h agent.Host, in agent.Install, s *agent.Summary) (ir.Capacity, error)

ContextCapacity reads only configuration and transcript data, never auth files. Unknown models use a small fallback; explicit configuration can only lower the cap.

func (*Module) Detect

func (m *Module) Detect(_ context.Context, h agent.Host) (agent.Install, error)

Detect resolves CODEX_HOME and the codex binary: the CLI, else the Codex app's bundled runtime.

func (*Module) FetchCloud added in v0.4.0

FetchCloud brings a task back as what the codex CLI shows of it: `codex cloud status` (its title, state, environment and diff summary) and, once it is done, `codex cloud diff` (the first attempt's unified diff). The core applies the diff in its worktree and commits it; the title and summary come as a short conversation (FidCode). The task's messages and steps stay in the cloud: the CLI does not print them. A task still running brings no diff.

func (*Module) HookTrust added in v0.4.2

func (m *Module) HookTrust(ctx context.Context, h agent.Host, in agent.Install, commands []string) agent.HookTrust

HookTrust asks Codex (app-server hooks/list) whether it trusts the hopsesh hooks. Codex records trust against a hash of each hook definition and skips untrusted or changed hooks without telling the session, so an installed hook can still deliver nothing. Trusting stays in Codex: /hooks in the CLI, or the review prompt in the app.

func (*Module) Import

func (m *Module) Import(ctx context.Context, h agent.Host, in agent.Install, from agent.ID, path, cwd, title string) (agent.SessionID, error)

Import has Codex's own importer convert a Claude Code session file (externalAgentConfig/import) into a new thread.

func (*Module) InSession added in v0.6.2

func (m *Module) InSession(agent.Install, string) string

InSession is "": Codex's /cd starts a new thread (a fork), so the session itself can only change folder while it is closed.

func (*Module) Integration

func (m *Module) Integration(h agent.Host, in agent.Install) agent.Integration

Integration says Codex reads user skills from ~/.agents/skills, and approval rules from any .rules file under $CODEX_HOME/rules. hopsesh owns rules/hopsesh.rules outright (Codex rewrites default.rules itself).

func (*Module) List

func (m *Module) List(ctx context.Context, h agent.Host, in agent.Install) (agent.Listing, error)

List walks sessions/YYYY/MM/DD, newest first. Sub-agent threads are left out, as Codex's own pickers do.

func (*Module) ListCloud added in v0.4.0

ListCloud lists Codex cloud tasks with `codex cloud list --json` (newest first, 20 a page, on with --cursor up to q.Limit), only q.Env's with --env. Code reviews are left out (they bring nothing back). A recorded task the pages did not reach is asked for with `codex cloud status`. The tasks carry their environment, which is how hopsesh suggests one for a hand-off.

func (*Module) Live

Live probes the lock Codex holds on thread-writer-locks/<id>.lock while a thread is open (the file stays after Codex exits; only the lock means open). The processes holding an open thread's lock are its Procs, the first of them its PID; a machine that cannot name lock holders leaves them out.

func (*Module) LocalIdentity added in v0.5.0

func (m *Module) LocalIdentity(root string, _ bool) (agent.OwnerRun, bool)

LocalIdentity reads the account and user ids from the root's auth.json (only those).

func (*Module) MovementHooks added in v0.4.0

func (m *Module) MovementHooks(h agent.Host, in agent.Install, bin string, args ...string) agent.HookIntegration

MovementHooks uses the current user-layer hooks.json contract. Contract checked 2026-10-06: https://developers.openai.com/codex/hooks https://developers.openai.com/codex/changelog#october-2026 Windows runner/source checked at rust-v0.160.0: https://github.com/openai/codex/blob/rust-v0.160.0/codex-rs/hooks/src/engine/command_runner.rs It uses the selected shell or cmd.exe fallback; the encoded PowerShell launch works under either without exposing literals to that outer shell. Vendor hook trust and features.hooks remain entirely under vendor/user control.

func (*Module) NativeParentGone added in v0.4.2

func (m *Module) NativeParentGone(ctx context.Context, h agent.Host, in agent.Install, child agent.Summary) (bool, error)

NativeParentGone reports that a legacy fork's declared parent has no rollout left in sessions/ or archived_sessions/, as after Codex's thread/delete. A legacy fork copies the parent's records into its own rollout, so it is a complete conversation; a paginated fork (history_base) reads its parent's rollout and is never treated as orphaned.

func (m *Module) ParseCloudLink(s string) (string, agent.SessionID, bool)

ParseCloudLink reads a task's link (chatgpt.com/codex/tasks/<id>) or its task_… id.

func (*Module) PlanChangeDir added in v0.6.2

func (m *Module) PlanChangeDir(_ context.Context, h agent.Host, in agent.Install, s agent.Summary, dir string) (agent.DirPlan, error)

PlanChangeDir has Codex itself change the thread's folder, the way `codex resume <id> -C <dir>` does: Codex resumes the thread in dir (no turn, no model call) and records the folder in the rollout (thread_settings_applied) and its own index. Nothing moves: a rollout's place does not depend on its folder. Codex's own /cd is not used: it forks the thread into a new one.

func (*Module) PlanMove

func (m *Module) PlanMove(src, dst agent.Install, s agent.Summary, b agent.Bundle, p agent.Placement) (agent.MovePlan, error)

PlanMove keeps every rollout at its relative path (Codex's index finds a thread by its file name, and an existing index row keeps its path). A keep-both copy gets a new id, which appears in the file name and inside many records.

func (*Module) Preview added in v0.4.0

func (m *Module) Preview(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, n int) (agent.Preview, error)

Preview reads the end of the rollout, within a tail window of the file (never the whole of it), and the first prompt from its head.

func (*Module) Profile

func (m *Module) Profile(agent.Install) ir.Profile

Profile says Codex's own tool calls cannot be forged safely, so history arrives as text.

func (*Module) ProjectSanitized added in v0.4.0

func (m *Module) ProjectSanitized(source, target ir.Segment) ([]ir.Projection, error)

ProjectSanitized maps the sanitizer, which drops whole reasoning and compaction records, retaining every other record in order. Reader lifting preserves that order, so this mapping uses the exact drop policy, not text similarity or wall-clock ancestry guesses.

func (*Module) Read

func (m *Module) Read(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, from ir.Cursor) (ir.Segment, error)

Read lifts a rollout into IR: the user's messages (not the context Codex injects), the agent's replies, and what ran, from Codex's structured item_completed records (falling back to raw function calls in rollouts that have none).

func (*Module) RecoverWrite added in v0.4.0

func (m *Module) RecoverWrite(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)

func (*Module) Rename added in v0.4.0

func (m *Module) Rename(_ context.Context, h agent.Host, in agent.Install, s agent.Summary, title string) error

Rename names the thread in session_index.jsonl, as Codex's own rename does (a legacy title label goes with the old name).

func (*Module) Resume

Resume is `codex resume <id> -C <folder> [prompt]` (or `codex fork <id>`), run in the thread's folder.

func (*Module) Sanitize

func (m *Module) Sanitize() agent.RewritePolicy

Sanitize is the policy for a move to a machine signed in to another account: Codex's encrypted reasoning and compaction are bound to the organization that produced them, and replaying them under another one makes the session fail to resume, so those records go (the conversation itself stays; Codex compacts again when it needs to).

func (*Module) SendCloud added in v0.4.0

func (m *Module) SendCloud(ctx context.Context, h agent.Host, _ agent.Install, r agent.SendRequest) (agent.Sent, error)

SendCloud starts a Codex cloud task with the briefing as its prompt: `codex cloud exec --env <env> --branch <branch> [--attempts N] <brief>`. The branch is already pushed. With r.Code ViaStartingDiff, the diff goes with the task in CODEX_STARTING_DIFF (on a branch that is already on the remote). It prints the task's link (from source: util::task_url). GitHub only; an environment is needed (`codex cloud` makes one; the CLI cannot).

func (*Module) SessionWatchPaths added in v0.4.1

func (m *Module) SessionWatchPaths(in agent.Install, pa agent.Path) []string

SessionWatchPaths excludes logs, credentials and unrelated caches.

func (*Module) Spec

func (*Module) Spec() agent.Spec

Spec declares Codex.

func (*Module) Stop

func (m *Module) Stop(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, grace time.Duration) error

Stop quits the Codex process that has the thread open. Codex installs no handler for SIGTERM, so it is sent only between turns (Codex writes every item to the rollout as it goes, so nothing finished is lost), and only to a CLI process named codex (any case) that holds the thread's writer lock. A thread the Codex app (or another shared app-server) holds is never stopped: that process serves every thread of its clients.

func (*Module) TestCloud added in v0.4.0

func (m *Module) TestCloud(ctx context.Context, h agent.Host, in agent.Install, _ string) (agent.CloudTest, error)

TestCloud checks, read-only, that codex is signed in with ChatGPT (`codex login status`), that `codex cloud --help` still has the commands this module uses, and that Codex cloud answers a listing (`codex cloud list --limit 1 --json`). It starts no task.

func (*Module) Verify

func (m *Module) Verify(ctx context.Context, h agent.Host, mp agent.MovePlan, staged map[string]string, p agent.Placement) error

Verify checks that the staged rollout starts in the target folder, as the target thread.

func (*Module) VerifyNativeFork added in v0.4.0

func (m *Module) VerifyNativeFork(ctx context.Context, h agent.Host, in agent.Install, parent, child agent.Summary) ([]agent.NativeInheritance, error)

VerifyNativeFork uses Codex's forked_from_id and optional exclusive ordinal, then compares copied native records. Text, timestamps or a title do not imply ancestry.

func (*Module) Write

func (m *Module) Write(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)

Write emits a legacy-mode rollout (no ordinals): session_meta, then each message as a response_item with its user_message/agent_message event (Codex titles threads from those events). Paginated appends preserve contiguous native ordinals.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL