README.md

  1# Crush
  2
  3<p align="center">
  4    <a href="https://stuff.charm.sh/crush/charm-crush.png"><img width="450" alt="Charm Crush Logo" src="https://github.com/user-attachments/assets/cf8ca3ce-8b02-43f0-9d0f-5a331488da4b" /></a><br />
  5    <a href="https://github.com/charmbracelet/crush/releases"><img src="https://img.shields.io/github/release/charmbracelet/crush" alt="Latest Release"></a>
  6    <a href="https://github.com/charmbracelet/crush/actions"><img src="https://github.com/charmbracelet/crush/actions/workflows/build.yml/badge.svg" alt="Build Status"></a>
  7</p>
  8
  9<p align="center">Your new coding bestie, now available in your favourite terminal.<br />Your tools, your code, and your workflows, wired into your LLM of choice.</p>
 10<p align="center">终端里的编程新搭档,<br />无缝接入你的工具、代码与工作流,全面兼容主流 LLM 模型。</p>
 11
 12<p align="center"><img width="800" alt="Crush Demo" src="https://github.com/user-attachments/assets/58280caf-851b-470a-b6f7-d5c4ea8a1968" /></p>
 13
 14## Features
 15
 16- **Multi-Model:** choose from a wide range of LLMs or add your own via OpenAI- or Anthropic-compatible APIs
 17- **Flexible:** switch LLMs mid-session while preserving context
 18- **Session-Based:** maintain multiple work sessions and contexts per project
 19- **LSP-Enhanced:** Crush uses LSPs for additional context, just like you do
 20- **Extensible:** add capabilities via MCPs (`http`, `stdio`, and `sse`)
 21- **Works Everywhere:** first-class support in every terminal on macOS, Linux, Windows (PowerShell and WSL), Android, FreeBSD, OpenBSD, and NetBSD
 22- **Industrial Grade:** built on the Charm ecosystem, powering 25k+ applications, from leading open source projects to business-critical infrastructure
 23
 24## Installation
 25
 26Use a package manager:
 27
 28```bash
 29# Homebrew
 30brew install charmbracelet/tap/crush
 31
 32# NPM
 33npm install -g @charmland/crush
 34
 35# Arch Linux (btw)
 36yay -S crush-bin
 37
 38# Nix
 39nix run github:numtide/nix-ai-tools#crush
 40
 41# FreeBSD
 42pkg install crush
 43```
 44
 45Windows users:
 46
 47```bash
 48# Winget
 49winget install charmbracelet.crush
 50
 51# Scoop
 52scoop bucket add charm https://github.com/charmbracelet/scoop-bucket.git
 53scoop install crush
 54```
 55
 56<details>
 57<summary><strong>Nix (NUR)</strong></summary>
 58
 59Crush is available via the official Charm [NUR](https://github.com/nix-community/NUR) in `nur.repos.charmbracelet.crush`, which is the most up-to-date way to get Crush in Nix.
 60
 61You can also try out Crush via the NUR with `nix-shell`:
 62
 63```bash
 64# Add the NUR channel.
 65nix-channel --add https://github.com/nix-community/NUR/archive/main.tar.gz nur
 66nix-channel --update
 67
 68# Get Crush in a Nix shell.
 69nix-shell -p '(import <nur> { pkgs = import <nixpkgs> {}; }).repos.charmbracelet.crush'
 70```
 71
 72### NixOS & Home Manager Module Usage via NUR
 73
 74Crush provides NixOS and Home Manager modules via NUR.
 75You can use these modules directly in your flake by importing them from NUR. Since it auto detects whether its a home manager or nixos context you can use the import the exact same way :)
 76
 77```nix
 78{
 79  inputs = {
 80    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
 81    nur.url = "github:nix-community/NUR";
 82  };
 83
 84  outputs = { self, nixpkgs, nur, ... }: {
 85    nixosConfigurations.your-hostname = nixpkgs.lib.nixosSystem {
 86      system = "x86_64-linux";
 87      modules = [
 88        nur.modules.nixos.default
 89        nur.repos.charmbracelet.modules.crush
 90        {
 91          programs.crush = {
 92            enable = true;
 93            settings = {
 94              providers = {
 95                openai = {
 96                  id = "openai";
 97                  name = "OpenAI";
 98                  base_url = "https://api.openai.com/v1";
 99                  type = "openai";
100                  api_key = "sk-fake123456789abcdef...";
101                  models = [
102                    {
103                      id = "gpt-4";
104                      name = "GPT-4";
105                    }
106                  ];
107                };
108              };
109              lsp = {
110                go = { command = "gopls"; enabled = true; };
111                nix = { command = "nil"; enabled = true; };
112              };
113              options = {
114                context_paths = [ "/etc/nixos/configuration.nix" ];
115                tui = { compact_mode = true; };
116                debug = false;
117              };
118            };
119          };
120        }
121      ];
122    };
123  };
124}
125```
126
127</details>
128
129<details>
130<summary><strong>Debian/Ubuntu</strong></summary>
131
132```bash
133sudo mkdir -p /etc/apt/keyrings
134curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
135echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
136sudo apt update && sudo apt install crush
137```
138
139</details>
140
141<details>
142<summary><strong>Fedora/RHEL</strong></summary>
143
144```bash
145echo '[charm]
146name=Charm
147baseurl=https://repo.charm.sh/yum/
148enabled=1
149gpgcheck=1
150gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
151sudo yum install crush
152```
153
154</details>
155
156Or, download it:
157
158- [Packages][releases] are available in Debian and RPM formats
159- [Binaries][releases] are available for Linux, macOS, Windows, FreeBSD, OpenBSD, and NetBSD
160
161[releases]: https://github.com/charmbracelet/crush/releases
162
163Or just install it with Go:
164
165```
166go install github.com/charmbracelet/crush@latest
167```
168
169> [!WARNING]
170> Productivity may increase when using Crush and you may find yourself nerd
171> sniped when first using the application. If the symptoms persist, join the
172> [Discord][discord] and nerd snipe the rest of us.
173
174## Getting Started
175
176The quickest way to get started is to grab an API key for your preferred
177provider such as Anthropic, OpenAI, Groq, OpenRouter, or Vercel AI Gateway and just start
178Crush. You'll be prompted to enter your API key.
179
180That said, you can also set environment variables for preferred providers.
181
182| Environment Variable        | Provider                                           |
183| --------------------------- | -------------------------------------------------- |
184| `ANTHROPIC_API_KEY`         | Anthropic                                          |
185| `OPENAI_API_KEY`            | OpenAI                                             |
186| `VERCEL_API_KEY`            | Vercel AI Gateway                                  |
187| `GEMINI_API_KEY`            | Google Gemini                                      |
188| `SYNTHETIC_API_KEY`         | Synthetic                                          |
189| `ZAI_API_KEY`               | Z.ai                                               |
190| `MINIMAX_API_KEY`           | MiniMax                                            |
191| `HF_TOKEN`                  | Hugging Face Inference                             |
192| `CEREBRAS_API_KEY`          | Cerebras                                           |
193| `OPENROUTER_API_KEY`        | OpenRouter                                         |
194| `GROQ_API_KEY`              | Groq                                               |
195| `VERTEXAI_PROJECT`          | Google Cloud VertexAI (Gemini)                     |
196| `VERTEXAI_LOCATION`         | Google Cloud VertexAI (Gemini)                     |
197| `AWS_ACCESS_KEY_ID`         | Amazon Bedrock (Claude)                            |
198| `AWS_SECRET_ACCESS_KEY`     | Amazon Bedrock (Claude)                            |
199| `AWS_REGION`                | Amazon Bedrock (Claude)                            |
200| `AWS_PROFILE`               | Amazon Bedrock (Custom Profile)                    |
201| `AWS_BEARER_TOKEN_BEDROCK`  | Amazon Bedrock                                     |
202| `AZURE_OPENAI_API_ENDPOINT` | Azure OpenAI models                                |
203| `AZURE_OPENAI_API_KEY`      | Azure OpenAI models (optional when using Entra ID) |
204| `AZURE_OPENAI_API_VERSION`  | Azure OpenAI models                                |
205
206### By the Way
207
208Is there a provider you’d like to see in Crush? Is there an existing model that needs an update?
209
210Crush’s default model listing is managed in [Catwalk](https://github.com/charmbracelet/catwalk), a community-supported, open source repository of Crush-compatible models, and you’re welcome to contribute.
211
212<a href="https://github.com/charmbracelet/catwalk"><img width="174" height="174" alt="Catwalk Badge" src="https://github.com/user-attachments/assets/95b49515-fe82-4409-b10d-5beb0873787d" /></a>
213
214## Configuration
215
216Crush runs great with no configuration. That said, if you do need or want to
217customize Crush, configuration can be added either local to the project itself,
218or globally, with the following priority:
219
2201. `.crush.json`
2212. `crush.json`
2223. `$HOME/.config/crush/crush.json`
223
224Configuration itself is stored as a JSON object:
225
226```json
227{
228  "this-setting": { "this": "that" },
229  "that-setting": ["ceci", "cela"]
230}
231```
232
233As an additional note, Crush also stores ephemeral data, such as application state, in one additional location:
234
235```bash
236# Unix
237$HOME/.local/share/crush/crush.json
238
239# Windows
240%LOCALAPPDATA%\crush\crush.json
241```
242
243> [!TIP]
244> You can override the user and data config locations by setting:
245> * `CRUSH_GLOBAL_CONFIG`
246> * `CRUSH_GLOBAL_DATA`
247
248### LSPs
249
250Crush can use LSPs for additional context to help inform its decisions, just
251like you would. LSPs can be added manually like so:
252
253```json
254{
255  "$schema": "https://charm.land/crush.json",
256  "lsp": {
257    "go": {
258      "command": "gopls",
259      "env": {
260        "GOTOOLCHAIN": "go1.24.5"
261      }
262    },
263    "typescript": {
264      "command": "typescript-language-server",
265      "args": ["--stdio"]
266    },
267    "nix": {
268      "command": "nil"
269    }
270  }
271}
272```
273
274### MCPs
275
276Crush also supports Model Context Protocol (MCP) servers through three
277transport types: `stdio` for command-line servers, `http` for HTTP endpoints,
278and `sse` for Server-Sent Events. Environment variable expansion is supported
279using `$(echo $VAR)` syntax.
280
281```json
282{
283  "$schema": "https://charm.land/crush.json",
284  "mcp": {
285    "filesystem": {
286      "type": "stdio",
287      "command": "node",
288      "args": ["/path/to/mcp-server.js"],
289      "timeout": 120,
290      "disabled": false,
291      "disabled_tools": ["some-tool-name"],
292      "env": {
293        "NODE_ENV": "production"
294      }
295    },
296    "github": {
297      "type": "http",
298      "url": "https://api.githubcopilot.com/mcp/",
299      "timeout": 120,
300      "disabled": false,
301      "disabled_tools": ["create_issue", "create_pull_request"],
302      "headers": {
303        "Authorization": "Bearer $GH_PAT"
304      }
305    },
306    "streaming-service": {
307      "type": "sse",
308      "url": "https://example.com/mcp/sse",
309      "timeout": 120,
310      "disabled": false,
311      "headers": {
312        "API-Key": "$(echo $API_KEY)"
313      }
314    }
315  }
316}
317```
318
319### Ignoring Files
320
321Crush respects `.gitignore` files by default, but you can also create a
322`.crushignore` file to specify additional files and directories that Crush
323should ignore. This is useful for excluding files that you want in version
324control but don't want Crush to consider when providing context.
325
326The `.crushignore` file uses the same syntax as `.gitignore` and can be placed
327in the root of your project or in subdirectories.
328
329### Allowing Tools
330
331By default, Crush will ask you for permission before running tool calls. If
332you'd like, you can allow tools to be executed without prompting you for
333permissions. Use this with care.
334
335```json
336{
337  "$schema": "https://charm.land/crush.json",
338  "permissions": {
339    "allowed_tools": [
340      "view",
341      "ls",
342      "grep",
343      "edit",
344      "mcp_context7_get-library-doc"
345    ]
346  }
347}
348```
349
350You can also skip all permission prompts entirely by running Crush with the
351`--yolo` flag. Be very, very careful with this feature.
352
353### Disabling Built-In Tools
354
355If you'd like to prevent Crush from using certain built-in tools entirely, you
356can disable them via the `options.disabled_tools` list. Disabled tools are
357completely hidden from the agent.
358
359```json
360{
361  "$schema": "https://charm.land/crush.json",
362  "options": {
363    "disabled_tools": [
364      "bash",
365      "sourcegraph"
366    ]
367  }
368}
369```
370
371To disable tools from MCP servers, see the [MCP config section](#mcps).
372
373### Agent Skills
374
375Crush supports the [Agent Skills](https://agentskills.io) open standard for
376extending agent capabilities with reusable skill packages. Skills are folders
377containing a `SKILL.md` file with instructions that Crush can discover and
378activate on demand.
379
380Skills are discovered from:
381
382- `~/.config/crush/skills/` on Unix (default, can be overridden with `CRUSH_SKILLS_DIR`)
383- `%LOCALAPPDATA%\crush\skills\` on Windows (default, can be overridden with `CRUSH_SKILLS_DIR`)
384- Additional paths configured via `options.skills_paths`
385
386```jsonc
387{
388  "$schema": "https://charm.land/crush.json",
389  "options": {
390    "skills_paths": [
391      "~/.config/crush/skills", // Windows: "%LOCALAPPDATA%\\crush\\skills",
392      "./project-skills"
393    ]
394  }
395}
396```
397
398You can get started with example skills from [anthropics/skills](https://github.com/anthropics/skills):
399
400```bash
401# Unix
402mkdir -p ~/.config/crush/skills
403cd ~/.config/crush/skills
404git clone https://github.com/anthropics/skills.git _temp
405mv _temp/skills/* . && rm -rf _temp
406```
407
408```powershell
409# Windows (PowerShell)
410mkdir -Force "$env:LOCALAPPDATA\crush\skills"
411cd "$env:LOCALAPPDATA\crush\skills"
412git clone https://github.com/anthropics/skills.git _temp
413mv _temp/skills/* . ; rm -r -force _temp
414```
415
416### Initialization
417
418When you initialize a project, Crush analyzes your codebase and creates
419a context file that helps it work more effectively in future sessions.
420By default, this file is named `AGENTS.md`, but you can customize the
421name and location with the `initialize_as` option:
422
423```json
424{
425  "$schema": "https://charm.land/crush.json",
426  "options": {
427    "initialize_as": "AGENTS.md"
428  }
429}
430```
431
432This is useful if you prefer a different naming convention or want to
433place the file in a specific directory (e.g., `CRUSH.md` or
434`docs/LLMs.md`). Crush will fill the file with project-specific context
435like build commands, code patterns, and conventions it discovered during
436initialization.
437
438### Attribution Settings
439
440By default, Crush adds attribution information to Git commits and pull requests
441it creates. You can customize this behavior with the `attribution` option:
442
443```json
444{
445  "$schema": "https://charm.land/crush.json",
446  "options": {
447    "attribution": {
448      "trailer_style": "co-authored-by",
449      "generated_with": true
450    }
451  }
452}
453```
454
455- `trailer_style`: Controls the attribution trailer added to commit messages
456  (default: `assisted-by`)
457	- `assisted-by`: Adds `Assisted-by: [Model Name] via Crush <crush@charm.land>`
458	  (includes the model name)
459	- `co-authored-by`: Adds `Co-Authored-By: Crush <crush@charm.land>`
460	- `none`: No attribution trailer
461- `generated_with`: When true (default), adds `💘 Generated with Crush` line to
462  commit messages and PR descriptions
463
464### Custom Providers
465
466Crush supports custom provider configurations for both OpenAI-compatible and
467Anthropic-compatible APIs.
468
469> [!NOTE]
470> Note that we support two "types" for OpenAI. Make sure to choose the right one
471> to ensure the best experience!
472> * `openai` should be used when proxying or routing requests through OpenAI.
473> * `openai-compat` should be used when using non-OpenAI providers that have OpenAI-compatible APIs.
474
475#### OpenAI-Compatible APIs
476
477Here’s an example configuration for Deepseek, which uses an OpenAI-compatible
478API. Don't forget to set `DEEPSEEK_API_KEY` in your environment.
479
480```json
481{
482  "$schema": "https://charm.land/crush.json",
483  "providers": {
484    "deepseek": {
485      "type": "openai-compat",
486      "base_url": "https://api.deepseek.com/v1",
487      "api_key": "$DEEPSEEK_API_KEY",
488      "models": [
489        {
490          "id": "deepseek-chat",
491          "name": "Deepseek V3",
492          "cost_per_1m_in": 0.27,
493          "cost_per_1m_out": 1.1,
494          "cost_per_1m_in_cached": 0.07,
495          "cost_per_1m_out_cached": 1.1,
496          "context_window": 64000,
497          "default_max_tokens": 5000
498        }
499      ]
500    }
501  }
502}
503```
504
505#### Anthropic-Compatible APIs
506
507Custom Anthropic-compatible providers follow this format:
508
509```json
510{
511  "$schema": "https://charm.land/crush.json",
512  "providers": {
513    "custom-anthropic": {
514      "type": "anthropic",
515      "base_url": "https://api.anthropic.com/v1",
516      "api_key": "$ANTHROPIC_API_KEY",
517      "extra_headers": {
518        "anthropic-version": "2023-06-01"
519      },
520      "models": [
521        {
522          "id": "claude-sonnet-4-20250514",
523          "name": "Claude Sonnet 4",
524          "cost_per_1m_in": 3,
525          "cost_per_1m_out": 15,
526          "cost_per_1m_in_cached": 3.75,
527          "cost_per_1m_out_cached": 0.3,
528          "context_window": 200000,
529          "default_max_tokens": 50000,
530          "can_reason": true,
531          "supports_attachments": true
532        }
533      ]
534    }
535  }
536}
537```
538
539### Amazon Bedrock
540
541Crush currently supports running Anthropic models through Bedrock, with caching disabled.
542
543- A Bedrock provider will appear once you have AWS configured, i.e. `aws configure`
544- Crush also expects the `AWS_REGION` or `AWS_DEFAULT_REGION` to be set
545- To use a specific AWS profile set `AWS_PROFILE` in your environment, i.e. `AWS_PROFILE=myprofile crush`
546- Alternatively to `aws configure`, you can also just set `AWS_BEARER_TOKEN_BEDROCK`
547
548### Vertex AI Platform
549
550Vertex AI will appear in the list of available providers when `VERTEXAI_PROJECT` and `VERTEXAI_LOCATION` are set. You will also need to be authenticated:
551
552```bash
553gcloud auth application-default login
554```
555
556To add specific models to the configuration, configure as such:
557
558```json
559{
560  "$schema": "https://charm.land/crush.json",
561  "providers": {
562    "vertexai": {
563      "models": [
564        {
565          "id": "claude-sonnet-4@20250514",
566          "name": "VertexAI Sonnet 4",
567          "cost_per_1m_in": 3,
568          "cost_per_1m_out": 15,
569          "cost_per_1m_in_cached": 3.75,
570          "cost_per_1m_out_cached": 0.3,
571          "context_window": 200000,
572          "default_max_tokens": 50000,
573          "can_reason": true,
574          "supports_attachments": true
575        }
576      ]
577    }
578  }
579}
580```
581
582### Local Models
583
584Local models can also be configured via OpenAI-compatible API. Here are two common examples:
585
586#### Ollama
587
588```json
589{
590  "providers": {
591    "ollama": {
592      "name": "Ollama",
593      "base_url": "http://localhost:11434/v1/",
594      "type": "openai-compat",
595      "models": [
596        {
597          "name": "Qwen 3 30B",
598          "id": "qwen3:30b",
599          "context_window": 256000,
600          "default_max_tokens": 20000
601        }
602      ]
603    }
604  }
605}
606```
607
608#### LM Studio
609
610```json
611{
612  "providers": {
613    "lmstudio": {
614      "name": "LM Studio",
615      "base_url": "http://localhost:1234/v1/",
616      "type": "openai-compat",
617      "models": [
618        {
619          "name": "Qwen 3 30B",
620          "id": "qwen/qwen3-30b-a3b-2507",
621          "context_window": 256000,
622          "default_max_tokens": 20000
623        }
624      ]
625    }
626  }
627}
628```
629
630## Logging
631
632Sometimes you need to look at logs. Luckily, Crush logs all sorts of
633stuff. Logs are stored in `./.crush/logs/crush.log` relative to the project.
634
635The CLI also contains some helper commands to make perusing recent logs easier:
636
637```bash
638# Print the last 1000 lines
639crush logs
640
641# Print the last 500 lines
642crush logs --tail 500
643
644# Follow logs in real time
645crush logs --follow
646```
647
648Want more logging? Run `crush` with the `--debug` flag, or enable it in the
649config:
650
651```json
652{
653  "$schema": "https://charm.land/crush.json",
654  "options": {
655    "debug": true,
656    "debug_lsp": true
657  }
658}
659```
660
661## Provider Auto-Updates
662
663By default, Crush automatically checks for the latest and greatest list of
664providers and models from [Catwalk](https://github.com/charmbracelet/catwalk),
665the open source Crush provider database. This means that when new providers and
666models are available, or when model metadata changes, Crush automatically
667updates your local configuration.
668
669### Disabling automatic provider updates
670
671For those with restricted internet access, or those who prefer to work in
672air-gapped environments, this might not be want you want, and this feature can
673be disabled.
674
675To disable automatic provider updates, set `disable_provider_auto_update` into
676your `crush.json` config:
677
678```json
679{
680  "$schema": "https://charm.land/crush.json",
681  "options": {
682    "disable_provider_auto_update": true
683  }
684}
685```
686
687Or set the `CRUSH_DISABLE_PROVIDER_AUTO_UPDATE` environment variable:
688
689```bash
690export CRUSH_DISABLE_PROVIDER_AUTO_UPDATE=1
691```
692
693### Manually updating providers
694
695Manually updating providers is possible with the `crush update-providers`
696command:
697
698```bash
699# Update providers remotely from Catwalk.
700crush update-providers
701
702# Update providers from a custom Catwalk base URL.
703crush update-providers https://example.com/
704
705# Update providers from a local file.
706crush update-providers /path/to/local-providers.json
707
708# Reset providers to the embedded version, embedded at crush at build time.
709crush update-providers embedded
710
711# For more info:
712crush update-providers --help
713```
714
715## Metrics
716
717Crush records pseudonymous usage metrics (tied to a device-specific hash),
718which maintainers rely on to inform development and support priorities. The
719metrics include solely usage metadata; prompts and responses are NEVER
720collected.
721
722Details on exactly what’s collected are in the source code ([here](https://github.com/charmbracelet/crush/tree/main/internal/event)
723and [here](https://github.com/charmbracelet/crush/blob/main/internal/llm/agent/event.go)).
724
725You can opt out of metrics collection at any time by setting the environment
726variable by setting the following in your environment:
727
728```bash
729export CRUSH_DISABLE_METRICS=1
730```
731
732Or by setting the following in your config:
733
734```json
735{
736  "options": {
737    "disable_metrics": true
738  }
739}
740```
741
742Crush also respects the `DO_NOT_TRACK` convention which can be enabled via
743`export DO_NOT_TRACK=1`.
744
745## Contributing
746
747See the [contributing guide](https://github.com/charmbracelet/crush?tab=contributing-ov-file#contributing).
748
749## Whatcha think?
750
751We’d love to hear your thoughts on this project. Need help? We gotchu. You can find us on:
752
753- [Twitter](https://twitter.com/charmcli)
754- [Slack](https://charm.land/slack)
755- [Discord][discord]
756- [The Fediverse](https://mastodon.social/@charmcli)
757- [Bluesky](https://bsky.app/profile/charm.land)
758
759[discord]: https://charm.land/discord
760
761## License
762
763[FSL-1.1-MIT](https://github.com/charmbracelet/crush/raw/main/LICENSE.md)
764
765---
766
767Part of [Charm](https://charm.land).
768
769<a href="https://charm.land/"><img alt="The Charm logo" width="400" src="https://stuff.charm.sh/charm-banner-next.jpg" /></a>
770
771<!--prettier-ignore-->
772Charm热爱开源 • Charm loves open source