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

Define prompt templates and reuse them

Open rksh1997 opened this issue 1 year ago • 6 comments

What would you like to be added?

I want to be able to define prompt template files (with placeholders) and be able to submit the prompt multiple times without having to re-write it.

Why is this needed?

For repetitive tasks like making a CRUD apis for multiple resources I can write a CRUD once then create a template prompt with example code and rules and reuse it again for all of the other resources.

Additional context

inside the .gemini/prompts folder we create a prompt file nest-crud.yaml which will look like this:

id: nest-crud
name: Generate a Nestjs CRUD api
variables:
  - name: resource
    description: Name of the resource (e.g Product, User)
template: |
  Referencing @samples/sample.module.ts and @samples/sample.controller.ts and @samples/sample.service.ts, create a CRUD API for {{resource}} using NestJS. Ensure to define the necessary modules, controllers, and services to handle the CRUD operations effectively.
  Ensure that the API follows NestJS best practices, including proper use of decorators, dependency injection, and error handling. Additionally, implement validation for incoming requests using class-validator and class-transformer packages to ensure data integrity and security.

Then in gemini cli I can select this predefined prompt and only fill the resource placeholder.

rksh1997 avatar Jul 03 '25 10:07 rksh1997

Note: I needed this feature for my use case, so I’ve gone ahead and implemented it.

I’d love to get your feedback and, if it aligns with the goals of the Gemini CLI, I’m happy to make any adjustments needed to get this merged into the main CLI.

You can check out a demo here:

https://github.com/user-attachments/assets/594094d1-97eb-4fac-b260-e1ebf6ca27ff

rksh1997 avatar Jul 03 '25 10:07 rksh1997

This is neat! Can't promise if we are at a place to take a PR for this, but if not a lot of effort, would be cool to take a look at it.

keithballinger avatar Jul 03 '25 10:07 keithballinger

@keithballinger should I open a pr or wait for approval?

rksh1997 avatar Jul 03 '25 10:07 rksh1997

That's a great idea!

devpool007 avatar Jul 04 '25 08:07 devpool007

Found possible duplicate issues:

  • #5023: (0.9083571434020996)

gsquared94 avatar Jul 30 '25 17:07 gsquared94

You can now use custom slash commands https://cloud.google.com/blog/topics/developers-practitioners/gemini-cli-custom-slash-commands

SandyTao520 avatar Aug 22 '25 19:08 SandyTao520