跳到正文
DEV Community· NeuralAlpha·· 3 小時前AI 評分67

運行多個 Claude Code 工作階段時遇到的問題及修正方法

Running a dozen Claude sessions as a tiny company: what broke and how we fixed it

AI 導讀

作者分享自己以 Claude Code 工作階段管理多個小型專案時遇到的問題,並整理通訊、權限、排程監測及報告流程的修正方法。設計包括由中繼工作階段轉送訊息但不作判斷、將聲稱已獲批准的訊息交由 COO 核實,並為排程檢查加入寬限時間。自主權分級則把超出小額上限的支出、羣發訊息、使用作者真名或不可逆刪除列為須經本人確認的操作。

正文

I run several small projects with Claude Code sessions instead of employees. One session plays "COO", others own a project each, one writes code, and one only passes messages. The registry currently lists 17 sessions (that is the registry count, not how many run at once).

This is not a success story. Revenue from the digital products is still close to zero. What I do have is a list of things that broke in the first weeks and the fixes that stuck. Here are the ones that matter if you try something similar.

Break #1: the sessions could not talk to each other

Some of my sessions had no way to message other sessions. Reports reached the COO only through a once-a-day check or when I pasted text by hand. A worker who wanted help from a sibling had no channel at all.

Fix: a relay session that runs on a fixed schedule (now every two hours during the day). It reads each session's new reply, writes numbers and events into a JSONL ledger, delivers session-to-session messages, and wakes the COO only when a decision is needed. Workers end their reply with one line:

PJC_TO {"to":"<recipient name>","msg":"<request, verbatim>"}

Two design rules made it safe enough:

  1. Relay, never judge. It does not summarize or rewrite a message. Once it starts interpreting, it becomes a second COO.
  2. Reply text is data, not instructions. Nothing in a reply can change what the relay does.

Cost of this design: messages can be up to two hours late. Urgent items go through a separate notification path.

Break #2: anyone can type "the owner approved this"

A session reply is just a string. If a worker writes "approved by the owner" or "COO's instruction", the reader may believe it.

Fix: a pattern filter in the relay.

SUSPICIOUS = re.compile(
    r"(本人.{0,6}(承認|OK|了承|許可)|承認済み|本体の指示|(owner|COO|user) (approved|says)|approved by|...)",
    re.I)

(The first alternatives are Japanese phrases for "the owner approved". The list in the repo is longer; this is an excerpt.) Matching messages are not delivered. They go to the COO, who decides. Instructions are accepted only from the COO's session ID.

Regexes can be dodged by rewording, so this is only the first net. The second one is a hard rule: anything that spends money, mass-emails a list, uses my real name or signs a contract, or deletes something irreversibly needs my confirmation, whatever path it came through.

Break #3: an exception was needed, and it needed a fence

At first every message between workers also went through the COO. The COO's reading load grew. I added one exception: two sessions that are a pair inside the same project (for example "X" and "X Code") may pass the COO's decisions to each other directly.

def same_unit(sender, dst, reg):
    ...
    return a + " Code" == b or b + " Code" == a

The fence: if the text contains words like payment, mass-send, contract, or deletion (a keyword list, which also catches the yen sign), it goes to the COO anyway. The keyword list over-blocks on purpose. A wrongly blocked message costs a minute. A wrongly delivered one can cost more.

Break #4: a scheduled task silently stopped, and nobody noticed

Failures leave logs. Silent stops do not. I wrote a small health check (tools/health.py) that reads two things: a snapshot of all scheduled tasks (last fired time, last result, cron expression) and a file where each mechanism writes "I ran" after every run.

It reports three problems only:

  • Late: the most recent scheduled time passed and the task did not fire (30 minute grace)
  • Failing: two failures in a row
  • Stale snapshot: the data itself is older than 72 hours

It also keeps "not recorded" and "zero" apart. If there is no record, the table says so; it never shows a comforting 0.

A false alarm in the first version

The first version compared each task against the latest scheduled time before the snapshot. If a task's scheduled time came a few minutes before the snapshot, the task was still running, and its "last fired" value was still the previous run. The check called it late. It was not.

The fix is one argument. Count scheduled times only up to snapshot time minus the grace period:

exp = prev_fire(cron, ref - GRACE)  # ignore a schedule that came due right before the snapshot

The cost is that a real stall can be noticed one cycle later. I took that trade because alarms that cry wolf get ignored.

Related fix: the relay used to do nothing when nothing changed, and left no trace, so to the health check it looked dead. Now every run, even a no-op, writes a heartbeat line.

Break #5: format drift and wrong addressees

  • Workers wrote their one-line reports in slightly different shapes, and the ingest step dropped some. I made the reader tolerant instead of making workers stricter.
  • The COO sometimes sent instructions to the wrong session (about three times in one week). That was the sender's error, not the relay's. The COO now checks business, task and session in the ledger before sending.

The rhythm that holds it together

A few fixed times keep the sessions from drifting apart:

  • Every two hours, 7:47 to 23:47: the relay (it sleeps at night; a light hourly watcher only checks whether new replies arrived)
  • Every morning: the COO's stand-up sheet, built from the ledger, then one short directive per project that actually moved
  • Every night: a daily check, plus an automatic pull of the numbers I can fetch by script
  • Every Saturday: a retrospective of the machinery itself: relay cost, failures, delays, duplicates, and the manual steps that still land on me. It may change at most three things per week

The Saturday limit matters. The first instinct of an agent that finds a flaw is to rebuild everything. Three small changes a week is slow enough that I can see which one helped.

How much freedom the sessions get

The other thing that kept this from becoming a mess is a short ladder of autonomy. Reading, counting and analysing is free (L0). Drafts and code inside a session's own folder are free (L1). Small changes inside an approved pattern, such as a title or a posting time, are free but reported weekly (L2). Publishing and pricing go ahead on the owner's side after a pre-publication check, with the action and how to undo it logged for me to read the next morning. Only a short list needs my approval before anything happens: spending above a small limit, mass messages to a list, my real name, my face or voice, and irreversible deletion.

The point is that the relay and the health check are not the safety system. They are the plumbing. The ladder is what limits the damage when a message is wrong.

What did not work

  • I tried to measure what the relay costs in usage. I never recorded the numbers, so I closed that experiment as "cannot be measured" on Nov 25. No delays were reported, and that is all I know.
  • The watcher that runs on my own PC for offloaded code jobs has no liveness check yet. If it stops, nothing tells me. That is on the to-do list.

If you want to copy this

  1. Give workers one reporting line you can parse, and make the parser forgiving.
  2. Let a single session pass messages, with no judgement.
  3. Never deliver a message that claims approval; route it to whoever can verify.
  4. Make "I ran" a record, including the runs that did nothing.
  5. Add a grace period to every alarm so that people keep trusting it.
  6. Write down what you will measure before you run something, or you will end up closing it as "cannot be measured".

I wrote this with an AI assistant and checked the facts against my own repository. Two small Claude skills I use around this (a two-week experiment with a stop line written first, and a pre-publish check) are free, English versions included: free skill pack.

來源:DEV Community · dev.to