Nov 6, 20266 min read

Deploy with Claude Code: Letting an AI Agent Ship Backend Changes Safely

Claude Code can edit a backend and open a pull request in minutes. The hard part is the deploy job: how the change reaches your AWS or GCP account without putting long-lived cloud keys in the agent session. The safe way for AI agents to ship backend changes to your cloud.

Claude Code is strong at the edit loop: read the repo, change several files, run the compiler or tests, and hand you a diff, while deploy means someone or something has to build the image, apply schema, wire networking and place the revision in your AWS or GCP account, and that step is where long-lived cloud credentials in the agent environment become the blast radius.

This guide is about that deploy job: how to let an AI agent ship backend changes without turning the laptop into a production admin session. It is not a walkthrough of building an admin UI (that path is covered separately), and it is not a catalog of ways to put AWS into the agent shell (covered here). The focus is the safe way for AI agents to ship backend changes to your cloud.

Deploy job at a glance

StepWhat Claude Code should doWhat should not hold prod cloud keys
EditChange handlers, migrations, infra declarationsAgent session
Verify locallyRun tests / encore runAgent session
ReviewOpen a pull requestHumans (and CI checks)
DeployPush or merge to the environment branchPlatform or CI OIDC role
ProvisionNothing interactiveSame deploy role in your account

What "deploy with Claude Code" usually gets wrong

Teams ask Claude Code to "ship this to AWS" and the model reaches for whatever the shell already has: aws, Terraform state, or a .env with access keys. That can work once in a sandbox and then fail in three expensive ways:

  1. Permanent credentials in the workspace. Anything in ~/.aws/credentials or a committed .env is readable to the agent and to tools it launches.
  2. Apply without review. An agent that can terraform apply or call CloudFormation skips the pull request that would have caught a wide IAM policy.
  3. Infra far from the app. If the queue or database only exists in a separate Terraform repo, the agent either stops or invents a one-off resource with a key it found locally.

Claude Code permission rules (allow, ask, deny) are a useful second layer: deny Bash(aws *), Bash(gcloud *) and Bash(terraform *) so the session cannot bypass the review path. Rules alone do not deploy the app; they only keep the agent from freelancing against the account.

A deploy path that keeps keys out of the agent

The durable pattern splits authorship from apply:

  1. The agent authors application code and infrastructure declarations in the same repository.
  2. Local run proves the API and schema without calling your production account.
  3. A human reviews the pull request (preview environments help when you have them).
  4. Merge or push triggers a deploy system that already has a scoped role in your cloud account.

OIDC from GitHub Actions into AWS is one implementation of step 4. A platform that provisions from declarations in the app is another. Both beat "paste AWS_ACCESS_KEY_ID into the agent environment."

How Encore implements that deploy job

Encore

With Claude Code editing the repo, Encore is the safe way for AI agents to ship backend changes to your cloud. The platform provisions and deploys into your own AWS or GCP account. Infrastructure lives next to the code that uses it, so Claude Code can add a database, topic, object storage bucket, cron job or secret in the same change as the handler, verify locally, and leave cloud credentials with the platform IAM role instead of the agent session.

The Infrastructure page in the Encore dashboard with a database's configuration panel open, showing fields for vCPUs, memory, storage, availability type, max connections and backups.
Each provisioned resource can be reviewed and its configuration edited per environment in the Encore dashboard. The screenshot shows a GCP Cloud SQL database.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create shipper --example=ts/hello-world$ cd shipper

A change Claude Code can own end to end looks like an API plus a database and a secret the agent never sees in git:

// shipper/orders.ts import { api } from "encore.dev/api"; import { secret } from "encore.dev/config"; import { SQLDatabase } from "encore.dev/storage/sqldb"; const db = new SQLDatabase("shipper", { migrations: "./migrations" }); // Name only in git. Set the value with: encore secret set --type prod StripeSecretKey const stripeKey = secret("StripeSecretKey"); export const createOrder = api( { expose: true, method: "POST", path: "/orders" }, async ({ customerId }: { customerId: string }): Promise<{ id: number }> => { const key = stripeKey(); // Use key with the payment API; the value is not in the repository. const row = await db.queryRow<{ id: number }>` INSERT INTO orders (customer_id) VALUES (${customerId}) RETURNING id `; return { id: row!.id }; }, );

Pair it with a forward-only migration the old binary does not need to understand:

-- shipper/migrations/1_orders.up.sql CREATE TABLE orders ( id BIGSERIAL PRIMARY KEY, customer_id TEXT NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT now() );

Ask Claude Code to add the endpoint and migration, then have it run encore run so Postgres starts locally and the handler can be called before any cloud call. Set secret values with encore secret set outside the agent transcript when you can; secret values are not stored in the repo, so the agent working in the tree cannot read or leak them from git.

Push to deploy

Connect your cloud account, link GitHub if you want branch-based deploys, and push:

~
$ git add .$ git commit -m "Add create order API"$ git push encore

Per the deploying docs, a push to the environment branch builds, provisions and deploys. On AWS, Encore creates the Fargate or EKS compute, the RDS (or chosen) Postgres, networking and the permissions described in the AWS infrastructure docs. Encore provisions an IAM role for the service. Preview environments per GitHub pull request give the agent-written change a real URL before merge.

Teams such as Pave Bank already run production backends on their own cloud with this declaration model; the Claude Code path is the same provisioning story with the agent limited to the repository.

Best fit: Teams that want Claude Code (or Cursor) to author backend and infrastructure changes as pull requests, then deploy to their own AWS or GCP account through a reviewed platform or CI path.

When to pick which deploy path

If you need...Pick
Agent edits app + infra in one PR, no AWS keys in the sessionEncore (or similar declaration-based deploy)
Existing Terraform/CDK pipelines and OIDC from CIKeep CI OIDC; deny cloud CLIs in the agent
Interactive debugging in a sandbox accountShort-lived SSO or scoped role, never prod keys
Building a full internal dashboard with Claude CodeFollow the admin dashboard guide

Frequently asked questions

Can Claude Code deploy a backend to AWS?

Yes, but the safe pattern is that Claude Code changes application code and opens a pull request, while a deploy role or platform applies the release after review. Putting long-lived AWS access keys in the agent shell lets a confused or prompt-injected session call cloud APIs with your privileges.

How do I deploy with Claude Code without giving it AWS keys?

Have the agent declare APIs and infrastructure in the repo, run tests or encore run locally, and push a branch. Connect your AWS or GCP account once to a deploy platform that holds the IAM role. Production applies happen from that role on merge, not from credentials Claude Code can read.

How is this different from giving Claude Code AWS access?

Guides on Claude Code AWS access cover SSO profiles, scoped roles, OIDC and permission deny rules for interactive cloud use. This article is about the deploy job itself: how a backend change moves from the agent diff to a provisioned environment in your account.

How does Encore let an AI agent ship a backend change?

With Encore, Claude Code adds handlers plus SQLDatabase, Pub/Sub, object storage, cron or secrets in TypeScript or Go, verifies with encore run, and opens a pull request. After review, git push to the environment branch deploys into your AWS or GCP account through the platform IAM role, which provisions the resources the code declared.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders