README.md

  1> [!WARNING]
  2> 🚧 This is a pre-release under heavy, active development. Things are still in flux but we’re excited to share early progress.
  3
  4# Crush
  5
  6<p>
  7    <img width="450" alt="Charm Crush Art" src="https://github.com/user-attachments/assets/9ab4c30c-9327-46b6-a722-3ad0e20f6976" /><br>
  8    <a href="https://github.com/charmbracelet/crush/releases"><img src="https://img.shields.io/github/release/charmbracelet/crush" alt="Latest Release"></a>
  9    <a href="https://github.com/charmbracelet/crush/actions"><img src="https://github.com/charmbracelet/crush/workflows/build/badge.svg" alt="Build Status"></a>
 10</p>
 11
 12Crush is a tool for building software with AI.
 13
 14## Installation
 15
 16Crush has first class support for macOS, Linux, and Windows.
 17
 18Nightly builds are available while Crush is in development.
 19
 20- [Packages](https://github.com/charmbracelet/crush/releases/tag/nightly) are available in Debian, RPM, APK, and PKG formats
 21- [Binaries](https://github.com/charmbracelet/crush/releases/tag/nightly) are available for Linux, macOS and Windows
 22
 23You can also just install it with go:
 24
 25```
 26git clone git@github.com:charmbracelet/crush.git
 27cd crush
 28go install
 29```
 30
 31<details>
 32<summary>Not a developer? Here’s a quick how-to.</summary>
 33
 34Download the latest [nightly release](https://github.com/charmbracelet/crush/releases) for your system. The [macOS ARM64 one](https://github.com/charmbracelet/crush/releases/download/nightly/crush_0.1.0-nightly_Darwin_arm64.tar.gz) is most likely what you want.
 35
 36Next, open a terminal and run the following commands:
 37
 38```bash
 39cd ~/Downloads
 40tar -xvzf crush_0.1.0-nightly_Darwin_arm64.tar.gz -C crush
 41sudo mv ./crush/crush /usr/local/bin/crush
 42rm -rf ./crush
 43```
 44
 45Then, run Crush by typing `crush`.
 46
 47---
 48
 49</details>
 50
 51## Getting Started
 52
 53The quickest way to get started to grab an API key for your preferred
 54provider such as Anthropic, OpenAI, or Groq, and just start Crush. You'll be
 55prompted to enter your API key.
 56
 57That said, you can also set environment variables for preferred providers:
 58
 59| Environment Variable       | Provider                                           |
 60| -------------------------- | -------------------------------------------------- |
 61| `ANTHROPIC_API_KEY`        | Anthropic                                          |
 62| `OPENAI_API_KEY`           | OpenAI                                             |
 63| `GEMINI_API_KEY`           | Google Gemini                                      |
 64| `VERTEXAI_PROJECT`         | Google Cloud VertexAI (Gemini)                     |
 65| `VERTEXAI_LOCATION`        | Google Cloud VertexAI (Gemini)                     |
 66| `GROQ_API_KEY`             | Groq                                               |
 67| `AWS_ACCESS_KEY_ID`        | AWS Bedrock (Claude)                               |
 68| `AWS_SECRET_ACCESS_KEY`    | AWS Bedrock (Claude)                               |
 69| `AWS_REGION`               | AWS Bedrock (Claude)                               |
 70| `AZURE_OPENAI_ENDPOINT`    | Azure OpenAI models                                |
 71| `AZURE_OPENAI_API_KEY`     | Azure OpenAI models (optional when using Entra ID) |
 72| `AZURE_OPENAI_API_VERSION` | Azure OpenAI models                                |
 73
 74## Configuration
 75
 76For many use cases, Crush can be run with no config. That said, if you do need config, it can be added either local to the project itself, or globally. Configuration has the following priority:
 77
 781. `.crush.json`
 792. `crush.json`
 803. `$HOME/.config/crush/crush.json`
 81
 82### LSPs
 83
 84Crush can use LSPs for additional context to help inform its decisions, just like you would. LSPs can be added manually like so:
 85
 86```json
 87{
 88  "lsp": {
 89    "go": {
 90      "command": "gopls"
 91    },
 92    "typescript": {
 93      "command": "typescript-language-server",
 94      "args": ["--stdio"]
 95    },
 96    "nix": {
 97      "command": "alejandra"
 98    }
 99  }
100}
101```
102
103### MCPs
104
105Crush supports Model Context Protocol (MCP) servers through three transport types: `stdio` for command-line servers, `http` for HTTP endpoints, and `sse` for Server-Sent Events. Environment variable expansion is supported using `$(echo $VAR)` syntax.
106
107```json
108{
109  "mcp": {
110    "filesystem": {
111      "type": "stdio",
112      "command": "node",
113      "args": ["/path/to/mcp-server.js"],
114      "env": {
115        "NODE_ENV": "production"
116      }
117    },
118    "github": {
119      "type": "http",
120      "url": "https://example.com/mcp/",
121      "headers": {
122        "Authorization": "$(echo Bearer $EXAMPLE_MCP_TOKEN)"
123      }
124    },
125    "streaming-service": {
126      "type": "sse",
127      "url": "https://example.com/mcp/sse",
128      "headers": {
129        "API-Key": "$(echo $API_KEY)"
130      }
131    }
132  }
133}
134```
135
136### Logging
137
138Enable debug logging with the `-d` flag or in config. View logs with `crush logs`. Logs are stored in `.crush/logs/crush.log`.
139```bash
140# Run with debug logging
141crush -d
142
143# View last 1000 lines
144crush logs
145
146# Follow logs in real-time
147crush logs -f
148
149# Show last 500 lines
150crush logs -t 500
151```
152
153Add to your `crush.json` config file:
154
155```json
156{
157  "options": {
158    "debug": true,
159    "debug_lsp": true
160  }
161}
162```
163
164### Configurable Default Permissions
165
166Crush includes a permission system to control which tools can be executed without prompting. You can configure allowed tools in your `crush.json` config file:
167
168```json
169{
170  "permissions": {
171    "allowed_tools": [
172      "view",
173      "ls",
174      "grep",
175      "edit:write",
176      "mcp_context7_get-library-doc"
177    ]
178  }
179}
180```
181
182The `allowed_tools` array accepts:
183
184- Tool names (e.g., `"view"`) - allows all actions for that tool
185- Tool:action combinations (e.g., `"edit:write"`) - allows only specific actions
186
187You can also skip all permission prompts entirely by running Crush with the `--yolo` flag.
188
189### Custom Providers
190
191Crush supports custom provider configurations for both OpenAI-compatible and Anthropic-compatible APIs.
192
193#### OpenAI-Compatible APIs
194
195Here's an example configuration for Deepseek, which uses an OpenAI-compatible API. Don't forget to set `DEEPSEEK_API_KEY` in your environment.
196
197```json
198{
199  "providers": {
200    "deepseek": {
201      "type": "openai",
202      "base_url": "https://api.deepseek.com/v1",
203      "api_key": "$DEEPSEEK_API_KEY",
204      "models": [
205        {
206          "id": "deepseek-chat",
207          "name": "Deepseek V3",
208          "cost_per_1m_in": 0.27,
209          "cost_per_1m_out": 1.1,
210          "cost_per_1m_in_cached": 0.07,
211          "cost_per_1m_out_cached": 1.1,
212          "context_window": 64000,
213          "default_max_tokens": 5000
214        }
215      ]
216    }
217  }
218}
219```
220
221#### Anthropic-Compatible APIs
222
223You can also configure custom Anthropic-compatible providers:
224
225```json
226{
227  "providers": {
228    "custom-anthropic": {
229      "type": "anthropic",
230      "base_url": "https://api.anthropic.com/v1",
231      "api_key": "$ANTHROPIC_API_KEY",
232      "extra_headers": {
233        "anthropic-version": "2023-06-01"
234      },
235      "models": [
236        {
237          "id": "claude-3-sonnet",
238          "model": "Claude 3 Sonnet",
239          "cost_per_1m_in": 3000,
240          "cost_per_1m_out": 15000,
241          "cost_per_1m_in_cached": 300,
242          "cost_per_1m_out_cached": 15000,
243          "context_window": 200000,
244          "default_max_tokens": 4096,
245          "supports_attachments": true
246        }
247      ]
248    }
249  }
250}
251```
252
253## Whatcha think?
254
255We’d love to hear your thoughts on this project. Feel free to drop us a note!
256
257- [Twitter](https://twitter.com/charmcli)
258- [The Fediverse](https://mastodon.social/@charmcli)
259- [Discord](https://charm.sh/chat)
260
261## License
262
263[MIT](https://github.com/charmbracelet/crush/raw/main/LICENSE)
264
265---
266
267Part of [Charm](https://charm.land).
268
269<a href="https://charm.sh/"><img alt="The Charm logo" width="400" src="https://stuff.charm.sh/charm-banner-next.jpg" /></a>
270
271<!--prettier-ignore-->
272Charm热爱开源 • Charm loves open source