> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gourmand.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Use Gobi CLI (cn)

> Learn how to use Gobi's command-line interface for context engineering, automated coding tasks, and headless development workflows with customizable models, rules, and tools

<Warning>Gobi CLI (cn) is currently in Beta</Warning>

`cn` is an open-source, modular coding agent for the command line.

It provides a battle-tested agent loop so you can simply plug in your model, rules, and tools.

<img src="https://mintcdn.com/gourmand/cY6wRTl5s2wbpiM-/images/cn-demo.gif?s=ddde6a7d2225ae03a2c489daf29324ba" alt="cn" width="1588" height="1080" data-path="images/cn-demo.gif" />

## Quick start

<Info>
  Make sure you have [Node.js 18 or higher
  installed](https://nodejs.org/en/download/).
</Info>

```bash theme={null}
# Install
npm i -g @gourmanddev/cli

# Interactive mode
cn

# Headless mode
cn -p "Generate a conventional commit name for the current git changes"
```

## How to Use Gobi CLI - Basic Usage

Out of the box, `cn` comes with tools that let it understand your codebase, edit files, run terminal commands, and more (if you approve). You can ask `cn` to:

* Fix failing tests
* Find something in the codebase
* Execute a refactor
* Write a new feature
* And a lot more

Use '@' to give it file context, or '/' to run slash commands.

If you want to resume a previous conversation, run `cn --resume`.

## How to Use Headless Mode (`-p` flag)

In headless mode, `cn` will only output its final response, making it perfect for Unix Philosophy-style scripting and automation. For example, you could pipe your git diff into `cn` to generate a commit message, and write this to a file:

```bash theme={null}
echo "$(git diff) Generate a conventional commit name for the current git changes" | cn -p > commit-message.txt
```

## How to Configure Gobi CLI

`cn` uses [`config.yaml`](/reference), the exact same configuration file as Gobi. This means that you can log in to [Gobi Hub](/hub/introduction) or use your existing local configuration.

To switch between configurations, you can use the `/config` slash command in `cn`, or you can start it with the `--config` flag (e.g. `cn --config gourmand/default-agent` or `cn --config ~/.gobi/config.yaml`).

### How to Add Custom Models

Learn how to add custom models [here](/customize/overview). Then, you can use the `/model` slash command to switch between them in `cn`.

### How to Configure Rules

`cn` supports [rules](/customize/deep-dives/rules) in the same way as the Gobi IDE extensions. You can also use the `--rule` flag to manually include a rule from the hub. For example, `cn --rule nate/spanish` will tell `cn` to use [this rule](https://hub.gourmand.dev/nate/spanish) to always speak in Spanish.

### How to Configure Tools

`cn` supports MCP tools, which can be configured in the [same way](/customize/deep-dives/mcp) as with the Gobi IDE extensions.

#### How to Set Tool Permissions

`cn` includes a tool permission system to make sure you approve of the agent's actions. It will begin with minimal permissions but as you approve tool calls, it will add policies to `~/.gobi/permissions.yaml` to remember your preferences.

If you want to explicitly allow or deny tools for a single session, you can use the command line flags `--allow`, `--ask`, and `--exclude`. For example:

```bash theme={null}
# Always allow the Write tool
cn --allow Write()

# Always ask before running curl
cn --ask Bash(curl*)

# Never use the Fetch tool
cn --exclude Fetch
```

## API Key Authentication

For automation in CI or other headless environments, you can use an API key to authenticate with Gobi. First, obtain your personal API key [here](https://hub.gourmand.dev/settings/api-keys). Then, set it as the `GOBI_API_KEY` environment variable. You can now use `cn -p` (headless mode) without needing to log in.

If you wish to run an automation on behalf of your organization you can obtain an organization-scoped API key by going to [your organization's settings](https://hub.gourmand.dev/settings/organizations) -> API Keys.

## Troubleshooting

Run `cn` with the `--verbose` flag to see more detailed logs. These will be output to `~/.gobi/logs/cn.log`.

If you have feedback on the beta, please [share in our Discord](https://discord.com/invite/EfJEfdFnDQ) or [leave feedback in the GitHub discussion](https://github.com/gourmand/gobi/discussions/7307).
