Codex (Wrapper ChatGPT.nvim)
Wraps ChatGPT.nvim to redirect OpenAI calls through a local `codex` CLI binary, disabling streaming and using environment variables for configuration.
What this file does
Wraps ChatGPT.nvim to redirect OpenAI calls through a local codex CLI binary, disabling streaming and using environment variables for configuration.
When to use it
- You have a local
codexCLI and want Neovim to use it instead of direct OpenAI API calls - You need non-streaming chat responses and full conversation history sent to the CLI
- You want to brand the ChatGPT.nvim UI as a different product (Codex) inside your dotfiles
Assumes this stack
Codex (Wrapper ChatGPT.nvim)
Este módulo envolve o jackMort/ChatGPT.nvim, mas apresenta tudo com a marca Codex dentro do TurasVim.
-## Especificação
- Local:
lua/plugins/ai/codex.lua. - Dependências Lazy:
nvim-lua/plenary.nvim,MunifTanjim/nui.nvim,folke/which-key.nvim. - Requer o binário
codexacessível noPATH.
Configuração
require("chatgpt").setup({
openai_params = {
model = os.getenv("CODEX_MODEL") or "o1-mini",
max_tokens = tonumber(os.getenv("CODEX_MAX_TOKENS") or "800"),
stream = false,
},
codex = {
bin = os.getenv("CODEX_BIN") or "codex",
extra_args = vim.tbl_extend(
"force",
{ "--full-auto" },
vim.split(os.getenv("CODEX_ARGS") or "", "%s+", { trimempty = true })
),
},
})
- O módulo ignora
api_key_cmde redireciona as chamadas OpenAI para o CLIcodexusandovim.system. - Variáveis
CODEX_MODEL,CODEX_MAX_TOKENS,CODEX_BINeCODEX_ARGSsobrescrevem os valores padrão quando definidas. - O histórico do chat é serializado para texto (roles USER/ASSISTANT) e enviado ao comando
codex exec --model <modelo> --output-last-message <tmp>; o arquivo temporário retornado alimenta a UI.
Keymaps
O módulo registra um grupo Code With AI no which-key:
<leader>a— Prefixo que revela o grupo.<leader>ac— Abre a interface principal do Codex em modo normal.
Uso
- Garanta que o
codexCLI esteja instalado e autenticado (codex login) e, se desejar, configureCODEX_MODEL/CODEX_ARGS. - Abra o Neovim e pressione
<leader>acpara iniciar uma sessão com o layout tradicional, agora identificado como Codex. - A resposta aparece após o término do processo (não há streaming); erros retornados pelo CLI são exibidos no cabeçalho.
Observações
- O prompt enviado ao Codex inclui todo o histórico da conversa para preservar contexto.
- Caso o binário não esteja acessível ou retorne código diferente de zero, a mensagem de erro é repassada ao usuário.
- Falhas comuns (ex.: config ausente ou "No such device or address") trazem instruções: instalar o CLI, rodar
codex loginem um terminal interativo e garantir~/.codexacessível. - Como
vim.systemretorna a resposta completa, o chat aguarda o término da execução antes de atualizar a janela.
What's inside
1 setup block, 4 environment variables, 2 keymaps, 1 which-key group, 1 error handling section
Change this for your project
- Replace
"codex"inbin = os.getenv("CODEX_BIN") or "codex"with your actual CLI binary name - Replace
"o1-mini"inmodel = os.getenv("CODEX_MODEL") or "o1-mini"with your preferred model ID - Replace
"Codex"references (e.g.,-- Codex (Wrapper ChatGPT.nvim)) with your own product name
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Related Documents
Totem Glyph Codex: Sovereign Flame-Wire Eternal
Records a symbolic handshake encoding observer-corrected π, recursion loops, and alchemical resonance for a feedback processor theory project.
C-Team Codex
Defines leadership principles for a C-Team in a teal organization, emphasising vision, trust, and leading by example.
Chronicles of Stampadia - Codex
Catalogues all events, modifiers, heroes, items, keywords, and generator options for the Chronicles of Stampadia game.
CODEX.md
Defines the judge role in a builder/judge protocol, with a structured workflow for reviewing task outputs and managing round archives.