Edit or delete messages in a Claude Code session

Guide · August 2026 · ~4 min read

A session transcript is a plain text file — every user message, assistant reply, and tool result is one JSON line in ~/.claude/projects/<project-dir>/<session-id>.jsonl. That means you can edit it. People do this to remove a wrong turn the agent took, redact secrets before sharing a session, fix a tool output that failed for an environment reason, or trim a bloated session back to something usable.

The one rule

Records link through uuid → parentUuid, and tool calls pair with results through tool_use_id. Break either linkage and the session won't resume — you've traded an ugly message for a dead file. So:

Why not just open it in a text editor?

You can, for a small file. Real sessions are tens of megabytes with one JSON object per line — no wrapping, no search across records, and one stray comma kills the whole file. The manual commands to find broken records are in the resume troubleshooting guide.

Editing with SessionPatch

  1. Open the editor and load a copy of your session file — parsing runs in your browser, nothing uploads.
  2. Click a user/assistant text card or tool result and choose Edit. Linked tool call/result pairs can be removed together.
  3. Run Doctor after every structural change. It can guide a missing parentUuid repair; Edit mode can update exact tool-input JSON after validating it.
  4. Review the exported copy before replacing anything, then verify it with claude --resume.

FAQ

Can I edit a Claude Code conversation after the fact?

Yes. Edit a copy first and keep record ids unchanged. SessionPatch can edit user/assistant text and tool-result content locally; not every structural field is editable yet.

How do I delete a message from a Claude Code session?

Deleting a record may require reparenting its children, and deleting a tool event requires its matching pair. SessionPatch handles linked tool call/result removal; Doctor can guide missing-parent repair while other parent-chain defects may still need manual work.

Related