| name | export-chat-session |
| description | Export a Codex Desktop session conversation from local ~/.codex/sessions JSONL logs into a reusable JSON file and a standalone self-contained HTML viewer. Use when the user asks to export, archive, save, render, or view a Codex chat/session/conversation, especially when they provide a Codex session id. |
Export Chat Session
Workflow
- Ask for a full session id when the user did not provide one. Tell them: "You can right-click the conversation in the left sidebar and copy the session id."
- Run
scripts/export_chat_session.py with the session id. The script recursively searches ~/.codex/sessions/ for a JSONL filename ending in <session-id>.jsonl.
- Export both files to the user's Downloads directory by default:
codex-chat-<session-id>.json
codex-chat-<session-id>.html
- Give the user the output paths. Mention if any messages were skipped as non-conversation metadata.
Script
Use:
python3 /Users/zweizhao/.codex/skills/export-chat-session/scripts/export_chat_session.py --session-id <session-id>
Optional flags:
--output-dir <dir>
--include-context
--include-aborted
--after-text <text>
--before-text <text>
Data Rules
Use response_item messages as the canonical source:
type == "response_item"
payload.type == "message"
payload.role in ["user", "assistant"]
Ignore duplicated or non-user-facing records by default:
event_msg
reasoning
turn_context
session_meta as message content
web_search_call
token_count
task_started
task_complete
Also filter auto-loaded workspace instruction messages by default, including messages that start with # AGENTS.md instructions for ... and contain an <INSTRUCTIONS> block. Use --include-context only when the user explicitly wants these internal context messages.
The standalone HTML must embed the full export JSON and the local vendored Markdown renderer internally. It must not depend on the sibling JSON file or a remote CDN at view time.