Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 115 additions & 65 deletions registry/coder-labs/modules/sourcegraph-amp/README.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,145 @@
---
display_name: Amp
icon: ../../../../.icons/sourcegraph-amp.svg
description: Sourcegraph's AI coding agent with deep codebase understanding and intelligent code search capabilities
description: Install and configure the Amp CLI in your workspace.
verified: true
tags: [agent, sourcegraph, amp, ai, tasks]
tags: [agent, sourcegraph, amp, ai]
---

# Sourcegraph Amp CLI
# Amp

Run [Amp CLI](https://ampcode.com/) in your workspace to access Sourcegraph's AI-powered code search and analysis tools, with AgentAPI integration for seamless Coder Tasks support.
Install and configure the [Amp CLI](https://ampcode.com/docs/cli) in your workspace.

```tf
module "amp-cli" {
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
version = "3.0.1"
agent_id = coder_agent.example.id
amp_api_key = var.amp_api_key
install_amp = true
agentapi_version = "latest"
module "amp" {
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
version = "4.0.0"
agent_id = coder_agent.main.id
amp_api_key = var.amp_api_key
}
```

## Prerequisites
> [!WARNING]
> If upgrading from v3.x.x of this module: v4 is a major refactor that drops support for Coder Tasks and AgentAPI. The module now only installs and configures Amp; launch it with your own `coder_app`. `ai_prompt`, `mode`, `report_tasks`, `install_via_npm`, and the web/CLI app inputs are removed; pass `--mode` in your launcher instead. `base_amp_config` no longer writes default keys, and the Coder task-reporting MCP server is no longer added. Keep using v3.x.x if you depend on Coder Tasks.

- **Default (official installer)**: No prerequisites - the official installer includes its own runtime (Bun)
- **npm installation (`install_via_npm = true`)**: Requires Node.js and npm to be installed before Amp installation
- Required for Alpine Linux or other musl-based systems
- Ensure Node.js and npm are available in your workspace image or via earlier provisioning steps
## Examples

## Usage Example
### Standalone mode with a launcher app

```tf
data "coder_parameter" "ai_prompt" {
name = "AI Prompt"
description = "Write an initial prompt for Amp to work on."
type = "string"
default = ""
mutable = true
locals {
amp_workdir = "/home/coder/project"
}

variable "amp_api_key" {
type = string
description = "Sourcegraph Amp API key. Get one at https://ampcode.com/settings"
sensitive = true
module "amp" {
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
version = "4.0.0"
agent_id = coder_agent.main.id
workdir = local.amp_workdir
amp_api_key = var.amp_api_key
}

module "amp-cli" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
amp_version = "3.0.0"
agent_id = coder_agent.example.id
amp_api_key = var.amp_api_key # recommended for tasks usage
workdir = "/home/coder/project"
instruction_prompt = <<-EOT
# Instructions
- Start every response with `amp > `
EOT
ai_prompt = data.coder_parameter.ai_prompt.value
base_amp_config = jsonencode({
"amp.anthropic.thinking.enabled" = true
"amp.todos.enabled" = true
"amp.tools.stopTimeout" = 600
"amp.git.commit.ampThread.enabled" = true
"amp.git.commit.coauthor.enabled" = true
"amp.terminal.commands.nodeSpawn.loadProfile" = "daily"
"amp.permissions" = [
{ "tool" : "mcp__coder__*", "action" : "allow" },
{ "tool" : "Bash", "action" : "allow", "context" : "thread" },
{ "tool" : "Bash", "matches" : { "cmd" : ["rm -rf /*", "rm -rf ~/*"] }, "action" : "reject", "context" : "subagent" },
{ "tool" : "edit_file", "action" : "allow" },
{ "tool" : "write_file", "action" : "allow" },
{ "tool" : "read_file", "action" : "allow" },
{ "tool" : "Grep", "action" : "allow" }
resource "coder_app" "amp" {
agent_id = coder_agent.main.id
slug = "amp"
display_name = "Amp"
icon = "/icon/sourcegraph-amp.svg"
open_in = "slim-window"
command = <<-EOT
#!/usr/bin/env bash
set -e
cd "${local.amp_workdir}"
exec amp --mode medium
EOT
}
```

### Settings, MCP servers, and guidance

```tf
module "amp" {
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
version = "4.0.0"
agent_id = coder_agent.main.id
workdir = "/home/coder/project"
amp_api_key = var.amp_api_key

base_amp_config = <<-EOF
{
"amp.git.commit.coauthor.enabled": true,
"amp.permissions": [
{
"tool": "Bash",
"action": "ask",
"matches": {
"cmd": ["git push*"]
}
}
]
})
}
EOF

mcp = <<-EOF
{
"playwright": {
"command": "npx",
"args": ["-y", "@playwright/mcp@latest", "--headless", "--isolated", "--no-sandbox"]
}
}
EOF

instruction_prompt = <<-EOT
# Instructions
- Run the test suite before committing.
EOT
}
```

`base_amp_config` uses the [Amp settings](https://ampcode.com/docs/cli/settings) format and overwrites `~/.config/amp/settings.json` on every start. `mcp` uses the [`amp.mcpServers`](https://ampcode.com/docs/customize/mcp) format and is added after it. `instruction_prompt` is written to `~/.config/AGENTS.md` ([AGENTS.md](https://ampcode.com/docs/customize/agents-md)).

### Serialize a downstream `coder_script` after the install pipeline

The module exposes the `scripts` output: an ordered list of `coder exp sync` names for the scripts this module creates (pre_install, install, post_install). Scripts that were not configured are absent.

```tf
module "amp" {
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
version = "4.0.0"
agent_id = coder_agent.main.id
}

resource "coder_script" "post_amp" {
agent_id = coder_agent.main.id
display_name = "Run after Amp install"
run_on_start = true
script = <<-EOT
#!/usr/bin/env bash
set -euo pipefail
trap 'coder exp sync complete post-amp' EXIT
coder exp sync want post-amp ${join(" ", module.amp.scripts)}
coder exp sync start post-amp

amp --version
EOT
}
```

## Authentication

Set `amp_api_key` (exported as `AMP_API_KEY`) or run `amp login` in the workspace. See [Amp CLI](https://ampcode.com/docs/cli).

## Troubleshooting

- If `amp` is not found, ensure `install_amp = true` and your API key is valid
- Logs are written under `/home/coder/.amp-module/` (`install.log`, `agentapi-start.log`) for debugging
- If AgentAPI fails to start, verify that your container has network access and executable permissions for the scripts
Check the log files in `~/.coder-modules/coder-labs/sourcegraph-amp/logs/` for detailed information.

> [!IMPORTANT]
> To use tasks with Amp CLI, create a `coder_parameter` named `"AI Prompt"` and pass its value to the amp-cli module's `ai_prompt` variable. The `folder` variable is required for the module to function correctly.
> For using **Coder Tasks** with Amp CLI, make sure to set `amp_api_key`.
> This ensures task reporting and status updates work seamlessly.
```bash
cat ~/.coder-modules/coder-labs/sourcegraph-amp/logs/install.log
cat ~/.coder-modules/coder-labs/sourcegraph-amp/logs/pre_install.log
cat ~/.coder-modules/coder-labs/sourcegraph-amp/logs/post_install.log
```

## References

- [Amp CLI Documentation](https://ampcode.com/manual)
- [AgentAPI Documentation](https://github.com/coder/agentapi)
- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents)
- [Amp CLI documentation](https://ampcode.com/docs/cli)
- [Amp configuration](https://ampcode.com/docs/cli/settings)
- [Amp MCP](https://ampcode.com/docs/customize/mcp)
Loading
Loading