Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This PR introduces a comprehensive snippet management system for Codex CLI, enabling developers to store, manage, and dynamically reference reusable code snippets within prompts.
Features Added
snippet add,snippet show,snippet list,snippet remove,snippet helpsnippet: <label>syntax in prompts with automatic code expansion~/.codex/snippets.jsonWhy
Developers frequently reuse common code patterns (debounce functions, API templates, utility functions) across different prompts. Currently, users must manually copy-paste or retype these patterns, leading to:
This feature addresses these pain points by providing a built-in snippet system similar to what developers expect in modern code editors.
How
Implementation Architecture
snippet-storage.ts): JSON-based persistence with CRUD operationssnippet-commands.ts): CLI command parsing and user interactionsnippet-resolver.ts): Regex-based snippet detection and replacementinput-utils.ts,cli.tsx): Seamless integration with existing input processingTechnical Details
/snippet:\s*([a-zA-Z0-9_-]+)/gto detect references✅ Expanded snippets: debounce)Example Usage
Testing
Breaking Changes
None. This is a purely additive feature that doesn't modify existing functionality.
Files Changed
codex-cli/src/utils/snippet-storage.ts- Core storage managementcodex-cli/src/utils/snippet-commands.ts- CLI command handlerscodex-cli/src/utils/snippet-resolver.ts- Inline snippet resolutioncodex-cli/src/utils/input-utils.ts- Integration with input processingcodex-cli/src/cli.tsx- CLI command routingRelated Issues
Addresses the need for code reusability and developer productivity enhancement in terminal-based AI coding workflows.
Checklist: