What feature would you like to see?
Proposal: Add Semantic Index and Search to Codex CLI
Summary
Codex CLI is strong at local agentic coding, but it struggles to reliably find the right places in medium to large codebases because it lacks a first-class semantic search capability. Users currently fall back to grep or filename heuristics, which break down in polyglot repositories, renamed identifiers, or when concepts are expressed differently than the query.
Adding an official semantic index and search flow will materially improve Codex’s accuracy and speed on large projects and aligns with OpenAI’s direction to make Codex handle larger contexts and complex, multi-step software tasks.
Problem Statement and User Evidence
Community requests:
An earlier issue specifically asked for semantic code search via an index and was closed without the feature landing in core, indicating unmet demand and opportunity to contribute.
Current limitations:
Without semantic retrieval, Codex relies on keyword search and path heuristics, which miss relevant code when names differ or when logic spans multiple files and languages. This leads to wrong or incomplete edits and extra back-and-forth. Community discussions repeatedly call for deeper “code intelligence.”
Strategic fit:
Codex has recently expanded in IDEs, terminals, and GitHub with a push toward larger tasks and persistent state. A built-in index that the agent can query is complementary to that direction.
Goals and Non-Goals
Goals
- Make Codex reliably find relevant code across large and polyglot repos through vector retrieval that understands meaning, not just tokens.
- Keep the developer workflow simple — one command to build an index, one to search it, with minimal configuration.
- Enable both human-initiated searches and future agent-initiated tool use.
Non-goals
- Replace static analysis, LSP features, or heavyweight language servers.
- This is retrieval to locate relevant snippets fast and feed them to Codex, not a full IDE indexer.
Proposed Solution
CLI Subcommands
codex index
Builds a local semantic index of the project using OpenAI embeddings and stores vectors plus metadata on disk.
codex search "<natural language query>"
Returns the most similar code snippets with file path and line ranges. Output is optimized for copy-pasting into a prompt or for agent consumption.
This approach maintains compatibility with existing workflows while delivering a major improvement for large repositories.
Why This Benefits Users
Developers using Codex across IDEs and terminals will gain faster, more accurate navigation and edits on real-world projects. As Codex takes on multi-file changes and long-running feature work, retrieval becomes critical.
Detailed Design
User-Facing CLI
codex index
- Scans the current workspace, skipping common build/vendor folders.
- Splits code into logical chunks (~200–400 lines).
- Embeds them and writes an index at
.codex_index.
- Prints a progress summary at completion.
codex search "refactor image upload to be async" --top 8
- Embeds the query.
- Runs approximate nearest-neighbor search over the local index.
- Prints top K hits with file path, line ranges, short code excerpts, and similarity scores.
Configuration and Flags
--src <path> to index a specific directory
--top <K> for number of search results
--filter <glob or extension> to narrow search output
- Configurable embedding model (default to current OpenAI model)
- Optional backend selection for future pluggability
Core Components
Chunking
Use pragmatic, language-agnostic splitting by blocks or functions. Store file paths and spans per chunk. Optional tree-sitter parsing can be added later.
Embeddings
Use OpenAI’s embeddings API for vector representations. Store model metadata for compatibility. Allow swapping models via config.
Vector Store
Use a local FAISS index via Rust bindings for speed and zero external dependencies.
- Stored at
.codex_index/index.bin
- Metadata sidecar JSON maps vector IDs to file paths and line ranges
Alternative backends like Qdrant or SQLite-ANN can be added later if requested.
Search
Normalize embeddings for cosine similarity and return top K results.
Output includes readable snippets with file paths and line spans for quick navigation.
Agent Integration Path
Near-term: Human-driven usage.
Mid-term: Expose search as a callable tool so Codex can autonomously pull context during tasks.
This leverages the tool-use push without tightly coupling to a specific interface.
Performance and Cost Considerations
- Indexing cost/time scale with project size; embedding is a one-time operation per chunk.
- Search is instantaneous and local once built.
- This shifts cost from repeated scans to a cacheable, one-time build step.
- Incremental indexing can be added later by hashing files and re-embedding changed chunks only.
Privacy and Security
- Indexing is limited to the current workspace; no traversal outside it.
- Embeddings are created by sending code chunks to the OpenAI embeddings API, documented publicly.
- Users can opt out by not running
index.
- Future enhancement could include offline local-model indexing.
Alternatives Considered
- Pure keyword search: Fast but fails with synonymy and refactors.
- IDE LSPs: Strong per-language but not suited for multi-language, terminal-first workflows.
- External vector DBs: Add operational complexity; local FAISS index keeps setup frictionless.
Compatibility and UX
- Backward compatible; new commands are opt-in.
- Plain text output compatible with all terminals.
- Index directory (
.codex_index) can be safely deleted or ignored in Git.
- Fits seamlessly into Codex’s multi-environment rollout.
Phased Delivery Plan
Phase 1 – MVP
- Implement
codex index and codex search commands.
- Add directory scanning, chunking, embeddings, FAISS index build, metadata write.
- Implement query path with top-K results and filters.
- Add documentation and usage examples.
Phase 2 – Quality and Speed
- Parallelize embedding with backoff for rate limits.
- Add incremental indexing via hashing.
- Introduce language-aware chunking for common stacks.
Phase 3 – Agent Integration
- Expose as a lightweight MCP tool for Codex to call autonomously.
- Optionally provide editor jump links (e.g., VS Code).
Success Metrics
- Improved search precision measured by human acceptance during refactors.
- Fewer “can’t find the right file” errors.
- Community adoption and positive issue/PR feedback.
- High maintainability and test coverage.
Risks and Mitigations
- FAISS bindings maintenance: Pin stable crates; allow a Rust ANN fallback.
- Token cost for large repos: Clear documentation and default chunking limits.
- Roadmap overlap: Communicate early with maintainers to align efforts.
What’s Needed from Maintainers
- Approval to proceed with implementation behind guarded, opt-in commands.
- Guidance on dependency policy — FAISS vs pure Rust ANN.
- Preferences on configuration surface and naming.
- Direction on whether to expose agent tool use in the initial PR or later.
Contribution Plan
- Create a feature branch and integrate new commands into the existing CLI parser.
- Implement indexer and search modules in Rust with clear interfaces and metadata.
- Add comprehensive tests for chunking, metadata, and an integration test on a sample repo.
- Update README and CLI help.
- Respond quickly to review feedback and sign the CLA as required.
Why Now
Codex is expanding rapidly across IDEs and CLIs, with GPT-5-Codex emphasizing sustained, multi-file work. A semantic index is the missing foundation that lets the agent consistently find the right code and make safer changes at scale. Shipping this now compounds the value of recent updates and improves real developer workflows immediately.
Additional information
No response
What feature would you like to see?
Proposal: Add Semantic Index and Search to Codex CLI
Summary
Codex CLI is strong at local agentic coding, but it struggles to reliably find the right places in medium to large codebases because it lacks a first-class semantic search capability. Users currently fall back to grep or filename heuristics, which break down in polyglot repositories, renamed identifiers, or when concepts are expressed differently than the query.
Adding an official semantic index and search flow will materially improve Codex’s accuracy and speed on large projects and aligns with OpenAI’s direction to make Codex handle larger contexts and complex, multi-step software tasks.
Problem Statement and User Evidence
Community requests:
An earlier issue specifically asked for semantic code search via an index and was closed without the feature landing in core, indicating unmet demand and opportunity to contribute.
Current limitations:
Without semantic retrieval, Codex relies on keyword search and path heuristics, which miss relevant code when names differ or when logic spans multiple files and languages. This leads to wrong or incomplete edits and extra back-and-forth. Community discussions repeatedly call for deeper “code intelligence.”
Strategic fit:
Codex has recently expanded in IDEs, terminals, and GitHub with a push toward larger tasks and persistent state. A built-in index that the agent can query is complementary to that direction.
Goals and Non-Goals
Goals
Non-goals
Proposed Solution
CLI Subcommands
codex indexBuilds a local semantic index of the project using OpenAI embeddings and stores vectors plus metadata on disk.
codex search "<natural language query>"Returns the most similar code snippets with file path and line ranges. Output is optimized for copy-pasting into a prompt or for agent consumption.
This approach maintains compatibility with existing workflows while delivering a major improvement for large repositories.
Why This Benefits Users
Developers using Codex across IDEs and terminals will gain faster, more accurate navigation and edits on real-world projects. As Codex takes on multi-file changes and long-running feature work, retrieval becomes critical.
Detailed Design
User-Facing CLI
codex index.codex_index.codex search "refactor image upload to be async" --top 8Configuration and Flags
--src <path>to index a specific directory--top <K>for number of search results--filter <glob or extension>to narrow search outputCore Components
Chunking
Use pragmatic, language-agnostic splitting by blocks or functions. Store file paths and spans per chunk. Optional tree-sitter parsing can be added later.
Embeddings
Use OpenAI’s embeddings API for vector representations. Store model metadata for compatibility. Allow swapping models via config.
Vector Store
Use a local FAISS index via Rust bindings for speed and zero external dependencies.
.codex_index/index.binAlternative backends like Qdrant or SQLite-ANN can be added later if requested.
Search
Normalize embeddings for cosine similarity and return top K results.
Output includes readable snippets with file paths and line spans for quick navigation.
Agent Integration Path
Near-term: Human-driven usage.
Mid-term: Expose search as a callable tool so Codex can autonomously pull context during tasks.
This leverages the tool-use push without tightly coupling to a specific interface.
Performance and Cost Considerations
Privacy and Security
index.Alternatives Considered
Compatibility and UX
.codex_index) can be safely deleted or ignored in Git.Phased Delivery Plan
Phase 1 – MVP
codex indexandcodex searchcommands.Phase 2 – Quality and Speed
Phase 3 – Agent Integration
Success Metrics
Risks and Mitigations
What’s Needed from Maintainers
Contribution Plan
Why Now
Codex is expanding rapidly across IDEs and CLIs, with GPT-5-Codex emphasizing sustained, multi-file work. A semantic index is the missing foundation that lets the agent consistently find the right code and make safer changes at scale. Shipping this now compounds the value of recent updates and improves real developer workflows immediately.
Additional information
No response