

# Clean up resources

When you finish with Claude Managed Agents for Amazon Bedrock, delete sessions before you delete what they use, and copy any files you want to keep first.

## Save files and events
<a name="claude-managed-agents-bedrock-cleanup-save-files-and-events"></a>

Copy files and export any session events you want to keep before you delete a session. On AgentCore, files in the container's own file system go away when the session's container stops. Files the agent wrote to an S3 folder, a repository, or another system stay there. Delete them separately when you no longer need them.

To keep the conversation in the service, archive the idle session instead of deleting it. Archiving keeps the events, not the container's files. For a session without S3 folders or files, its AgentCore container can remain until the runtime's idle timeout. For a session with S3 folders or files, archiving asks AgentCore to stop the container right away.

## Delete your sessions
<a name="claude-managed-agents-bedrock-cleanup-delete-your-sessions"></a>

List the sessions your role created, and delete each one you no longer need:

```bash
cma GET "sessions?created_by_me=true" | jq -r '.data[] | [.id, .status, (.title // "")] | @tsv'
cma DELETE "sessions/sesn_..."
```

The list returns one page. If the answer has `next_page`, repeat the request with `&page=` and that value.

The `cma` shell function is in [Step 1: Set up a shell](claude-managed-agents-bedrock-first-agent.md#claude-managed-agents-bedrock-first-agent-step-1-set-up-a-shell) of Run your first agent. A running session cannot be deleted, so send it a `user.interrupt` first. Deleting a session deletes its events and stops its container on AgentCore. Self-hosted, stop the tool runner yourself. To keep a session's events, archive it with `POST /sessions/{id}/archive` instead. Delete only sessions that belong to your application.

## Delete memory stores
<a name="claude-managed-agents-bedrock-cleanup-delete-memory-stores"></a>

Delete the memory stores you no longer need, which deletes their memories and versions. To keep one read-only instead, archive it:

```bash
cma DELETE "memory_stores/memstore_..."
cma POST "memory_stores/memstore_.../archive"
```

## Archive your agents
<a name="claude-managed-agents-bedrock-cleanup-archive-your-agents"></a>

Agents cannot be deleted. Archive the ones you no longer use, so no new session starts on them:

```bash
cma POST "agents/agent_.../archive"
```

## Delete the stack
<a name="claude-managed-agents-bedrock-cleanup-delete-the-stack"></a>

If you used the CloudFormation template, first detach the `ClaudeManagedAgentsCaller` policy from `CmaCaller`, or delete `CmaCaller`, if you created it. CloudFormation can't delete a managed policy that is still attached to a role. Then delete the stack:

```bash
IMAGES=$(aws ecr list-images --region us-west-2 --repository-name cma-tool-runner \
  --query imageIds --output json)
if [ "${IMAGES}" != "[]" ]; then
  aws ecr batch-delete-image --region us-west-2 --repository-name cma-tool-runner \
    --image-ids "${IMAGES}"
fi
aws cloudformation delete-stack --region us-west-2 --stack-name claude-managed-agents
aws cloudformation wait stack-delete-complete --region us-west-2 --stack-name claude-managed-agents
```

CloudFormation cannot delete a repository that still holds images, which is why the images go first. Deleting the stack removes the runtime, the repository, the roles, and the caller policy.

**Important**  
Every application that uses the caller policy loses access, and every session that uses the session role stops working.

If you made the resources in the console, delete them in this order: the AgentCore Runtime, the ECR repository, the caller policy, the tool runner role, and the session role.

## Check what is left
<a name="claude-managed-agents-bedrock-cleanup-check-what-is-left"></a>
+ **Log groups.** The runtime's log groups under `/aws/bedrock-agentcore/runtimes/` stay after the runtime is deleted. Delete them, or set a retention period.
+ **Data retention mode.** If you set `aws_review` for Claude Fable, it still applies to every Amazon Bedrock call in the account. Set it back if nothing else needs it.
+ **Self-hosted.** Delete the session folders and `activation.json` files you made, the `cma-runner` profile, and `CmaSelfHostedToolRunnerRole` if you created it by hand.
+ **Caller role.** Delete `CmaCaller` and the `cma-caller` profile if you created them.
+ **Customer managed keys.** If you set a project's encryption configuration, delete `CmaKeyRole` and schedule the AWS KMS key for deletion only after you delete the project's sessions and memory stores. Once AWS KMS deletes the key, content under it can't be recovered.
+ **Examples.** Each example has its own stack and its own clean-up steps. See [Clean up the examples](claude-managed-agents-bedrock-examples.md#claude-managed-agents-bedrock-examples-clean-up-the-examples).