Skip to content

How to get tool_result in stream? #9

Description

@livoras
import { claude } from '@instantlyeasy/claude-code-sdk-ts';

async function main() {
  const prompt = "Use bash to echo Hello"
  
  const response = await claude()
    .withModel('claude-sonnet-4-20250514')
    .skipPermissions()
    .query(prompt)
    .stream(async (message) => {
      console.log("----------------------------------------", prompt, "-----------------------------------------")
      console.dir(message, { depth: null })
    });
  
  console.log(response);
}

main();

Result

---------------------------------------- Use bash tool to echo Hello World -----------------------------------------
{
  type: 'assistant',
  content: [
    {
      type: 'tool_use',
      id: 'toolu_01Cs4pQMaSyTVkmis338ppeM',
      name: 'Bash',
      input: {
        command: 'echo "Hello World"',
        description: 'Echo Hello World to console'
      }
    }
  ],
  session_id: 'a1898fef-d554-4961-b618-a9e173cb0faa'
}
---------------------------------------- Use bash tool to echo Hello World -----------------------------------------
{
  type: 'assistant',
  content: [ { type: 'text', text: 'Hello World' } ],
  session_id: 'a1898fef-d554-4961-b618-a9e173cb0faa'
}
---------------------------------------- Use bash tool to echo Hello World -----------------------------------------
{
  type: 'result',
  subtype: 'success',
  content: '',
  session_id: 'a1898fef-d554-4961-b618-a9e173cb0faa',
  usage: {
    input_tokens: 11,
    cache_creation_input_tokens: 1834,
    cache_read_input_tokens: 49394,
    output_tokens: 84,
    server_tool_use: { web_search_requests: 0 },
    service_tier: 'standard'
  },
  cost: { total_cost: undefined }
}
Image

There is a content type named 'tool_result', but actually never see any tool use results in stream callback. How can I get a tool use result after a tool is finished.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No 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