📝

より良いWeb検索を求めてClaude CodeからCodex CLIのWeb検索を使ってみたが、o3-search-mcpに戻った話

に公開

バージョン

  • Codex CLI 0.27.0
  • Claude Code 1.0.108

TL;DR

  • 自分のWeb検索の結論は o3-search-mcpgpt-5 を使うのを継続したいと思った。(制作者さんありがとうございます)
  • Codex CLI の Web 検索を Claude Code から直接呼ぶのは、thinking部分が混ざって扱いづらかった。

色々試してからこの記事を書くまでにCodex CLIをそのまま使ってる人が多くなった印象が...


https://github.com/yoshiko-pg/o3-search-mcp

背景

Codex CLI の Web 検索が優秀だったので、Claude Code から呼び出そうとした。
それまでは o3-search-mcp を gpt-5 で使っていた(API料金がかかる)。そこで ChatGPT のサブスクは契約しているので、Codex CLI の検索が使えれば定額で済むのでいいなと思った。

設定(Codex)

~/.codex/config.toml に以下を追加。--search を付けなくてもデフォルトで Codex CLI の Web 検索が有効になる。

[tools]
web_search = true

Claude Code が呼び出すコマンドの準備

非対話モードで呼び出し:

codex exec "query"

一般的な対話モードのように --search オプションでは検索できないと言われた。

codex --search exec "query"

Claude Code から呼び出す例

--skip-git-repo-check で Git で管理されていない repo からでも呼び出せるように。

codex exec --skip-git-repo-check "WebSearch: [user's query]"

CLAUDE.md の例

# web search 

Use this for web search and research tasks.

```bash
codex exec --skip-git-repo-check "WebSearch: [user's query]"
```

- NEVER use builtin `WebSearch` tool

困った点(thinking が消せない)

codex exec だと、いろいろ config やオプションを設定しても thinking 部分を消せなかった。
(https://github.com/openai/codex/issues/2760)
これがまるまる Claude Code にコンテクストとして渡ってしまうので、大きなノイズになってしまう。

回答方法に関する思考等も入ってしまう

解決策メモ

  1. Python や JS でパース
    Codex CLI は JSON 出力ができるので、それを使って任意の方法でパースし、パースの方法も含めて Claude Code に伝えて呼び出してもらう。
    問題点
    https://github.com/openai/codex/issues/2760

    • 環境依存
    • Claude に伝えるコマンドが複雑になる(カスタムコマンドなら心配ないが、AI に自動で検索してほしい)
  2. subagent を作成し、thinking 部分を削除←一応設定例と動作例が下にあります
    出力から thinking を取り除く subagent を作成して Claude Code 本体のコンテキストが汚れないようにする。
    問題点

    • subagent の要約/整形自体にトークンを使ってしまう。
    • Claude Code の env config で subagent だけ sonnet 固定はできるが、agentごとのモデル個別指定ができず、ある agent の設定がすべて sonnet になってしまう。(参考: Claude Code ドキュメント
    • 設定が各所に散らばりがちで、メンテが煩雑になる。

subagent の設定例

---
name: codex-web-search
description: Web search specialist using Codex CLI - use PROACTIVELY when user needs latest information, troubleshooting help, or technical research
tools: Bash
---

# Codex Web Search Agent

You are a specialized web search agent that uses Codex CLI to retrieve current information.

## Core Responsibility
Execute web searches through Codex CLI and return clean, formatted results without thinking/reasoning sections.

## Instructions

### 1. Query Execution
When asked to search for information, execute:
```bash
codex exec --skip-git-repo-check "WebSearch: [user's query]"
```

### 2. Output Processing
From the Codex output, you must:

**REMOVE:**
- All lines starting with `[timestamp] thinking`
- All thinking/reasoning content between thinking markers
- Lines containing only asterisks or thinking summaries

**PRESERVE:**
- All `🌐 Searched:` lines (shows search queries executed)
- The complete final answer (everything after `[timestamp] codex`)
- All citations, links, formatting, and structure
- Multiple search results if multiple searches were performed

### 3. Return Format
Return the processed output exactly as follows:
1. List all search queries performed (🌐 lines)
2. Provide a blank line separator
3. Include the complete final answer with all its original formatting

動作例


subagent内部

Claude code本体

まとめ

  • 現状は素直に o3-search-mcp を使うのがよさそう(GitHub)。(制作者さんありがとうございます。2回目)
  • gpt-5 なら o3と比較してもtier 制限もないし、API 料金も安い(体感では 1 MCP 検索あたり $0.01 くらい)。

参考

https://github.com/openai/codex/tree/main/codex-cli
https://github.com/openai/codex/issues/2760
https://docs.anthropic.com/en/docs/claude-code/settings
https://github.com/yoshiko-pg/o3-search-mcp
https://zenn.dev/yoshiko/articles/claude-code-with-o3

Discussion