Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/opencode/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SessionPrompt } from "./prompt"
import { fn } from "@/util/fn"
import { Command } from "../command"
import { Snapshot } from "@/snapshot"
import { Plugin } from "@/plugin"

import type { Provider } from "@/provider/provider"
import { PermissionNext } from "@/permission/next"
Expand Down Expand Up @@ -136,9 +137,19 @@ export namespace Session {
})
.optional(),
async (input) => {
const sessionID = Identifier.ascending("session")

// Allow plugins to customize session creation (e.g., set custom directory)
const creating = await Plugin.trigger(
"session.creating",
{ sessionID, parentID: input?.parentID },
{ directory: Instance.directory },
)

return createNext({
id: sessionID,
parentID: input?.parentID,
directory: Instance.directory,
directory: creating.directory,
title: input?.title,
permission: input?.permission,
})
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ export interface Hooks {
system: string[]
},
) => Promise<void>
/**
* Called before a session is created. Allows plugins to customize
* session creation, including setting a custom working directory.
*
* - `directory`: The working directory for the session (defaults to Instance.directory)
*/
"session.creating"?: (
input: { sessionID: string; parentID?: string },
output: { directory: string },
) => Promise<void>
/**
* Called before session compaction starts. Allows plugins to customize
* the compaction prompt.
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/content/docs/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Plugins can subscribe to events as seen below in the Examples section. Here is a

#### Session Events

- `session.creating`
- `session.created`
- `session.compacted`
- `session.deleted`
Expand Down