Skip to content

Built in shell tool does not emit terminal content with exitCode on tool.execution_complete #1803

Description

@anthonykim1

I’m trying to get the exit code for shell tool execution completion from the SDK tool.execution_complete event.

The SDK types suggest this should be available through terminal content on the tool result:

// node_modules/@github/copilot-sdk/dist/generated/session-events.d.ts

export interface ToolExecutionCompleteEvent {
  data: ToolExecutionCompleteData;
  type: "tool.execution_complete";
}

export interface ToolExecutionCompleteData {
  result?: ToolExecutionCompleteResult;
  success: boolean;
  toolCallId: string;
}

export interface ToolExecutionCompleteResult {
  content: string;
  contents?: ToolExecutionCompleteContent[];
  detailedContent?: string;
  structuredContent?: {
    [k: string]: unknown | undefined;
  };
}

export interface ToolExecutionCompleteContentTerminal {
  cwd?: string;
  exitCode?: number;
  text: string;
  type: "terminal";
}

Given that shape, I expected the shell command exit code to be available from the completed tool event payload like this:

session.on("tool.execution_complete", event => {
  const terminalContent = event.data.result?.contents?.find(
    content => content.type === "terminal"
  );

  const exitCode = terminalContent?.exitCode;
});

In other wordsL event.data.result?.contents?.find(c => c.type === "terminal")?.exitCode

Actual behavior seems to be tool.execution_complete just returning flattened text in event.data.result

event.data.result = {
  content: "...<shellId: 0 completed with exit code 0>",
  detailedContent: "...<shellId: 0 completed with exit code 0>"
}

Should the built-in shell/bash tool populate ToolExecutionCompleteResult.contents with a ToolExecutionCompleteContentTerminal block containing exitCode and cwd?

Image

Metadata

Metadata

Labels

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