Skip to content

[FEATURE]: opencode session export to markdown or json #9387

Closed

Description

@paralin

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

We need a way to export opencode sessions to Markdown or Json format with a TUI flag.

 % opencode session export -h
opencode session export [sessionID]

export session transcript to file

Positionals:
  sessionID  session id to export                                                           [string]

Options:
  -h, --help        show help                                                              [boolean]
  -v, --version     show version number                                                    [boolean]
      --print-logs  print logs to stderr                                                   [boolean]
      --log-level   log level                   [string] [choices: "DEBUG", "INFO", "WARN", "ERROR"]
      --dir         directory to run in                                                     [string]
  -o, --output      output file path                                                        [string]
  -f, --format      output format       [string] [choices: "markdown", "json"] [default: "markdown"]

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Jan 19, 2026
  2. github-actions commented on Jan 19, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  3. tetipong2542 commented on Jan 21, 2026

    @tetipong2542

    I Needed

  4. paralin commented on Jan 21, 2026

    @paralin
    ContributorAuthor

    Implemented; #5426

  5. dhruvkej9 commented on Jan 28, 2026

    @dhruvkej9

    @rekram1-node please merge this export is very difficult currently, also there is no way to export to JSON

  6. Nindaleth commented on Feb 12, 2026

    @Nindaleth
    Contributor

    @paralin hey I was wondering, is the current session export to JSON somehow insufficient? I totally welcome Markdown exports for human consumption, just the JSON is already available and your PR seems to duplicate it.

    If no sessionID given, a small and simple selection TUI opens.

    $ opencode export --help
    opencode export [sessionID]
    
    export session data as JSON
    
    Positionals:
      sessionID  session id to export                                                           [string]
    
    Options:
      -h, --help        show help                                                              [boolean]
      -v, --version     show version number                                                    [boolean]
          --print-logs  print logs to stderr                                                   [boolean]
          --log-level   log level                   [string] [choices: "DEBUG", "INFO", "WARN", "ERROR"]
    
  7. mrw commented on Feb 12, 2026

    @mrw

    I'm not the original creator of this, but I am also looking forward to this. For us, the markdown export is definitely more useful than the JSON because we want to make it readable for humans without going through a whole additional level of JSON->Markdown transformation.

  8. Nindaleth commented on Feb 12, 2026

    @Nindaleth
    Contributor

    @mrw if you need something right now, OpenCode already supports /export which does exactly the MD export of the active session - product of an earlier PR of @paralin (just found out and used today, thx!)

  9. mrw commented on Feb 12, 2026

    @mrw

    Thanks! We've been using that but are hoping to get this in a CLI flag so we can automate it better as part of an internal conversation sharing flow/system we're building. (I'm just sharing this to help contextualize the feedback/use case).

  10. mnickw commented on Apr 1, 2026

    @mnickw

    It would be great to have output file path as an argument as well

  11. mnickw commented on Apr 1, 2026

    @mnickw

    Also would be awesome to have export to md in sdk as well

  12. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on May 3, 2026
  13. blain3white commented on Jun 8, 2026

    @blain3white

    If you need a workaround/reference, I'm building Clean My Agent for local AI-agent session scan/backup/export, including OpenCode sessions: https://github.com/blain3white/clean-my-agent

  14. defanator commented on Jul 1, 2026

    @defanator

    Hi. Not sure if this is relevant one, but wanted to share: for a relatively long session exporting via TUI ("Export session transcript", Ctrl-x x) produces truncated markdown in a way when a few initial queries from the very beginning of a session are missing. Exporting the same session from CLI to JSON works just fine with the entire history present in resulting JSON.

    +1 for having a CLI option to choose format, and hopefully the above finding would save someone's time.

    (Observing this with opencode 1.17.12.)

  15. emyasnikov commented on Jul 30, 2026

    @emyasnikov

    On long context and compaction the sessions are getting truncated, those why I implemented own plugin to avoid this (https://github.com/emyasnikov/opencode-session-store), but hope to see an built-in feature (#39641).

  16. Chi-teck commented on Aug 21, 2026

    @Chi-teck

    I just published another workaround while this is open: oc-transcript, a small CLI app that opens opencode.db read-only and prints a chronological transcript to stdout or to a file.

    One caveat, and the reason I still want this feature in opencode itself: the tool reads the database directly, and the schema is apparently not a public API. Any change to it on your side can break the tool without warning. A built-in export command stays correct across such changes; an outside reader cannot.

  17. neriousy commented on Oct 1, 2026

    @neriousy
    Member

    OpenCode v2 can export sessions:

    • opencode session export [session] writes the session as JSON (--sanitize is available), and opencode session import loads it back.
    • In the TUI, /export saves the transcript as Markdown or JSON, either to the clipboard or to a file.

    Added in #40914 and moved under the session command in #48055.

    Closing as completed. If something doesn't work on v2, please open a new issue.

  18. LorenzoBettini commented on Oct 15, 2026

    @LorenzoBettini

    But in the desktop app it always export as JSON; I typically prefer markdown; isn't there a way to export it as markdown in the desktop app?

  19. Chi-teck commented on Oct 15, 2026

    @Chi-teck

    @LorenzoBettini the agent conversations typically happen in markdown format. So it would be tricky to wrap markdown messages into markdown export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions