A few weeks ago one of my Claude Code sessions was handed a broken endpoint: report submission returned 500 on QA and 404 on production. Before it started digging, it asked the other two sessions I had open whether they knew anything about it.

Both replied within a minute. The first one explained the 500: the QA Lambda pointed at a production database it had no network path to. The second one said something none of us had connected to this bug yet: the API’s AWS WAF used the SizeRestrictions_BODY rule from AWSManagedRulesCommonRuleSet, which blocks any request body over 8 KB. A report with a photo is always over 8 KB. So even after we fixed the 500 and the 404, every real report from the mobile app would have been rejected with a 403.

The 8 KB limit in that rule can’t be raised, so the usual fix is to override the rule to Count and add a label-based rule that blocks oversized bodies everywhere except the report route. That’s what we did. All three fixes went into the same pull request, and that one answer saved a full round of "it’s fixed / no, it’s still broken" with the mobile team.

Some context. I run the backend of an API platform for a large international organization on my own. The stack is AWS Lambda (mostly Python), API Gateway and CDK, deployed through Azure DevOps pipelines into separate QA and production accounts. Most of the time I have two or three agent sessions running at once, and some stay open for days. Getting the agents to write code was quick. What took me months was everything around it: making them remember the right things, keeping them out of each other’s way, and letting them work without me clicking "approve" all day. This post is the setup I ended up with and the mistakes that shaped it.

The agents forget everything

A session only knows what’s in its context. Open a new one and it has to figure out again which AWS account is QA, why the pipeline has two approval gates, and which API the mobile app talks to. On infrastructure work, that’s expensive, because most of what matters isn’t in the code. It’s things like "this Lambda needs an extra IAM policy because it runs in a VPC".

Long sessions have the opposite problem. After a day or two the context fills up and gets compacted into a summary. The summary keeps the goal and drops the details, and the details are what you need on day two.

I deal with this in three ways.

CLAUDE.md

Every session reads CLAUDE.md from the repo root first. Mine is 185 lines. It has the environments with the exact login commands, how to build, test and deploy, a folder map, the commit conventions, and a "Gotchas" section. Everything else is in the README, and CLAUDE.md says so in its first lines.

The Gotchas section is the part that pays off. Each entry is a symptom, a cause and a fix, written so the agent can match it to an error message. For example: if a Lambda has a custom role and runs in a VPC, CDK won’t attach the VPC policy for you, and the deploy fails with "execution role does not have permissions to call CreateNetworkInterface". The first time, that cost an afternoon. Every session since has fixed it in a minute.

Mine is in .gitignore because it’s full of workarounds for my own machine. If you want the whole team’s agents to share one, commit it and review it like code. A wrong line there is a wrong instruction to every future session.

Memory notes

Claude Code also has a memory folder per project that the agents read and write themselves. After a few months mine has 32 notes and an index file with one line per note. Only the index is loaded at the start of a session. More precisely, only the first 200 lines or the first 25KB of the index file (MEMORY.md), whichever comes first, are loaded at session start, and anything past that isn’t. That limit is the real reason index lines have to be short and specific. The agent opens a note when its index line looks relevant.

Each note is one fact, and the most useful part is a Why line:

---
name: english-only-project-artifacts
description: ALL work items, PRs and commits in English (chat can be in any language)
metadata:
  type: feedback
---

Everything written into project artifacts must be in English.

**Why:** shared project with international stakeholders. Caught when a work item
was created with a title in my native language and had to be rewritten.

**How to apply:** write ADO and git content in English from the start, whatever
language the conversation is in.

Without a reason, an agent applies a rule too literally or drops it when it gets in the way. With the reason, it can work out whether the rule fits a case nobody planned for.

The index line matters just as much. "Notes on the image builder" never gets opened again. "Images missing from the archive because the builder sent no User-Agent; the host returns 403 to bare requests" gets opened every time someone asks about missing images.

Memory brought its own problems:

  • Notes go stale. The PR a note calls "pending" gets merged, a decision gets reversed. One of my notes starts with "UPDATE: decision REVERSED". So I treat every note as a lead to check. If it names a file, branch or AWS resource, the agent confirms it still exists before acting on it. The best version of this came from an agent itself, which opened an answer with "caveat: ~26 days old, verify against current state."

  • Status notes turn into logs. My biggest note grew to 1,850 words of dated updates, with the current state buried at the bottom. Now the agent rewrites these notes from scratch each time, with the current state at the top.

  • Notes repeat git. Agents like to write down what they just did, but that’s already in the commits and PRs. A note earns its place when it says something the repo can’t: why we decided something, what didn’t work, who owns an outside system.

  • Save early. Compaction loses resource names, half-finished checks and the reasons behind choices. So I ask the agent to save what it’s found before a long or risky step. In one session it wrote its findings a few minutes into an investigation, and when the session got compacted hours later, nothing was lost.

There’s also one note called "session handoff" whose index line starts with "START HERE in a new session". It’s my shift handover, and it’s the note I’d write first if I were starting again.

Here’s a trimmed version of mine:

---
name: session-handoff
description: START HERE in a new session. Access tricks, proven patterns, current state, open threads
metadata:
  type: project
---

## Access
- Our AWS SSO tokens expire within minutes. Ask me to log in, then batch AWS work.
- Git over SSH hangs. Use the REST API for pushes and PRs.

## Proven patterns
- Prod Lambda change: clone-test with a harmless payload, then publish a version,
  change code, change config, verify, roll back on error.

## Current state (2026-10-01)
- Notifications on Secrets Manager: QA done, PROD done for all live functions.
- Drift: done live and in the runbook, not fully in IaC yet.

## Open threads
- Image archive size: blocked on a product decision.

Sessions that talk to each other

The opening story only works because sessions can see each other. Claude Code can list the other sessions running on the same machine and send them a message, which arrives marked as coming from a peer session. (Claude Code calls this cross-session messaging. It’s a fairly new feature: the changelog lists it as added in v2.1.224, for macOS and Linux, so check that your version is at least that.)

A few rules I follow:

  • One topic per session. "Report submission v2", and never "whatever I’m doing today". Mixed topics make compaction summaries worse.

  • Separate copies of the code. Each session that edits files gets its own git worktree. Two agents in one checkout will overwrite each other without noticing. Worktrees of one repo share one memory folder. Notes rarely clash because each note is its own file. The index is different: it’s a single file that every session edits when it adds a note, so that’s where clashes would happen. In practice they don’t, because the agent edits the index by exact-match replacement, and Claude Code refuses the edit if the file changed since the agent last read it. The agent then re-reads the index and adds its line again.

  • Check a peer’s answer before acting on it. If another session says the bucket policy is wrong, look at the bucket policy first.

  • Ask how old the knowledge is. "From my notes, 26 days old" and "I checked five minutes ago" are very different answers.

  • Make the question self-contained. The other session can’t see your context. Include the endpoint, the symptoms and what you already know. For example: "POST /{lang}/exchange/reports returns 500 on QA and 404 on PROD. The QA Lambda connects to the production LogIE database. Do you know why QA can’t reach it, or anything else about this route?"

It helps with boring things too. Before my stand-up, one session asks another for "2-3 short lines on what you did yesterday: route, QA/PROD status, PR number, anything still open". It’s a better summary than the one I’d write from memory at 9:55.

Letting the agents work without asking

None of this helps if the agent stops every few minutes to ask permission. For months, mine did.

276 rules and leaked tokens

Every time I clicked "always allow" on a shell command, Claude Code saved that exact command as a rule. After a few months I had 276 of them and I was still getting prompts, because each rule matched one literal command:

"Bash(AWS_PROFILE=qa-admin aws lambda get-function --function-name builder-qa --query 'Configuration.[Runtime,Handler]' --output table)"

Change the function name and it no longer matches. I’d also set the "bypass permissions" mode, but the Claude Code VS Code extension (as of September 2026) didn’t pick it up from the settings file, so it did nothing.

Cleaning up those rules, I found something worse. Some of them had credentials in them: an API key in a curl header, a personal access token in curl -u. "Always allow" had saved them in plain text in my home folder.

Now the agent never puts a credential in a command. It reads the credential from the OS keychain at run time, for example PAT=$(security find-generic-password -s …​ -w) on macOS, or PAT=$(secret-tool lookup service …​) on Linux. If a command like that gets "always allowed," the saved rule holds the lookup rather than the token. The rule lives in a memory note and nothing technical enforces it, so I also grep my settings files now and then. Any token that ever ended up in a saved rule counts as leaked and gets rotated. If you’ve used "always allow" for a while, run this today:

grep -nE -- '-u :|x-api-key|Bearer ' ~/.claude/settings*.json .claude/settings*.json

What I use now

I stopped listing commands and started listing limits:

{
  "permissions": {
    "allow": ["Bash", "Read", "Edit", "Write", "Glob", "Grep"],
    "deny": [
      "Bash(git push --force:*)", "Bash(git push -f:*)",
      "Bash(git reset --hard:*)", "Bash(git branch -D:*)",
      "Bash(git clean -f:*)", "Bash(sudo:*)",
      "Bash(rm -rf /:*)", "Bash(rm -rf ~:*)"
    ],
    "defaultMode": "default"
  }
}

A bare tool name in allow allows every use of it, and the deny list still applies on top. I kept defaultMode on default so the deny list stays in charge, without depending on how a bypass mode treats it.

Be honest with yourself about what this list is. It’s easy to get around: git push origin +main force-pushes without matching any rule. It catches the accidental destructive command. The real protection is the next part, plus IAM and branch policies that hold no matter who types the command.

The next part is a memory note that says what the agent may do on its own: read logs, call QA Lambdas, run smoke tests, curl endpoints, then report back with evidence. It asks only at real decision points, or before anything that can’t be undone or that people outside the team will see: a production deploy, deleting or rotating something, merging a PR, sending a message.

Habits that keep it safe

  • QA is open; production goes step by step. In QA the agent can deploy and break things freely. In production, once I’ve approved it, it publishes a Lambda version to roll back to, changes code first, config second, checks, and rolls back if the check fails.

  • Test on a copy. Before moving a live Lambda’s database credentials into Secrets Manager, the agent made a temporary copy of the function with the new code and called it with harmless input (a notification to a device that doesn’t exist). The copy failed: the old role couldn’t read the new secret. Switching the real function first would have stopped push notifications for every user.

  • Check against the remote. In my setup git fetch over SSH started hanging silently and local main fell weeks behind. A session deployed local code to a QA Lambda and undid three recent fixes. We caught it by comparing file hashes with the remote before the nightly job ran. Now the agent checks every file against the remote through the REST API before any manual deploy.

  • Don’t block on the human. AWS logins expire and only I can log back in. Instead of stopping to ask, the agent runs aws sts get-caller-identity in a background loop and carries on as soon as I’ve logged in.

Where to draw the line

The risky permissions are often the ones that don’t look risky. An agent with CLI access to your pipelines acts under your identity. If you are also the approver for the environments that pipeline deploys to, then "start a run" can quietly mean "approve production". Nothing in the command says "deploy to prod", and that’s exactly why it’s easy to miss.

So I settled on two rules. First, a person clicks production approvals in the UI, at the moment of the decision. An approval is only worth something if someone is paying attention right then, and an agent calling the approval API for you turns it into a formality. Second, anything that can trigger a production deploy as a side effect counts as an approval too: starting a pipeline, merging to main, re-running a stage. It’s worth going through your own pipeline once and listing those paths.

What stays with a person

The agents do most of the investigating and most of the typing now. A few things stay with me:

  • Anything with real-world effects. A production report gets geocoded, put on a map and sent to people’s inboxes. A push lands on real phones. The agent tests these paths only with requests that can’t do harm, like an invalid payload that must return 422.

  • Real data. When QA needed its own database, it got the production schema and a few rows of obviously fake data.

  • Secret values. The agent checks that a secret exists and the right role can read it. It never prints the value.

  • Messages to people. The agent drafts, I send. It doesn’t know who already knows what, or which topic is touchy for whom.

  • Product calls. Whether 5,000 images go into the app’s offline archive is a product decision. The agent brings the numbers: archive size, download time on a slow connection, how often the images change.

If you want to try this

  1. Write a CLAUDE.md of 100 to 200 lines with exact commands and a Gotchas section.

  2. Use memory deliberately. It’s on by default. One fact per note, a specific index line, and a Why. Save notes before risky steps too.

  3. Clean memory up once a month: delete what’s done, rewrite what turned into a log.

  4. Replace command-by-command approvals with tool-level allow plus a deny list, then grep your settings for saved credentials.

  5. Write down what the agent can do alone, what it asks about, and what it never does.

  6. Give each parallel session its own topic and its own worktree.

  7. Keep production approvals with a person, and list every path in your pipeline that can approve them by accident.

If you only do one of these, do the Gotchas section. Each entry takes five minutes to write after an incident, and it’s the one part of the setup that every future session reads.