Skip to content

Commit 26748a7

Browse files
committed
feat(registry/coder/modules/claude-code): add enable_state_persistence variable
Add the enable_state_persistence variable (bool, default true) and pass it through to the agentapi sub-module. Bump agentapi version to 2.2.0. Add test runs for default and disabled state persistence. Add State Persistence documentation section to README. Refs coder/internal#1258
1 parent 8defcb2 commit 26748a7

3 files changed

Lines changed: 79 additions & 28 deletions

File tree

‎registry/coder/modules/claude-code/README.md‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude
1313
```tf
1414
module "claude-code" {
1515
source = "registry.coder.com/coder/claude-code/coder"
16-
version = "4.7.5"
16+
version = "4.8.0"
1717
agent_id = coder_agent.main.id
1818
workdir = "/home/coder/project"
1919
claude_api_key = "xxxx-xxxxx-xxxx"
@@ -36,6 +36,20 @@ module "claude-code" {
3636

3737
By default, Claude Code automatically resumes existing conversations when your workspace restarts. Sessions are tracked per workspace directory, so conversations continue where you left off. If no session exists (first start), your `ai_prompt` will run normally. To disable this behavior and always start fresh, set `continue = false`
3838

39+
## State Persistence
40+
41+
AgentAPI can save and restore conversation state across workspace restarts.
42+
This is enabled by default.
43+
44+
To disable:
45+
46+
```tf
47+
module "claude-code" {
48+
# ... other config
49+
enable_state_persistence = false
50+
}
51+
```
52+
3953
## Examples
4054

4155
### Usage with Agent Boundaries
@@ -47,7 +61,7 @@ By default, when `enable_boundary = true`, the module uses `coder boundary` subc
4761
```tf
4862
module "claude-code" {
4963
source = "registry.coder.com/coder/claude-code/coder"
50-
version = "4.7.5"
64+
version = "4.8.0"
5165
agent_id = coder_agent.main.id
5266
workdir = "/home/coder/project"
5367
enable_boundary = true
@@ -68,7 +82,7 @@ For tasks integration with AI Bridge, add `enable_aibridge = true` to the [Usage
6882
```tf
6983
module "claude-code" {
7084
source = "registry.coder.com/coder/claude-code/coder"
71-
version = "4.7.5"
85+
version = "4.8.0"
7286
agent_id = coder_agent.main.id
7387
workdir = "/home/coder/project"
7488
enable_aibridge = true
@@ -97,7 +111,7 @@ data "coder_task" "me" {}
97111
98112
module "claude-code" {
99113
source = "registry.coder.com/coder/claude-code/coder"
100-
version = "4.7.5"
114+
version = "4.8.0"
101115
agent_id = coder_agent.main.id
102116
workdir = "/home/coder/project"
103117
ai_prompt = data.coder_task.me.prompt
@@ -120,7 +134,7 @@ This example shows additional configuration options for version pinning, custom
120134
```tf
121135
module "claude-code" {
122136
source = "registry.coder.com/coder/claude-code/coder"
123-
version = "4.7.5"
137+
version = "4.8.0"
124138
agent_id = coder_agent.main.id
125139
workdir = "/home/coder/project"
126140
@@ -176,7 +190,7 @@ Run and configure Claude Code as a standalone CLI in your workspace.
176190
```tf
177191
module "claude-code" {
178192
source = "registry.coder.com/coder/claude-code/coder"
179-
version = "4.7.5"
193+
version = "4.8.0"
180194
agent_id = coder_agent.main.id
181195
workdir = "/home/coder/project"
182196
install_claude_code = true
@@ -198,7 +212,7 @@ variable "claude_code_oauth_token" {
198212
199213
module "claude-code" {
200214
source = "registry.coder.com/coder/claude-code/coder"
201-
version = "4.7.5"
215+
version = "4.8.0"
202216
agent_id = coder_agent.main.id
203217
workdir = "/home/coder/project"
204218
claude_code_oauth_token = var.claude_code_oauth_token
@@ -271,7 +285,7 @@ resource "coder_env" "bedrock_api_key" {
271285
272286
module "claude-code" {
273287
source = "registry.coder.com/coder/claude-code/coder"
274-
version = "4.7.5"
288+
version = "4.8.0"
275289
agent_id = coder_agent.main.id
276290
workdir = "/home/coder/project"
277291
model = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
@@ -328,7 +342,7 @@ resource "coder_env" "google_application_credentials" {
328342
329343
module "claude-code" {
330344
source = "registry.coder.com/coder/claude-code/coder"
331-
version = "4.7.5"
345+
version = "4.8.0"
332346
agent_id = coder_agent.main.id
333347
workdir = "/home/coder/project"
334348
model = "claude-sonnet-4@20250514"

‎registry/coder/modules/claude-code/main.tf‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ variable "enable_aibridge" {
261261
}
262262
}
263263

264+
variable "enable_state_persistence" {
265+
type = bool
266+
description = "Enable AgentAPI conversation state persistence across restarts."
267+
default = true
268+
}
269+
264270
resource "coder_env" "claude_code_md_path" {
265271
count = var.claude_md_path == "" ? 0 : 1
266272
agent_id = var.agent_id
@@ -356,25 +362,26 @@ locals {
356362

357363
module "agentapi" {
358364
source = "registry.coder.com/coder/agentapi/coder"
359-
version = "2.0.0"
360-
361-
agent_id = var.agent_id
362-
web_app_slug = local.app_slug
363-
web_app_order = var.order
364-
web_app_group = var.group
365-
web_app_icon = var.icon
366-
web_app_display_name = var.web_app_display_name
367-
folder = local.workdir
368-
cli_app = var.cli_app
369-
cli_app_slug = var.cli_app ? "${local.app_slug}-cli" : null
370-
cli_app_display_name = var.cli_app ? var.cli_app_display_name : null
371-
agentapi_subdomain = var.subdomain
372-
module_dir_name = local.module_dir_name
373-
install_agentapi = var.install_agentapi
374-
agentapi_version = var.agentapi_version
375-
pre_install_script = var.pre_install_script
376-
post_install_script = var.post_install_script
377-
start_script = <<-EOT
365+
version = "2.2.0"
366+
367+
agent_id = var.agent_id
368+
web_app_slug = local.app_slug
369+
web_app_order = var.order
370+
web_app_group = var.group
371+
web_app_icon = var.icon
372+
web_app_display_name = var.web_app_display_name
373+
folder = local.workdir
374+
cli_app = var.cli_app
375+
cli_app_slug = var.cli_app ? "${local.app_slug}-cli" : null
376+
cli_app_display_name = var.cli_app ? var.cli_app_display_name : null
377+
agentapi_subdomain = var.subdomain
378+
module_dir_name = local.module_dir_name
379+
install_agentapi = var.install_agentapi
380+
agentapi_version = var.agentapi_version
381+
enable_state_persistence = var.enable_state_persistence
382+
pre_install_script = var.pre_install_script
383+
post_install_script = var.post_install_script
384+
start_script = <<-EOT
378385
#!/bin/bash
379386
set -o errexit
380387
set -o pipefail

‎registry/coder/modules/claude-code/main.tftest.hcl‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,36 @@ run "test_aibridge_disabled_with_api_key" {
387387
}
388388
}
389389

390+
run "test_enable_state_persistence_default" {
391+
command = plan
392+
393+
variables {
394+
agent_id = "test-agent"
395+
workdir = "/home/coder"
396+
}
397+
398+
assert {
399+
condition = var.enable_state_persistence == true
400+
error_message = "enable_state_persistence should default to true"
401+
}
402+
}
403+
404+
run "test_disable_state_persistence" {
405+
command = plan
406+
407+
variables {
408+
agent_id = "test-agent"
409+
workdir = "/home/coder"
410+
enable_state_persistence = false
411+
}
412+
413+
assert {
414+
condition = var.enable_state_persistence == false
415+
error_message = "enable_state_persistence should be false when explicitly disabled"
416+
}
417+
}
418+
419+
390420
run "test_no_api_key_no_env" {
391421
command = plan
392422

0 commit comments

Comments
 (0)