gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Bug: Non-interactive sessions do not log tool calls in session history

Open sniemczyk-google opened this issue 1 year ago • 1 comments

What happened?

When running the Gemini CLI in a non-interactive session (using the -p flag), tool call information is not being recorded in the automatically saved session history JSON files. However, when running in an interactive session (with the -i flag), the tool calls are logged correctly.

For example, when running the following command:

gemini -e none --allowed-tools=run_shell_command --allowed-tools="run_shell_command(wc)" -p "Use wc to count the lines in poem.md"

The command executes successfully, but the corresponding session log file is missing the toolCalls section, even though a tool was used. Here is the content of the session file:

{
  "sessionId": "2d930cce-6744-4551-a764-1a2d085b84f9",
  "projectHash": "a7a86deed79eae624f96947bf41d7fff47ef3939dc916d899817b2532bd7821d",
  "startTime": "2025-10-10T20:48:21.244Z",
  "lastUpdated": "2025-10-10T20:49:00.880Z",
  "messages": [
    {
      "id": "4442deb0-5157-4b1b-8126-e75402df2858",
      "timestamp": "2025-10-10T20:48:21.245Z",
      "type": "user",
      "content": "Use wc to count the lines in poem.md"
    },
    {
      "id": "90ac2c87-4640-4c0a-9875-c912c9038c7e",
      "timestamp": "2025-10-10T20:49:00.880Z",
      "type": "gemini",
      "content": "5 poem.md",
      "thoughts": [
        {
          "subject": "Defining the Command",
          "description": "I've realized I need to use `wc` to count lines, which requires a command string. The user wants the line count of `poem.md`, so I'll incorporate that file name into the command. The `run_shell_command` tool is the vehicle I'll use to execute this.",
          "timestamp": "2025-10-10T20:48:24.329Z"
        },
        {
          "subject": "Executing the Command",
          "description": "I've got the command figured out: `wc -l poem.md`. Using `wc` directly is the most straightforward route, and `-l` is key for line counting.  I'm ready to execute it with the `run_shell_command` tool.",
          "timestamp": "2025-10-10T20:48:25.751Z"
        }
      ],
      "tokens": {
        "input": 11578,
        "output": 4,
        "cached": 8155,
        "thoughts": 0,
        "tool": 0,
        "total": 11582
      },
      "model": "gemini-2.5-pro"
    }
  ]
}

What did you expect to happen?

What did you expect to happen?

I expected the session history file for the non-interactive session to contain a `toolCalls` field within the Gemini message, detailing the tool that was executed, similar to what is logged for interactive sessions. This is a regression, as this information was previously available.


### Client information

<details>
<summary>Client Information</summary>

Run `gemini` to enter the interactive CLI, then run the `/about` command.

```console
> /about

╭───────────────────────────────────────────────────────────────────────────────────╮
│                                                                                   │
│ About Gemini CLI                                                                  │
│                                                                                   │
│ CLI Version                 0.10.0-nightly.20251007.c195a9aa-git.c82c2c2b         │
│ Git Commit                  c82c2c2b                                              │
│ Model                       gemini-2.5-pro                                        │
│ Sandbox                     no sandbox                                            │
│ OS                          linux                                                 │
│ Auth Method                 gemini-api-key                                        │
│                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────╯

Login information

No response

Anything else we need to know?

This issue appears to be a regression. As noted in issue #3882, the automatic saving of chats in interactive sessions works as expected, but for non-interactive chats, the tool call information is missing. This is a pretty substantial bug that hinders the ability to analyze tool usage in non-interactive sessions.

sniemczyk-google avatar Oct 10 '25 20:10 sniemczyk-google

@sniemczyk-google I have a PR in: #10951.

bl-ue avatar Oct 11 '25 15:10 bl-ue