How to Use Gemini CLI for Safer AI-Assisted Coding

How to Use Gemini CLI for Safer AI-Assisted Coding

Gemini CLI brings Google’s AI assistant into your terminal. It can explain code and edit files. It can also run tests and investigate project problems.

Install Gemini CLI

Gemini CLI runs through Node.js and npm. Its package metadata requires Node.js 20 or newer.

Install the stable package with:

npm install -g @google/gemini-cli

Start the tool by entering:

gemini

Google’s getting-started guide lists npm as the standard installation method. It also describes authentication through a Google account and other supported methods.

The stable release was version 0.68.0 on November 10, 2026. The project publishes stable, preview, and nightly channels. Stable is the recommended choice for most users.

Open a project session

Run Gemini CLI from the project directory. Start with a question that asks for inspection instead of edits.

gemini

Try a prompt such as:

Explain this project structure. Do not change any files.

This gives the agent a clear boundary. It can inspect the repository before proposing work.

Use the @ symbol when you want to provide a specific file. For example:

@src/app.ts Explain the request flow and identify possible error paths.

You can reference several files in one prompt. This helps when a feature spans multiple modules.

Gemini CLI also reads project instructions from GEMINI.md files. Put coding rules, test commands, and architecture notes in the file at your project root.

The tool loads more specific files as it moves through subdirectories. Use /memory show to inspect the context sent to the model. The official GEMINI.md guide explains this hierarchy.

Ask for controlled changes

Give the agent one small task at a time. State the files it may change. Also state the checks it should run.

Review the login form. Propose a fix for the validation bug. Change only files in src/auth. Explain the plan first.

Review the plan before allowing edits. Ask the agent to show the affected files after each change.

Gemini CLI asks for approval before shell commands by default. You can allow one command, trust a command for the session, or deny it.

Keep approval prompts enabled for unfamiliar repositories. Do not use automatic approval modes until you understand the project and its scripts.

After an edit, ask Gemini CLI to run focused tests. Then inspect the file changes yourself.

Show the files you changed. Explain each change. Run the smallest relevant test command.

The shell command guide documents approval prompts and related safety behavior.

Enable the project sandbox

Sandboxing isolates potentially dangerous operations from your main system. It can limit file access. It can also reduce the risk of damage.

Start a session with sandboxing enabled:

gemini --sandbox

Gemini CLI can use Docker, Podman, macOS Seatbelt, and other supported environments. Some commands may need extra permissions.

When that happens, the tool presents a sandbox expansion request. Read the requested access before approving it.

Sandboxing does not make generated code trustworthy. Review scripts, dependencies, network access, and file changes before accepting them.

The official sandbox documentation describes supported methods and permission requests.

Use a repeatable workflow

A useful Gemini CLI workflow has four stages. First, ask for analysis. Second, request a plan. Third, approve a narrow edit. Fourth, review tests and the final diff.

Keep secrets outside the project context. Do not place passwords, private keys, or production tokens in prompts or GEMINI.md.

Check ignore rules before sharing a repository. Gemini CLI respects Git ignore files during file discovery. You can also control file filtering in its settings.

Gemini CLI works best as a fast project assistant. It can reduce repetitive work. You remain responsible for the code and commands it produces.

References

Google. (2026, November 10). Latest stable release: v0.68.0. GitHub. https://github.com/google-gemini/gemini-cli/blob/main/docs/changelogs/latest.md

Google. (n.d.). Get started with Gemini CLI. GitHub. Retrieved November 24, 2026, from https://github.com/google-gemini/gemini-cli/blob/main/docs/get-started/index.md

Google. (n.d.). Gemini CLI package metadata. GitHub. Retrieved November 24, 2026, from https://github.com/google-gemini/gemini-cli/blob/main/package.json

Google. (n.d.). Provide context with GEMINI.md files. GitHub. Retrieved November 24, 2026, from https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/gemini-md.md

Google. (n.d.). Shell commands with Gemini CLI. GitHub. Retrieved November 24, 2026, from https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/tutorials/shell-commands.md

Google. (n.d.). Sandboxing in Gemini CLI. GitHub. Retrieved November 24, 2026, from https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/sandbox.md