Skip to content

Feature: session:end internal hook event #10142

@spk-alex

Description

@spk-alex

Summary

Add a session:end internal hook event that fires when a session completes.

Use Case

Integrating OpenClaw with workflow orchestration systems like Temporal. When an agent session completes, we want to signal back to a waiting workflow so it can proceed to the next step.

Current workaround requires agents to explicitly run a CLI command at the end of their task, which is fragile and adds cognitive load to agent instructions.

Proposed Behavior

// Hook event structure
{
  type: 'session',
  action: 'end',
  sessionKey: string,
  sessionId: string,
  timestamp: Date,
  context: {
    stopReason: 'stop' | 'toolUse' | 'maxTokens' | 'error',
    lastMessage?: string,
    metadata?: Record<string, any>  // Custom data passed when session started
  }
}

Example Hook

const handler: HookHandler = async (event) => {
  if (event.type !== 'session' || event.action !== 'end') return;
  
  const workflowId = event.context.metadata?.workflowId;
  if (workflowId) {
    // Signal Temporal workflow
    await exec(`temporal workflow signal --workflow-id ${workflowId} --name complete`);
  }
};

Notes

The docs mention session:end as a planned future event. This issue tracks that feature request.

Related: session:start would also be useful for the same integration patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.enhancementNew feature or requestimpact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions