Skip to content

fix: propagate OPENCODE_SESSION_ID to wiki tool in-process run (#399) - #400

Merged
dhague merged 1 commit into
mainfrom
fix/399-propagate-opencode-session-id
Sep 3, 2026
Merged

fix: propagate OPENCODE_SESSION_ID to wiki tool in-process run (#399)#400
dhague merged 1 commit into
mainfrom
fix/399-propagate-opencode-session-id

Conversation

@dhague

@dhague dhague commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #399.

The session-tracker plugin's shell.env hook injects OPENCODE_SESSION_ID into every shell command's environment, but the wiki tool runs the enchiridion bundle in-process via run() — the hook never fires for tool calls, only for shell spawns.

Root cause

When the agent calls wiki(args=[save-session, --slug, ...]), the bundle's captureSession() reads process.env.OPENCODE_SESSION_ID via processLookupEnv. Because the wiki tool is an in-process call (not a shell command), the tracker's shell.env hook never sets the env var, so captureSession throws the 'neither ID is set' error.

Fix

In wiki-enchiridion.ts's execute(), inject context.sessionID (which OpenCode supplies to every tool call) into process.env.OPENCODE_SESSION_ID before calling run() and restore the prior value in a finally block.

Test

cli.run.test.ts gains a regression test that sets the env var directly (simulating what the plugin now does) and asserts that run(['save-session']) moves past the 'neither ID is set' check before failing on the tracker-state lookup — confirming the var is read by the in-process bundle.

The session-tracker plugin's shell.env hook injects OPENCODE_SESSION_ID
into every *shell* command's environment, but the wiki tool runs the
enchiridion bundle in-process via run() — the hook never fires for it.

Fix: in wiki-enchiridion.ts's execute(), inject context.sessionID into
process.env.OPENCODE_SESSION_ID before calling run() and restore the
prior value in a finally, so save-session (and any other subcommand that
reads the session id) sees the correct value.

Test: cli.run.test.ts adds a regression test that sets the env var
directly (simulating what the plugin now does) and asserts that
run(['save-session']) moves past the 'neither ID is set' check before
failing on the tracker-state lookup — confirming the env var is read.
@dhague
dhague merged commit a9e71c5 into main Sep 3, 2026
7 checks passed
@dhague
dhague deleted the fix/399-propagate-opencode-session-id branch September 3, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: propagate OPENCODE_SESSION_ID to the wiki command layer

1 participant