If you are still only using AI as a chatbot in your web browser, you are officially missing out.
The Gemini CLI is Google's terminal-based AI assistant. Compared to the web version, command-line tools have a natural advantage in handling local files and reading project context. For developers, it is not merely a chatbot, but a terminal "copilot" that can directly read code, execute scripts, and generate results.
Below is a compilation of practical tips for deep-diving into the Gemini CLI, covering core features like custom instructions, terminal interaction, and safe rollbacks.
Installing the Gemini CLI
The Gemini CLI depends on a runtime environment. To keep your system clean and achieve multi-version coexistence, we need a solid setup.
1. Configure the Node.js Environment
Use ServBay to configure your environment. ServBay supports full version coverage from Node.js 12 to 24, and different versions do not conflict with each other, making it perfect for isolating development environments.
Open the ServBay service management panel and find the language runtime settings:
- Select "Packages" in the left sidebar and choose Node.js.
- Click the green button to download (Gemini CLI requires a Node.js environment of version 20+).
Verify if the environment is ready in your terminal:
node -v
2. Install Gemini CLI
Once the environment is ready, execute the installation command directly in the terminal:
npm install -g @google/gemini-cli
After installation is complete, simply type gemini in the terminal to launch the interactive interface.
Practical Guide to Gemini CLI
GEMINI.md: The "Factory Settings" for Your Project
Create a file named GEMINI.md in your project's root directory. This acts as an instruction manual. Whenever the Gemini CLI starts in this directory, it will automatically read this file.
This solves the problem of "having to repeat the project rules to the AI every time you start a new session." It is recommended to define your tech stack, coding standards, and common scripts in this file.
Example GEMINI.md content:
# Project Context Configuration
## Core Tech Stack
- Framework: Next.js (App Router)
- Styling: Tailwind CSS
- State Management: Zustand
## Development Standards
- Components: Prefer functional components; must include TypeScript interface definitions.
- Paths: Use aliases like `@/components` to avoid relative paths like `../../`.
- Commits: Commit messages must follow the Conventional Commits specification.
## Common Command Cheat Sheet
- Start Dev Environment: `npm run dev`
- Type Check: `npm run type-check`
- Production Build: `npm run build`
With this file in place, you simply need to issue a command like "Help me write a user card component," and Gemini will automatically follow the Next.js + Tailwind CSS + TypeScript specifications without needing extra prompts.
Terminal Mode: Work Without Leaving the Conversation
A great feature of the Gemini CLI is its built-in terminal command mode. Developers don't need to switch windows back and forth between the AI dialog and the system terminal.
In the chat input box, type ! to switch to command execution mode.
- Scenario: The AI just finished modifying code, and you want to run a test immediately or check if the file was generated.
-
Action: Directly input
!npm run testor!ls -la.
The benefit of this design is that all operations are completed within the same window flow, keeping your train of thought uninterrupted.
Custom Commands (.toml): Automating Repetitive Tasks
Gemini CLI allows you to define shortcut commands (Slash Commands) using .toml files. You can place these files in the user directory ~/.gemini/commands/ for global use or in the project root .gemini/commands/ for project-specific use.
This is like setting up macros for the AI, turning complex prompts into simple /commands.
Example: One-Click Weekly Report Generation
Create .gemini/commands/report.toml in your project:
# File: .gemini/commands/report.toml
# Usage: /report
description = "Automatically summarize this week's work"
# This is a preset prompt template
prompt = """
Please read the git commit records from the last 7 days and check the recently modified files in the `src/` directory.
Help me generate a weekly report containing the following three points:
1. **Core Progress**: What major features were completed this week.
2. **Problem Solving**: What key Bugs were fixed.
3. **Next Week's Plan**: Based on TODO comments in the code, suggest what to do next week.
Keep the output format concise and clear.
"""
From now on, every Friday, you just need to type /report in the terminal, and the AI will automatically look through the records and write the weekly report for you. No more nagging from management!
Advanced: Dynamic Parameters & Command Embedding
This is arguably the most powerful feature of the Gemini CLI: embedding terminal commands inside custom instructions. This lets the CLI execute a system command first, get the result, and then feed it to the AI.
Command Embedding !{...}
Using the !{command} syntax, you can insert the output of a terminal command directly into your prompt.
Real-world Use Case: Intelligent Commit Message Generation
We can create a command that makes the AI write Git commit messages for us.
# File: .gemini/commands/git/commit.toml
# Usage: /git:commit
description = "Analyze the staging area and generate a Commit Message"
prompt = """
You are a code specification expert. Please look at the output of `git diff --cached` below (which is my staged code changes) and help me write a Git Commit Message.
Requirements:
1. Format must follow the Conventional Commits specification (e.g., feat: xxx, fix: xxx).
2. The first line should be a short summary, followed by a list of specific changes.
Changes are as follows:
!{git diff --cached}
"""
When you type /git:commit:
- The CLI silently executes
git diff --cachedin the background. - It retrieves the text of the code differences.
- It stuffs that text into the
!{...}position. - It sends the whole thing to Gemini.
The resulting commit message is both accurate and effortless.
Safe Rollback: The Checkpoint Mechanism
Letting AI modify files directly can occasionally go wrong. Gemini CLI provides a Checkpoint mechanism—essentially a save file for your code.
How to use it:
After enabling Checkpoint in your settings.json, whenever the AI prepares to modify a file (e.g., writing code), the CLI automatically creates a temporary Git snapshot in the background. This does not affect your original Git history.
Using /restore to undo:
If the AI breaks the code:
- Type
/restoreto view the list of save points. - Type
/restore <ID>to roll back.
This not only reverts the files to their original state but also rewinds the conversation history to the state before the modification, allowing you to adjust your instructions and let the AI try again.
Multi-Directory Collaboration
If your project structure is complex (e.g., separating frontend and backend), Gemini CLI supports mounting multiple directories simultaneously.
/directory add packages/backend,packages/frontend
After adding them, you can reference files in different directories directly using the @ symbol:
"Please compare the interface definition in
@packages/backend/api.tsand update the types in@packages/frontend/api-client.ts."
This breaks down directory limitations, giving the AI a global view and allowing you to command it more effectively.
Summary
The Gemini CLI extends AI capabilities from a chat bot to the level of actual execution.
By using ServBay to quickly build a stable Node.js environment, utilizing GEMINI.md to solidify project consensus, and combining .toml custom instructions with terminal injection to connect your local toolchain, developers can build a highly customized auxiliary workflow. Added to the safety net provided by the Checkpoint rollback mechanism, allowing AI to intervene in complex code modifications becomes much more controllable.
Master these skills, and you will no longer be simply asking AI for code snippets, but transforming it into a local development collaborator that understands project context, automatically executes tasks, and is always reversible.
Sounds pretty cool, right? Go give it a try!




Top comments (0)