How to know from CLI when session_id session has closed? #7772

Open
opened 2026-02-16 18:08:11 -05:00 by yindo · 7 comments
Owner

Originally created by @davidbernat on GitHub (Jan 27, 2026).

Question

Here is a typical metadata file for a specific {session_id}.json file created when opencode starts.

>>> cat ses_3ffca45a2ffef1fjbYFDGFsNIm.json
{
  "id": "ses_3ffca45a2ffef1fjbYFDGFsNIm",
  "slug": "tidy-planet",
  "version": "1.1.36",
  "projectID": "999db38d440ef12a42cc028ea638c2b6cc4dc148",
  "directory": "{base_directory},
  "title": "OPENCODE session heartbeat plan v0.1.0",
  "time": {
    "created": 1769530047072,
    "updated": 1769530997208
  },
  "summary": {
    "additions": 0,
    "deletions": 0,
    "files": 0
  }
}  

But the documentation do not specify any state change when its opencode session closes.
It would be helpful for monitoring logs in real time from outside the opencode process.

opencode export still takes about 1 second and so we are still looking for a real-time mode.
But this will suffice for our needs in the meantime. Thank you.

Originally created by @davidbernat on GitHub (Jan 27, 2026). ### Question Here is a typical metadata file for a specific `{session_id}.json` file created when opencode starts. ``` >>> cat ses_3ffca45a2ffef1fjbYFDGFsNIm.json { "id": "ses_3ffca45a2ffef1fjbYFDGFsNIm", "slug": "tidy-planet", "version": "1.1.36", "projectID": "999db38d440ef12a42cc028ea638c2b6cc4dc148", "directory": "{base_directory}, "title": "OPENCODE session heartbeat plan v0.1.0", "time": { "created": 1769530047072, "updated": 1769530997208 }, "summary": { "additions": 0, "deletions": 0, "files": 0 } } ``` But the documentation do not specify any state change when its opencode session closes. It would be helpful for monitoring logs in real time from outside the opencode process. `opencode export` still takes about 1 second and so we are still looking for a real-time mode. But this will suffice for our needs in the meantime. Thank you.
Author
Owner

@github-actions[bot] commented on GitHub (Jan 27, 2026):

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

  • #10592: How does our client access OpenCode CLI context in real-time via Bash? (i.e. Logging API) - This issue discusses real-time access to session context and state, which relates to monitoring session lifecycle and closure.

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

@github-actions[bot] commented on GitHub (Jan 27, 2026): This issue might be a duplicate of existing issues. Please check: - #10592: How does our client access OpenCode CLI context in real-time via Bash? (i.e. Logging API) - This issue discusses real-time access to session context and state, which relates to monitoring session lifecycle and closure. Feel free to ignore if none of these address your specific case.
Author
Owner

@davidbernat commented on GitHub (Jan 27, 2026):

Hey OpenCode folks:

  1. privileged to see that my GitHub posts are so unique the bot only finds references to my GitHub posts.
  2. I spoke too soon. How does opencode export {session_id} work in practice?

This error code repeats for every session_id, and we know several are open.
Either the docs are confused, or my use is confused, or you have an errant billionaire playing scorpio showing design flaws by infiltrating your code running on expensive hardware. Let's assume 1 or 2. :)

Just need an answer here. The ticket above is several weeks old. Thanks, guys.
Otherwise errant billionaire would be in a real big pickle (pun intended)
Thanks. xo.
Image

@davidbernat commented on GitHub (Jan 27, 2026): Hey OpenCode folks: 1. privileged to see that my GitHub posts are so unique the bot only finds references to my GitHub posts. 2. I spoke too soon. How does `opencode export {session_id}` work in practice? This error code repeats for every session_id, and we know several are open. Either the docs are confused, or my use is confused, or you have an errant billionaire playing scorpio showing design flaws by infiltrating your code running on expensive hardware. Let's assume 1 or 2. :) Just need an answer here. The ticket above is several weeks old. Thanks, guys. Otherwise errant billionaire would be in a real big pickle (pun intended) Thanks. xo. <img width="1331" height="579" alt="Image" src="https://github.com/user-attachments/assets/0249473c-fee3-4445-a5ae-77f47576b82d" />
Author
Owner

@cravenceiling commented on GitHub (Jan 27, 2026):

Right now, you can only export sessions when you are inside the project folder for that session. So it should work if you enter the project directory and run the same command. For example, running opencode export will show the sessions for the current project.

Also, if I’m not mistaken, running opencode export in a directory that is not a git repo will display sessions that don’t have a specific project ID associated with them, but are instead marked as "global".

@cravenceiling commented on GitHub (Jan 27, 2026): Right now, you can only export sessions when you are inside the project folder for that session. So it should work if you enter the project directory and run the same command. For example, running `opencode export` will show the sessions for the current project. Also, if I’m not mistaken, running `opencode export` in a directory that is not a git repo will display sessions that don’t have a specific project ID associated with them, but are instead marked as `"global"`.
Author
Owner

@cravenceiling commented on GitHub (Jan 27, 2026):

@rekram1-node why not allow exporting any session regardless of the current project/directory with a flag or something?

@cravenceiling commented on GitHub (Jan 27, 2026): @rekram1-node why not allow exporting any session regardless of the current project/directory with a flag or something?
Author
Owner

@davidbernat commented on GitHub (Jan 28, 2026):

@cravenceiling it is not a problem to change cwd for each particular session_id since its directory is in the session logs.
Now that I know. Thank you.

much more concerning is:

  1. opencode export {session_id} takes ~1 second to generate, which is a lot of bandwidth for n tasks at heartbeat intervals
  2. none of the {session_id}.json data confirms when a session_id has terminated, so no knowledge when to stop monitoring
  3. what is saved in the opencode system logging directory is fragmented and undocumented, as is any reconstruction protocols to reconstitute an export (of session context) from the opencode system logging components; clearly this is intentional on the part of your company
  4. it appears entirely undocumented how to debug an issue such as what may also be complicated matters for my project, which is that since 2026-22-01 logging of all opencode logs except those {session_id}.json seem to have ceased [shrug]

1 & 2 are core capabilities of any enterprise solution, and a current blocker.
Modern workflow management spawns dozens of subagent sessions per primary session making provenance and tracing impossible, despite being core value propositions for client integrity
3 is frustrating, and one presumes you will eventually offer this, which should render any monitoring I write obsolete
4 is a problem unique to 'some interaction with opencode' and important to fix at my earliest convenience with information

1 & 2 concern this ticket directly.
3 & 4 are helpful.
Thanks. Blocker.

@davidbernat commented on GitHub (Jan 28, 2026): @cravenceiling it is not a problem to change cwd for each particular session_id since its directory is in the session logs. Now that I know. Thank you. much more concerning is: 1. `opencode export {session_id}` takes ~1 second to generate, which is a lot of bandwidth for n tasks at heartbeat intervals 2. none of the `{session_id}.json` data confirms when a session_id has terminated, so no knowledge when to stop monitoring 3. what is saved in the opencode system logging directory is fragmented and undocumented, as is any reconstruction protocols to reconstitute an export (of session context) from the opencode system logging components; clearly this is intentional on the part of your company 4. it appears entirely undocumented how to debug an issue such as what may also be complicated matters for my project, which is that since 2026-22-01 logging of all opencode logs except those `{session_id}.json` seem to have ceased [shrug] 1 & 2 are core capabilities of any enterprise solution, and a current blocker. Modern workflow management spawns dozens of subagent sessions per primary session making provenance and tracing impossible, despite being core value propositions for client integrity 3 is frustrating, and one presumes you will eventually offer this, which should render any monitoring I write obsolete 4 is a problem unique to 'some interaction with opencode' and important to fix at my earliest convenience with information 1 & 2 concern this ticket directly. 3 & 4 are helpful. Thanks. Blocker.
Author
Owner

@davidbernat commented on GitHub (Jan 28, 2026):

Your backends are either compromised to create faulty data or those designs to provide access to mechanisms to create faulty data are intentional in your user agreement. xo.
Please respond with the requested information. We have made our necessary public statements. Blocker.
Fascinating to watch the industry.

@davidbernat commented on GitHub (Jan 28, 2026): Your backends are either compromised to create faulty data or those designs to provide access to mechanisms to create faulty data are intentional in your user agreement. xo. Please respond with the requested information. We have made our necessary public statements. Blocker. Fascinating to watch the industry.
Author
Owner

@davidbernat commented on GitHub (Feb 12, 2026):

@cravenceiling @rekram1-node I second the suggestion of @cravenceiling. To me, at the end of every session, I want a nicely exported sequence to reproduce the interactions and the subagents. Presently, these are deleted every ten sessions, which is an extraordinarily valuable resource of my company to lose. Building my own log => export functionality, and adding monitors or plugins, seems to be an improper division of labor.

Where is OpenCode on scheduling these improvements to enterprise logging paradigms of reproducibility and accountability?

@davidbernat commented on GitHub (Feb 12, 2026): @cravenceiling @rekram1-node I second the suggestion of @cravenceiling. To me, at the end of every session, I want a nicely exported sequence to reproduce the interactions and the subagents. Presently, these are deleted every ten sessions, which is an extraordinarily valuable resource of my company to lose. Building my own log => export functionality, and adding monitors or plugins, seems to be an improper division of labor. Where is OpenCode on scheduling these improvements to enterprise logging paradigms of reproducibility and accountability?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7772