I wanted to run the same work as a Codex scheduled task from the command line, sign in with my ChatGPT account, and connect an MCP server. These are separate steps: Scheduled manages the recurring task, codex exec runs a prompt, and codex mcp configures the tools available to the CLI. The examples below use Windows PowerShell.
Can the CLI launch an existing Scheduled task?
As of October 17, 2026, the documented CLI does not provide the Scheduled management interface or a command to run an existing scheduled task by name or ID. Use the desktop app or ChatGPT web to manage Scheduled tasks. The CLI can run the same instructions independently, but this does not trigger the saved Scheduled task. See the official Scheduled tasks documentation.
Save the full task instructions in task.txt, then pass that file to Codex:
Get-Content -Raw -Encoding UTF8 .\task.txt | codex exec -
The final - explicitly tells Codex to read the prompt from standard input. If the working directory is outside a Git repository, add --skip-git-repo-check:
Get-Content -Raw -Encoding UTF8 .\task.txt | codex exec --skip-git-repo-check -
This starts a separate run. The scheduled task’s chat history, attachments, and connections are not automatically imported. Put durable instructions in the prompt or an accessible skill, and configure the required MCP servers for the CLI. The non-interactive mode documentation explains prompt files and scripting.
Sign in with a ChatGPT account
After installing Codex CLI, run:
codex login
Complete the browser sign-in using the ChatGPT account you want to use. Codex caches the credentials for subsequent runs, including codex exec. Check the authentication status with:
codex login status
ChatGPT sign-in uses the Codex access available through your ChatGPT plan. An OpenAI API key is an alternative authentication method with separate usage-based API billing; it is not required for ChatGPT sign-in. See the authentication documentation.
Sign in on a machine without a browser
For a remote or headless machine, use device-code authentication:
codex login --device-auth
Open the displayed link in a browser on another device, sign in, and enter the one-time code. Device-code login may need to be enabled in your ChatGPT security settings or by a workspace administrator.
Add a remote MCP server
For a server that exposes a Streamable HTTP MCP endpoint, add its URL. The name myserver is a local configuration label, and the URL below is a placeholder:
codex mcp add myserver --url "https://example.com/mcp"
If that server supports and requires OAuth, authenticate separately:
codex mcp login myserver
If it instead expects a bearer token, use an environment variable. Set MY_MCP_TOKEN through your normal secret-management mechanism, then reference its name when adding the server:
codex mcp add tokenserver --url "https://example.com/mcp" --bearer-token-env-var MY_MCP_TOKEN
That environment variable must be available to the process running Codex, including any scheduled invocation.
Add a local MCP server
For a local server using the stdio transport, put its launch command after --. Choose the command appropriate for your server; these are alternative examples:
codex mcp add pythonserver -- python "C:\mcp\server.py"
codex mcp add nodeserver -- node "C:\mcp\server.js"
Replace the paths with your actual server files. Python or Node.js must be installed and available to the CLI process. Codex starts the stdio server using the configured command.
Check the MCP configuration
codex mcp list
In an interactive Codex session, enter /mcp to inspect active MCP servers. For all available management commands, run:
codex mcp --help
The official MCP documentation covers CLI configuration, OAuth, and additional options.
Run the prompt every hour
For an independent hourly CLI workflow on Windows, Windows Task Scheduler can invoke a PowerShell script that runs codex exec. Use absolute paths, the intended working directory, and a Windows account with access to the saved authentication and required environment variables. This is a separate schedule from the task saved in the app. Test the prompt and MCP connection manually before scheduling it.

