◆IKORG

← Practice · September 2, 2026

How to Connect GPT-5 to Claude Code Without an API Key

Install Codex CLI, sign in with a ChatGPT subscription, and give Claude a command it can use to ask GPT-5 questions right in the middle of its work.

6 min readtools

I have two subscriptions—ChatGPT and Claude. And for a long time, it was frustrating: you are working in Claude Code and want a second opinion on the architecture, but to ask GPT, you have to open a browser, copy the code there, then copy the answer back. On top of that, GPT API access costs extra, even though the subscription is already paid for.

It turns out there is no need to pay twice. Codex CLI supports authentication with a ChatGPT subscription, which means I can ask GPT-5 questions from the terminal under the same limits as in the browser. The rest is straightforward: wrap the call in a script and tell Claude about it.

Below is exactly what I have installed and use every day.

What You Get in the End

ask-gpt "review this migration plan; what am I missing?"
cat большой-файл.py | ask-gpt "find the bottlenecks"

Claude Code runs these commands itself when I ask it to “ask GPT.” The answer comes back into the session, and this does not use Claude’s limit—it uses the ChatGPT subscription.

Step 1. Install Codex CLI

You need Node.js 20 or newer:

npm install -g @openai/codex
codex --version

If npm installs global packages into a system directory and complains about permissions, install them locally in your home directory and add the path:

npm config set prefix ~/.local/node
export PATH="$HOME/.local/node/bin:$PATH"

Step 2. Sign In with Your Subscription

codex login --device-auth

The command displays a short code and a link. Open the link in a browser—even on your phone—enter the code, and confirm the sign-in to your ChatGPT account. That is it: the token is stored in ~/.codex/auth.json and refreshes automatically, so there is no need to sign in again.

This is the key point: no API key is created or billed. It uses the same subscription you already pay for.

Check it:

codex exec -s read-only --skip-git-repo-check "Reply with one word: hello"

Step 3. The Wrapper

Bare codex exec is inconvenient: it is agentic, prints an operational log, and makes you dig out the answer. Let us create a ~/.local/bin/ask-gpt script:

#!/usr/bin/env bash
set -euo pipefail
export PATH="$HOME/.local/node/bin:$PATH"

# question: either as an argument or via stdin
PROMPT="${*:-}"
[ -z "$PROMPT" ] && PROMPT="$(cat)"
[ -z "$PROMPT" ] && { echo "ask-gpt: empty question" >&2; exit 2; }

WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
ANS="$WORK/answer.txt"

codex exec -s read-only --skip-git-repo-check -C "$WORK" -o "$ANS" "$PROMPT" \
  >"$WORK/run.log" 2>&1 || { cat "$WORK/run.log" >&2; exit 1; }

# save a copy of the question and answer so they can be found later
ARCH="$HOME/system/gpt-consult/$(date +%Y-%m-%d_%H%M%S).md"
mkdir -p "$(dirname "$ARCH")"
{ echo "## Question"; echo "$PROMPT"; echo; echo "## Answer"; cat "$ANS"; } > "$ARCH"

cat "$ANS"
echo "[saved: $ARCH]" >&2
chmod +x ~/.local/bin/ask-gpt
ask-gpt "Reply with one word: working?"

Three things here are deliberate. -s read-only means GPT cannot modify files; it can only read and think, which is the right mode for a consultant. -C "$WORK" makes an empty temporary directory the working directory so the agent does not wander around the project. The answer goes to stdout as plain text, while the archive path goes to stderr so it does not get in the way when you redirect output to a file.

Step 4. Tell Claude About the Command

Claude Code will not figure out on its own that it has access to GPT. Add a few lines to ~/.claude/CLAUDE.md (or the project’s CLAUDE.md):

## Second opinion from GPT—the `ask-gpt` command

GPT-5 can be consulted from any session (ChatGPT subscription, not API; Claude's limit is not used):

    echo "question or code" | ~/.local/bin/ask-gpt
    ~/.local/bin/ask-gpt "short question"

When to use it: code and architecture review, a second opinion on a disputed decision,
generating long-form text. Do not use it to send users' personal data.

After that, “ask GPT what it thinks about this design” works like any other request.

Problems I Ran Into

Send long questions only through stdin. If you pass multiline text containing quotes and code as a command-line argument, sooner or later the escaping will break, and at a couple hundred kilobytes you will get “Argument list too long.” Write the question to a file and pass it as ask-gpt < вопрос.txt.

Do not kill a stuck request with pkill -f codex. The -f pattern searches the full command line and will match your own command, killing your shell. Match the exact name only: pkill -x codex, or use the specific PID.

The answer takes one to three minutes. Codex works agentically: it thinks, plans, and then answers. An empty answer file after thirty seconds does not mean it is stuck. Use timeout 300 and wait; in an interactive session, it is better to run it in the background.

Subscription limits are not unlimited. If you send dozens of heavy questions per hour, you can hit the ChatGPT Plus limit. For a background stream of requests, it is cheaper to look at OpenRouter—I will cover that in a separate post.

Why This Is Useful in Practice

There are three use cases that made this worth setting up.

Review with a fresh pair of eyes. Claude writes a module, and I ask GPT to find holes in it. The two models make different mistakes, and when one confidently overlooks a bug, the other often spots it.

Long-form text. Descriptions, articles, and website copy are expensive to generate under Claude’s limit. I send them to GPT, while Claude only edits and inserts them.

A debate between two models. Sometimes I ask both models to evaluate the same decision and show where they disagree. If they disagree, the issue really is ambiguous, and I need to decide it myself instead of flipping a coin.