Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/codex-* text eol=lf
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,29 @@ alongside everything else.

## Install

Recommended (works on Windows, macOS, and Linux):

```bash
git clone https://github.com/<you>/codex-shim
cd codex-shim
python3 -m pip install -e .
```

This installs `aiohttp` and registers `codex-shim`, `codex-app`, `codex-model`,
`codex-openrouter`, and `codex-minimax` as real entry-point scripts in your
Python install's `Scripts/` (Windows) or `bin/` (POSIX) directory. As long as
that directory is on `PATH`, the commands work from any shell — PowerShell,
cmd, Git Bash, bash, zsh.

If `pip` reports the scripts were written to a directory not on `PATH`, add it.
On Windows, that is typically `%APPDATA%\Python\Python3xx\Scripts` (user
install) or `<python>\Scripts` (system install).

POSIX-only alternative — symlink the bash wrappers directly:

```bash
git clone https://github.com/<you>/codex-shim ~/Documents/codex-shim
cd ~/Documents/codex-shim
python3 -m pip install --user aiohttp pytest # only runtime dep is aiohttp
ln -s "$PWD/bin/codex-shim" ~/.local/bin/codex-shim
ln -s "$PWD/bin/codex-app" ~/.local/bin/codex-app
ln -s "$PWD/bin/codex-shim" ~/.local/bin/codex-shim
ln -s "$PWD/bin/codex-app" ~/.local/bin/codex-app
ln -s "$PWD/bin/codex-model" ~/.local/bin/codex-model
```

Expand Down
1 change: 1 addition & 0 deletions bin/codex-minimax
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ while [ -h "$SOURCE" ]; do
done

ROOT="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
export PATH="$HOME/.local/bin:$HOME/.hermes/node/bin:$HOME/.npm-global/bin:$HOME/.npm-global:$PATH"
SETTINGS="${CODEX_SHIM_SETTINGS:-$ROOT/.codex-shim/minimax-settings.json}"
PORT="${CODEX_SHIM_PORT:-8767}"
PLACEHOLDER_KEY="REPLACE_WITH_MINIMAX_TOKEN_PLAN_KEY"
Expand Down
1 change: 1 addition & 0 deletions bin/codex-openrouter
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ while [ -h "$SOURCE" ]; do
done

ROOT="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
export PATH="$HOME/.local/bin:$HOME/.hermes/node/bin:$HOME/.npm-global/bin:$HOME/.npm-global:$PATH"
SETTINGS="${CODEX_SHIM_SETTINGS:-$ROOT/.codex-shim/openrouter-settings.json}"
PORT="${CODEX_SHIM_PORT:-8766}"
PLACEHOLDER_KEY="REPLACE_WITH_OPENROUTER_API_KEY"
Expand Down
9 changes: 8 additions & 1 deletion bin/codex-shim
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ while [ -h "$SOURCE" ]; do
done
ROOT="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
export PYTHONPATH="$ROOT${PYTHONPATH:+:$PYTHONPATH}"
exec python3 -m codex_shim.cli "$@"
PYTHON="${CODEX_SHIM_PYTHON:-}"
if [ -z "$PYTHON" ] && [ -x "$ROOT/.venv/bin/python" ]; then
PYTHON="$ROOT/.venv/bin/python"
fi
if [ -z "$PYTHON" ]; then
PYTHON="python3"
fi
exec "$PYTHON" -m codex_shim.cli "$@"
46 changes: 45 additions & 1 deletion codex_shim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,50 @@ def main(argv: list[str] | None = None) -> int:
return 2


def codex_app_entry() -> int:
return main(["app", *sys.argv[1:]])


def codex_model_entry() -> int:
args = sys.argv[1:]
if not args or args[0] == "list":
return main(["model", "list"])
return main(["model", "use", args[0]])


def codex_openrouter_entry() -> int:
args = sys.argv[1:]
if sys.platform == "win32":
return _exec_bash_shortcut("codex-openrouter", args)
if args and args[0] in {"setup", "--configure", "configure"}:
return main(["setup", "openrouter"])
return main(["openrouter", *args])


def codex_minimax_entry() -> int:
args = sys.argv[1:]
if sys.platform == "win32":
return _exec_bash_shortcut("codex-minimax", args)
if args and args[0] in {"setup", "--configure", "configure"}:
return main(["setup", "minimax"])
return main(["minimax", *args])


def _exec_bash_shortcut(name: str, args: list[str]) -> int:
script = PROJECT_ROOT / "bin" / name
os.execvp("bash", ["bash", _windows_path_to_wsl(script), *args])
return 127


def _windows_path_to_wsl(path: Path) -> str:
text = str(path.resolve())
if len(text) >= 3 and text[1:3] == ":\\":
drive = text[0].lower()
rest = text[3:].replace("\\", "/")
return f"/mnt/{drive}/{rest}"
return text.replace("\\", "/")


def list_providers() -> int:
width = max(len(name) for name in PROVIDER_SPECS)
for spec in PROVIDER_SPECS.values():
Expand Down Expand Up @@ -438,7 +482,7 @@ def start(settings_path: Path, port: int) -> int:
env["PYTHONPATH"] = str(PROJECT_ROOT) + os.pathsep + env.get("PYTHONPATH", "")
process = subprocess.Popen(cmd, cwd=str(PROJECT_ROOT), env=env, stdout=log, stderr=log, start_new_session=True)
PID_PATH.write_text(str(process.pid))
for _ in range(50):
for _ in range(300):
if _healthy(port):
print(f"Shim started on http://{DEFAULT_HOST}:{port} with pid {process.pid}.")
print(f"Log: {LOG_PATH}")
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ dependencies = [

[project.scripts]
codex-shim = "codex_shim.cli:main"
codex-app = "codex_shim.cli:codex_app_entry"
codex-model = "codex_shim.cli:codex_model_entry"
codex-openrouter = "codex_shim.cli:codex_openrouter_entry"
codex-minimax = "codex_shim.cli:codex_minimax_entry"

[tool.pytest.ini_options]
testpaths = ["tests"]
15 changes: 15 additions & 0 deletions tests/test_cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,18 @@ def test_provider_top_level_alias_runs_provider(tmp_path, monkeypatch):

assert rc == 0
assert captured == {"provider": "test-provider", "args": ["."], "port": 9998}


def test_windows_provider_entry_delegates_to_bash_shortcut(monkeypatch):
captured = {}

monkeypatch.setattr(cli.sys, "platform", "win32")
monkeypatch.setattr(cli.sys, "argv", ["codex-openrouter", "."])
monkeypatch.setattr(cli.os, "execvp", lambda file, args: captured.update(file=file, args=args))

cli.codex_openrouter_entry()

assert captured["file"] == "bash"
assert captured["args"][0] == "bash"
assert captured["args"][1].endswith("/bin/codex-openrouter")
assert captured["args"][2:] == ["."]