Codex CLI कैसे इंस्टॉल करें और पहला टास्क चलाएँ

Windows 11, macOS और Linux पर Codex CLI इंस्टॉल करने के चार तरीके, installation verify करने और official sign-in को custom provider से अलग रखने की पूरी guide।

विषय-सूची

Codex CLI, OpenAI का Rust में लिखा terminal-based coding agent है। यह आपके कंप्यूटर पर चलता है, repository के code के साथ काम करता है और tasks को isolated environment में execute करता है। इसे standalone installer, npm, Homebrew cask या GitHub Releases के binary से इंस्टॉल किया जा सकता है।

इंस्टॉलेशन के बाद दो अलग connection paths में से एक चुनें: ChatGPT या OpenAI API Key के जरिए official OpenAI sign-in, अथवा अपनी API Key वाला custom provider। दोनों में वही codex command इस्तेमाल होती है; अलग client इंस्टॉल करने की जरूरत नहीं है।

इंस्टॉल करने से पहले क्या चाहिए

Official installation guide में दिए baseline system requirements:

  • macOS: 12 (Monterey) या नया।
  • Linux: Ubuntu 20.04+ / Debian 10+।
  • Windows: WSL2 के साथ Windows 11; native Windows के लिए अलग documentation है।

Node.js सिर्फ npm से इंस्टॉल करते समय जरूरी है। Standalone installer, Homebrew cask और GitHub Releases archive तैयार executable इंस्टॉल करते हैं।

Official ChatGPT sign-in के लिए ChatGPT account चाहिए, जबकि official API access के लिए platform.openai.com की key चाहिए। Custom provider के लिए अपना BetterToken account, अपनी API Key और current Model ID चाहिए। Node.js केवल npm installation या automatic provider setup script के लिए आवश्यक है।

Codex CLI इंस्टॉल करना

macOS और Linux — standalone installer

यह सबसे आसान तरीका है; Node.js की जरूरत नहीं:

curl -fsSL https://chatgpt.com/codex/install.sh | sh

इंस्टॉलेशन पूरा होने पर command जाँचें:

codex --version

Version number दिखने का मतलब है कि command उपलब्ध है।

Codex इंस्टॉल हो गया? Current guide के अनुसार अपनी API Key कनेक्ट करें। पहले मौजूदा Docs में fields जाँचें, फिर यदि आपकी अपनी key अभी नहीं है तो BetterToken account बनाएँ।

macOS — Homebrew cask

brew install --cask codex

npm — macOS, Linux और Windows

काम करने वाला npm और Node.js आवश्यक है। Minimum Node.js version के लिए npmjs.com/@openai/codex पर package का engines field देखें।

npm install -g @openai/codex

इंस्टॉलेशन के बाद codex command न मिले तो global npm directory आपके PATH में नहीं है। सही path देखें:

npm config get prefix

उस directory को shell के PATH से मिलाएँ और terminal restart करें। बिना जाँचे /bin न जोड़ें: global executable का layout OS और Node.js installation method पर निर्भर करता है।

Linux — GitHub Releases का binary

github.com/openai/codex/releases पर तैयार Linux archives उपलब्ध हैं:

  • codex-x86_64-unknown-linux-musl.tar.gz — x86_64 के लिए
  • codex-aarch64-unknown-linux-musl.tar.gz — arm64 के लिए

Archive extract करें, executable का नाम codex रखें और उसे ऐसी writable directory में डालें जो आपके PATH में हो।

Windows

Codex CLI Windows पर natively या WSL2 के अंदर चल सकता है। Current Windows documentation native use के लिए Windows 11 की सिफारिश करती है; पूरी तरह updated Windows 10 best-effort आधार पर supported है।

Native Windows (PowerShell)। Official installer:

powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

Native mode में Codex, Windows Sandbox के जरिए task execution isolate करता है। Mode ~/.codex/config.toml में सेट होता है:

[windows]
sandbox = "elevated"
  • "elevated": recommended; dedicated sandbox user और firewall rules इस्तेमाल करता है।
  • "unelevated": dedicated sandbox के बिना current user पर ACL restrictions लागू करता है।

WSL2। Linux instructions के अनुसार WSL2 के अंदर Codex CLI का Linux version इंस्टॉल करें। Linux tooling के लिए OpenAI project को /mnt/ के बजाय WSL filesystem में रखने की सलाह देता है।

उसी Codex CLI को BetterToken API से कनेक्ट करें

BetterToken, Codex CLI को किसी दूसरे application से replace नहीं करता। Official codex executable ही काम करता है और ~/.codex/config.toml custom provider चुनता है। Codex requests, Base URL `https://www.bettertoken.ai/v1%60?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-044&utm_content=ustanovit-codex-cli-pervyy-zapusk के जरिए OpenAI Responses का उपयोग करती हैं।

यह migration तीन साफ चरणों में करें:

  1. अपना BetterToken account और अपनी dedicated API Key बनाएँ। Shared key इस्तेमाल न करें।
  2. Current BetterToken Codex guide खोलें, मौजूदा model list से current Model ID और provider fields copy करें, फिर चल रही Codex process को पूरी तरह बंद करें। Model ID, group या authentication fields को इस article से स्थायी मानकर न लिखें।
  3. पुराने OpenAI environment variables साफ करें, current Docs के अनुसार provider configuration लागू करें, Codex को नए terminal में पूरी तरह restart करें और एक छोटा read-only task चलाएँ। उसके बाद BetterToken Dashboard में request, model, status और input/output/cache token usage की पुष्टि करें।

macOS और Linux में conflicting variables हटाएँ:

unset OPENAI_API_KEY
unset OPENAI_BASE_URL

Windows PowerShell में current और future user sessions से उन्हें हटाएँ:

Remove-Item Env:OPENAI_API_KEY -ErrorAction SilentlyContinue
Remove-Item Env:OPENAI_BASE_URL -ErrorAction SilentlyContinue
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY", $null, "User")
[Environment]::SetEnvironmentVariable("OPENAI_BASE_URL", $null, "User")

Automatic BetterToken provider setup

यह script केवल BetterToken provider configure करती है; Codex CLI इंस्टॉल नहीं करती। इसके लिए Node.js चाहिए। यदि API key या model argument में न दिया जाए, script interactive terminal में पूछती है—secret को command line में न डालें।

macOS और Linux:

curl -fsSL https://www.bettertoken.ai/install-codex-provider.sh?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-044&utm_content=ustanovit-codex-cli-pervyy-zapusk | bash

Windows PowerShell:

iwr https://www.bettertoken.ai/install-codex-provider.ps1?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-044&utm_content=ustanovit-codex-cli-pervyy-zapusk -OutFile "$env:TEMP\install-codex-provider.ps1"; powershell -ExecutionPolicy Bypass -File "$env:TEMP\install-codex-provider.ps1"

Authentication fields और credential storage, Codex surface तथा client version के अनुसार बदल सकते हैं। इसलिए यह article exact auth booleans तय नहीं करता और official sign-in को custom provider के साथ एक ही configuration example में नहीं मिलाता।

संबंधित surface को current BetterToken Codex guide में चुनें, current model ID और provider fields वहीं से लें और changes के बाद Codex को पूरी तरह restart करें। Secrets केवल current Docs में बताए तरीके से दें—article text या command line में नहीं।

Official OpenAI authentication

नीचे की commands केवल official OpenAI route के लिए हैं। BetterToken custom provider के साथ codex login status, BetterToken API को verify नहीं करता; उसके लिए test task चलाएँ और Dashboard record देखें।

ChatGPT से sign in

यह command चलाएँ:

codex login

Browser खुलेगा—अपने ChatGPT account से sign-in पूरा करें। Codex session को locally save करता है, इसलिए अगले runs पर आम तौर पर दोबारा login नहीं करना पड़ता।

Authentication से पहले बिना arguments के codex चलाने पर interface भी sign-in का विकल्प देता है। Sign-in शुरू करने का मुख्य तरीका codex login है।

API Key से sign in

Key को command argument के रूप में न दें और echo से print न करें—value shell history में जा सकती है।

Current environment या secrets manager में OPENAI_API_KEY सेट करें। Value को article, command या output में न डालें। Variable सेट होने पर इसे stdin से दें:

printenv OPENAI_API_KEY | codex login --with-api-key

Key screen पर नहीं दिखती और command history में दर्ज नहीं होती।

Authentication verify करें

Sign-in के बाद status देखें:

codex login status

Command current authentication method दिखाती है या बताती है कि sign-in नहीं हुआ।

Status में authentication न हो तो सही method से sign-in दोहराएँ।

Sign out करके saved credentials हटाने के लिए:

codex logout

~/.codex/auth.json में access token होता है—इसे password की तरह संभालें। इसे manually delete न करें; साफ करने के लिए हमेशा codex logout इस्तेमाल करें।

Authentication documentation: developers.openai.com/codex/auth। Login subcommands और flags: developers.openai.com/codex/cli/reference।

Test repository में पहला task

Working code पर असर न पड़े, इसलिए शुरुआत test repository में करें। कोई public repository clone करें, उदाहरण के लिए Codex:

git clone https://github.com/openai/codex codex-test
cd codex-test

Read-only task चलाएँ:

codex --sandbox read-only "Explain the entry point of this project"

--sandbox read-only flag model-generated commands को केवल पढ़ने तक सीमित करता है। यदि Codex files बदले बिना project structure का सार्थक वर्णन देता है, पहला run पूरा है।

उसी restriction के साथ TUI जारी रखने के लिए:

codex --sandbox read-only

Interface में लिखें: What files are in this project and what does each do?

Official OpenAI route इस्तेमाल कर रहे हों तो authentication active होने की पुष्टि करें:

codex login status

BetterToken provider इस्तेमाल कर रहे हों तो सामान्य response connection की पहली पुष्टि है। साथ ही BetterToken Dashboard में request, model, status और input/output/cache token usage दिखाई देने की जाँच करें।

Troubleshooting

npm install के बाद codex: command not found

npm config get prefix चलाएँ, result को PATH से मिलाएँ और terminal restart करें। Exact executable path OS और Node.js installation method पर निर्भर करता है, इसलिए बिना जाँचे /bin न जोड़ें।

ChatGPT sign-in पर browser नहीं खुला

GUI रहित remote server पर पहले official device-code flow (beta) आजमाएँ:

codex login --device-auth

इसे पहले ChatGPT security settings या workspace permissions में enable करना पड़ता है। उपलब्ध न हो तो API Key sign-in इस्तेमाल करें:

printenv OPENAI_API_KEY | codex login --with-api-key

Callback, device code और fallback options official authentication guide में दिए हैं।

BetterToken कनेक्ट करने के बाद Codex response नहीं देता

पाँच बातें जाँचें: base_url ठीक https://www.bettertoken.ai/v1%60?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-044&utm_content=ustanovit-codex-cli-pervyy-zapusk हो, wire_api responsesही रहे, Model ID और provider fields current BetterToken Docs से लिए गए हों,model_providerचुनी हुई[model_providers.*]table से match करे, और पुरानेOPENAI_API_KEYयाOPENAI_BASE_URLconfiguration override न कर रहे हों।config.toml` बदलने के बाद Codex को नए terminal में पूरी तरह restart करें।

codex login status में Not logged in दिखता है

  • ChatGPT sign-in: codex login फिर चलाएँ और browser में sign-in पूरा करें।
  • API Key sign-in: working environment में OPENAI_API_KEY मौजूद होने की पुष्टि करें, फिर printenv OPENAI_API_KEY | codex login --with-api-key दोहराएँ।
  • ~/.codex/auth.json manually delete न करें—codex logout इस्तेमाल करें।

Codex CLI documentation: developers.openai.com/codex/cli। उसी Codex CLI को BetterToken API से जोड़ें: docs.bettertoken.ai/en/ai-tools/codex।

अपना LLM वर्कफ़्लो बेहतर बनाना चाहते हैं?

एक API से मॉडल जोड़ें, कुंजियाँ प्रबंधित करें और AI खर्च नियंत्रित करें।

मुफ़्त शुरू करें