Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(opencode): forward subagent parentID so drop_subagent_captures works (#755)

AkitaOnRailscf0faa9a394a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1347e7e8..aedb30ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+- The generated OpenCode and OpenCode 2 plugins now forward a subagent session's
+ `parentID` as the `agent_id` marker, so `[capture] drop_subagent_captures` can
+ recognize and drop OpenCode subagent sessions. Previously both plugins emitted
+ only `title`/`projectID` on `session.created`, so the marker never reached the
+ server and the opt-in was a silent no-op for OpenCode. Root sessions (no
+ `parentID`) stay unmarked (#755).
+
## [2.3.1] - 2026-09-17
### Added
diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rs
index 8ac7b60d..7e35448b 100644
--- a/crates/ai-memory-cli/src/commands/install_hooks.rs
+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs
@@ -3183,9 +3183,16 @@ const AiMemoryOpencode2: Plugin = {
?? event?.location?.directory ?? directory;
if (type === "session.created") {
const id = data?.sessionID ?? data?.id ?? info?.id;
+ const parentID = info?.parentID ?? data?.parentID;
startSession(id, data?.location?.directory ?? loc, {
title: data?.title ?? info?.title,
projectID: data?.projectID ?? info?.projectID,
+ // Subagent sessions carry a parentID; forward it as the `agent_id`
+ // marker so drop_subagent_captures works on OpenCode 2 too (#755).
+ // Root sessions have no parentID and must stay unmarked.
+ ...(typeof parentID === "string" && parentID
+ ? { agent_id: parentID }
+ : {}),
});
}
if (type === "session.idle") {
@@ -3845,6 +3852,13 @@ export const AiMemoryHooks: Plugin = async ({{ directory }}) => {{
startSession(id, cwd, {{
title: info.title,
projectID: info.projectID,
+ // A subagent session carries a parentID; forward it as the `agent_id`
+ // subagent marker so `drop_subagent_captures` can recognize (and drop)
+ // OpenCode subagent sessions too (#755). A root session has no
+ // parentID — never mark it, or every session looks like a subagent.
+ ...(typeof info.parentID === "string" && info.parentID
+ ? {{ agent_id: info.parentID }}
+ : {{}}),
}});
}}
if (event?.type === "session.idle") {{
@@ -8347,6 +8361,11 @@ model = "gpt-5"
assert!(!plugin.contains("handoffChecked"));
assert!(plugin.contains("function startSession"));
assert!(plugin.contains("function endSession"));
+ // #755: a subagent session must forward its parentID as the `agent_id`
+ // marker (so drop_subagent_captures recognizes it), and only when the
+ // parentID is a real string (a root session stays unmarked).
+ assert!(plugin.contains("agent_id: info.parentID"));
+ assert!(plugin.contains("typeof info.parentID === \"string\""));
assert!(plugin.contains("fetchHandoff"));
assert!(plugin.contains("function applyMarkerParams"));
assert!(plugin.contains("readFileSync(marker, \"utf8\")"));
@@ -8438,6 +8457,11 @@ model = "gpt-5"
assert!(!plugin.contains("Plugin.define({"));
assert!(plugin.contains("const AiMemoryOpencode2: Plugin = {"));
assert!(plugin.contains("export default AiMemoryOpencode2;"));
+ // #755: subagent sessions forward parentID as the `agent_id` marker,
+ // only when it is a real string (root sessions stay unmarked).
+ assert!(plugin.contains("const parentID = info?.parentID ?? data?.parentID"));
+ assert!(plugin.contains("agent_id: parentID"));
+ assert!(plugin.contains("typeof parentID === \"string\""));
// Beta hooks, verified against `@opencode-ai/plugin@beta`.
assert!(plugin.contains("ctx.event.subscribe"));
assert!(plugin.contains("ctx.session.hook(\"prompt\""));