Skip to content
Open
2 changes: 2 additions & 0 deletions packages/opencode/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { LspTool } from "./lsp"
import { Truncate } from "./truncation"
import { PlanExitTool, PlanEnterTool } from "./plan"
import { ApplyPatchTool } from "./apply_patch"
import { GetCurrentSessionTitleTool } from "./session-title"

export namespace ToolRegistry {
const log = Log.create({ service: "tool.registry" })
Expand Down Expand Up @@ -112,6 +113,7 @@ export namespace ToolRegistry {
CodeSearchTool,
SkillTool,
ApplyPatchTool,
GetCurrentSessionTitleTool,
...(Flag.OPENCODE_EXPERIMENTAL_LSP_TOOL ? [LspTool] : []),
...(config.experimental?.batch_tool === true ? [BatchTool] : []),
...(Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE && Flag.OPENCODE_CLIENT === "cli" ? [PlanExitTool, PlanEnterTool] : []),
Expand Down
18 changes: 18 additions & 0 deletions packages/opencode/src/tool/session-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import z from "zod"
import { Tool } from "./tool"
import { Session } from "../session"
import DESCRIPTION from "./session-title.txt"

export const GetCurrentSessionTitleTool = Tool.define("get_current_session_title", {
description: DESCRIPTION,
parameters: z.object({}),
async execute(_params, ctx) {
const session = await Session.get(ctx.sessionID)
const title = session?.title ?? "Unknown"
return {
title: "Retrieved session title",
output: title,
metadata: {},
}
},
})
3 changes: 3 additions & 0 deletions packages/opencode/src/tool/session-title.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Use this tool to retrieve the title of the current session.

This tool returns the current session's title as a string. The title is initially set when the session is created and may possibly be updated using other tools at your disposal.