Skip to content

feat: built-in image generation tool and slash command#20848

Open
jackwotherspoon wants to merge 3 commits intomainfrom
nanobanana
Open

feat: built-in image generation tool and slash command#20848
jackwotherspoon wants to merge 3 commits intomainfrom
nanobanana

Conversation

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

@jackwotherspoon jackwotherspoon commented Mar 2, 2026

Summary

Introduces a built-in image generation tool and /image slash command, enabling users to generate and edit images directly from the CLI using Nano Banana (Gemini) image generation models.

Gemini.CLI.-.image.generation.mp4

Details

  • Added GenerateImageTool to packages/core which uses @google/genai to interface with Nano Banana models.
  • Default Model: gemini-3.1-flash-image-preview (NanoBanana 2).
  • Auth Gating: The tool is only registered when using Gemini API Key (USE_GEMINI) or Vertex AI (USE_VERTEX_AI) authentication methods, as "Login with Google" can't support image models currently.
  • Added /image (and /img alias) slash command to packages/cli for quick image generation.
  • Supports parameters like aspect ratio, size, count, and input image for editing.
  • Added an experimental setting experimental.imageGeneration to toggle this feature.
  • Images are saved to a configurable directory (defaults to generated-images/).
  • Supports return_to_context to allow the model to see the generated image for iterative refinement.

Related Issues

None (New feature).

How to Validate

Use natural language or /image.

  1. Enable image generation in /settings.
  2. Run a simple prompt: Create an image of a pixel art banana.
  3. Check generated-images/ for the output.
  4. Try editing an image: /image make it blue --edit generated-images/banana.png.
  5. Verify multiple variations: /image a futuristic city --count 3.
  6. Run tests: npm test -w @google/gemini-cli-core -- src/tools/generate-image.test.ts and npm test -w @google/gemini-cli -- src/ui/commands/imageCommand.test.ts.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on MacOS
    • npm run

@jackwotherspoon jackwotherspoon requested review from a team as code owners March 2, 2026 15:14
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the CLI's capabilities by integrating advanced image generation and editing functionalities. It allows users to create and modify images directly through command-line prompts, making the CLI a more versatile tool for creative and development workflows. The feature is opt-in via an experimental setting and is designed to work seamlessly with existing Gemini authentication methods.

Highlights

  • Built-in Image Generation Tool: Introduced a new GenerateImageTool in packages/core that leverages Nano Banana (Gemini) image generation models for creating and editing images.
  • New Slash Command: Added an /image (with /img alias) slash command to packages/cli for direct image generation and editing from the command line interface.
  • Configurable Settings and Authentication: The image generation feature is controlled by an experimental setting (experimental.imageGeneration) and is only registered when using Gemini API Key or Vertex AI authentication methods.
  • Image Parameters and Output: The /image command supports various parameters such as aspect ratio, size, count, and an input image for editing. Generated images are saved to a configurable directory (defaulting to generated-images/) and can be returned to context for iterative refinement.
  • Comprehensive Testing: New unit tests were added for both the imageCommand in packages/cli and the GenerateImageTool in packages/core to ensure functionality and parameter validation.
Changelog
  • docs/cli/settings.md
    • Added experimental.imageGeneration setting to the CLI settings documentation.
  • docs/reference/configuration.md
    • Documented the new experimental.imageGeneration boolean setting in the configuration reference.
  • packages/cli/src/config/config.ts
    • Integrated the imageGeneration setting from experimental settings into the CLI configuration loading.
  • packages/cli/src/config/settingsSchema.ts
    • Added the imageGeneration property to the experimental section of the settings schema.
  • packages/cli/src/services/BuiltinCommandLoader.ts
    • Imported and registered the new imageCommand to make it available as a built-in slash command.
  • packages/cli/src/ui/commands/imageCommand.test.ts
    • Added a new test file for the imageCommand and its argument parsing utility parseImageArgs.
  • packages/cli/src/ui/commands/imageCommand.ts
    • Added a new file defining the /image slash command, including argument parsing, validation, and mapping to the generate_image tool.
  • packages/core/src/config/config.ts
    • Imported GenerateImageTool and AuthType.
    • Added imageGeneration property to ConfigParameters and the Config class.
    • Implemented updateImageGenToolRegistration to dynamically register or unregister the GenerateImageTool based on the imageGeneration setting and current authentication type.
    • Registered the GenerateImageTool conditionally during tool registration if image generation is enabled and supported by the authentication method.
  • packages/core/src/index.ts
    • Exported the new generate-image.js module.
  • packages/core/src/tools/definitions/base-declarations.ts
    • Declared GENERATE_IMAGE_TOOL_NAME constant.
  • packages/core/src/tools/definitions/coreTools.ts
    • Exported GENERATE_IMAGE_TOOL_NAME.
  • packages/core/src/tools/generate-image.test.ts
    • Added a new test file for the GenerateImageTool, covering its build, description, execution, and helper functions like promptToFilename and getUniqueFilename.
  • packages/core/src/tools/generate-image.ts
    • Added a new file implementing the GenerateImageTool class, including image generation logic, API integration with @google/genai, file saving, parameter validation, and error handling.
  • packages/core/src/tools/tool-names.ts
    • Imported and re-exported GENERATE_IMAGE_TOOL_NAME.
    • Defined GENERATE_IMAGE_DISPLAY_NAME.
    • Included GENERATE_IMAGE_TOOL_NAME in ALL_BUILTIN_TOOL_NAMES.
  • schemas/settings.schema.json
    • Added the imageGeneration property to the experimental section of the settings JSON schema, including its title, description, and default value.
Activity
  • The pull request introduces a new feature, so there is no prior activity to report. The author has provided a detailed summary and validation steps.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a powerful new image generation feature through the GenerateImageTool and a corresponding /image slash command. The implementation is well-structured, with clear separation of concerns between the CLI command parsing and the core tool logic. The new tool includes robust validation, error handling, and support for various generation parameters.

I've identified two high-severity issues. One is related to incomplete validation of the count parameter, which could lead to unhelpful error messages. The other concerns the argument parser for the /image command, which can silently ignore flags, potentially causing user confusion. Addressing these will improve the reliability and user experience of this new feature.

Comment on lines +29 to +45
while (i < parts.length) {
const part = parts[i];
if (part.startsWith('--')) {
const flagName = part.slice(2).split('=')[0];
const inlineValue = part.includes('=') ? part.split('=')[1] : undefined;

if (inlineValue !== undefined) {
flags[flagName] = inlineValue;
} else if (flagName === 'return') {
flags[flagName] = true;
} else if (i + 1 < parts.length && !parts[i + 1].startsWith('--')) {
flags[flagName] = parts[i + 1];
i++;
}
}
i++;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The argument parser for the /image command can silently ignore flags if they are provided without a required value. For example, if a user runs /image a cat --ratio, the --ratio flag is ignored, and the command proceeds with the default aspect ratio without notifying the user that a value was expected. This can lead to confusing behavior.

I recommend refactoring the parser to be aware of which flags expect values (like --ratio) and which are booleans (like --return). This would allow it to return an error when a flag that requires a value is missing one. For example, you could add an else block to the flag parsing logic to handle cases where a value is expected but not found, and then return an error message to be displayed to the user.

Comment on lines +730 to +732
if (params.count < 1 || params.count > 4) {
return "The 'count' parameter must be between 1 and 4.";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The validation for the count parameter is incomplete. If a non-numeric string is passed for count from the /image command, parseInt will produce NaN. The current validation params.count < 1 || params.count > 4 evaluates to false for NaN, allowing the invalid value to pass. This leads to the tool failing silently without a helpful error message. Please add a check for NaN.

Suggested change
if (params.count < 1 || params.count > 4) {
return "The 'count' parameter must be between 1 and 4.";
}
if (Number.isNaN(params.count) || params.count < 1 || params.count > 4) {
return "The 'count' parameter must be a number between 1 and 4.";
}

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Mar 2, 2026
@victornpb
Copy link
Copy Markdown

sorry for for offtopic, but what screencap software did you use

@jackwotherspoon
Copy link
Copy Markdown
Collaborator Author

sorry for for offtopic, but what screencap software did you use

@victornpb totally okay to ask, it is Screen Studio 😎

@github-actions
Copy link
Copy Markdown

Size Change: +23.4 kB (+0.09%)

Total Size: 26.6 MB

Filename Size Change
./bundle/gemini.js 26.1 MB +23.4 kB (+0.09%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@helalsoft
Copy link
Copy Markdown

I WANT THIS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants