OctSum
00:00 / 17:31

AI Engineer · 17:31

I had some technical difficulties during my talk this morning, so I ran back home and I'm just gonna record it from my computer instead. So hi everyone, I'm Lydia. I work on the Claude Code team at Anthropic, and the models have gotten really good lately. So we have Opus 5.5, which is my favorite daily driver, and earlier this week we also launched Fable 5.2. And these models are extremely good at long-running tasks and understanding your code base, and especially Fable is also really good at verifying its own output. But as these models get better, the way that we work with them in Claude code also changes.

今天早上我演讲时遇到了一些技术问题,所以我跑回家,改用电脑来录制这段内容。 大家好,我是Lydia。 我在Anthropic的Claude Code团队工作,最近这些模型变得非常强大。 我们有Opus 5.5,它是我日常最喜欢用的模型,而本周早些时候我们还发布了Fable 5.2。 这些模型非常擅长长时间运行的任务和理解你的代码库,尤其是Fable,它还非常擅长验证自己的输出。 但随着这些模型越来越好,我们在Claude Code中与它们协作的方式也在改变。

So earlier this year, I don't know if you remember, but sessions kind of used to look like this. So we'd use a model like Opus 4.5, which honestly for its time was really good. I really enjoyed working with Opus 4.5. But compared to today, it would just stop a lot earlier. So it would just run for shorter amounts of time. And we'd also keep correcting it. We'd keep reminding it to do things, add things like importance, exclamation mark, all these things to our Claude MD file. And also features like auto mode didn't exist yet. So we were either approving everything manually or taking the riskier approach with dangerously skip permission. So we were still very much in the loop as humans. But as these models got better at taking on bigger tasks, our sessions also changed. So nowadays, at least at Anthropic, our sessions look more like this. So we're running dozens of sessions at the same time, running for hours, verifying their own results along the way, and we even have sessions orchestrate other sessions. so whereas we used to be in the loop for almost every step and running one or just a couple sessions at a time, we've now essentially become managers for dozens of sessions.

所以,今年早些时候,我不知道你们是否还记得,会话过去大致是这样的。 那时我们使用的是Opus 4.5这样的模型,老实说,以当时的水平来看,它已经非常出色了。 我非常喜欢和Opus 4.5一起工作。 但与今天相比,它往往会更早停下来。 也就是说,它运行的时间比较短。 而且我们还得不断纠正它。 我们得不断提醒它做事情,还会在我们的CLAUDE.md文件里加入“重要”、感叹号之类的各种标记。 另外,当时还没有自动模式这类功能。 所以我们要么手动批准每一步操作,要么采用风险更高的做法,即使用dangerously skip permission(跳过权限)。 因此,我们作为人类仍然深度参与其中。 但随着这些模型越来越擅长承担更大的任务,我们的会话方式也随之改变。 所以如今,至少在Anthropic,我们的会话更像是这样。 我们同时运行几十个会话,每个会话持续数小时,并在过程中自行验证结果,甚至还有会话去协调调度其他会话。 因此,过去我们几乎每一步都要亲自参与,一次只运行一两个会话;而现在,我们基本上已经成为管理几十个会话的“经理”。

we also get a lot more done though. now you may have seen our blog post in october about how anthropic went from about 2,500 changes a day in may to more than 30,000 a day in september. but this also means that we as developers just have to rethink on what we're focused on instead. so if you think about our best practices from earlier this year, it was mainly about steering sessions, approving commands, saying no to certain things or restricting what claude could do, checking the output, and also starting the sessions. so everywhere that we now step out of that loop, something else has to take over. and this is either the model, the harness, or the environment that it's running in. so if we are not in a loop to approve every command and we're running so many sessions at the same time, how can we make sure that the code it's writing is still high quality? and most importantly, if these sessions are running for hours without our supervision, how can we make sure that they're running safely? so let's go through that by taking this old session and seeing what we have to change to get to that end result that i showed earlier.

不过我们也因此完成了更多工作。 你们可能看过我们十月发布的博客文章,讲的是Anthropic如何从五月的每天约2,500次变更,增长到九月的每天超过30,000次。 但这也意味着,我们作为开发者,需要重新思考自己应该把精力放在哪里。 所以如果回想一下我们今年早些时候的最佳实践,主要包括:引导会话、批准命令、对某些操作说不或限制Claude的能力范围、检查输出,以及启动会话。 因此,每当我们退出这个循环时,就必须有其他东西来接管。 这要么是模型本身,要么是工具框架(harness),要么是它运行的环境。 那么,如果我们不再需要批准每一条命令,而且同时运行大量会话,我们怎样才能确保它编写的代码依然是高质量的? 更重要的是,如果这些会话在我们无人监督的情况下运行数小时,我们怎样才能确保它们运行是安全的? 接下来,我们就以之前那个旧会话为例,看看需要做哪些改动,才能达到我之前展示的最终结果。

well, first of all, let's use the actual defaults we start sessions in nowadays. so that's not really something you should think about. so let's update the model here from opus 4.5 to opus 5.5 and change the manual permission to auto mode. And Opus 55 is a lot better at understanding your intent and understanding your code base. So we really don't have to steer it as much anymore mid-session. And you also no longer have to approve every command because we started making auto mode the default permission mode back in August.

首先,让我们使用如今启动会话时的实际默认设置。 所以这并不是你需要特别考虑的事情。 那么我们把这里的模型从Opus 4.5更新到Opus 5.5,并把手动权限改为自动模式。 而且Opus 55在理解你的意图和理解你的代码库方面要好得多。 所以我们在会话中途真的不必再像以前那样频繁地引导它了。 而且你也不再需要批准每一条命令,因为早在八月我们就已将自动模式设为默认权限模式。

Now being better at understanding your intent and your code base also means that we have to rethink the instructions we have in our code base. So. if you followed our best practices from earlier this year, you may still have things like important or never do this, exclamation mark, all these things in your claude md file. but with today's models, you really don't need that. and it can actually make the model go off track. so you end up with more tool calls and overall worse results. so nowadays, your claude md file should only include the things that claude cannot see from your code. so for example, maybe you have a service that's still using some legacy source somewhere, but it's not directly referenced in the code. that's still good to keep in there. but everything else, like what stack you're on or where to look, you really don't need that anymore. and we actually have a command for this called doctor prompt audit, which makes it really easy to optimize your environment for a specific model. so if you're on opus 5.5 here and you run this command, it will automatically check your CLAUDE.md and your skills to see what the new model no longer needs.

既然它更擅长理解你的意图和代码库,这也意味着我们需要重新审视代码库中的指令。 所以。 如果你遵循了我们今年早些时候的最佳实践,你的Claude.md文件中可能仍然有诸如“重要”“绝对不要这样做!”之类的内容。 但对于如今的模型来说,你其实并不需要这些。 而且这些内容实际上可能会让模型偏离正轨。 所以你最终会有更多的工具调用,整体结果也会变得更差。 所以如今,你的 CLAUDE.md 文件应该只包含 Claude 无法从你的代码中看到的内容。 比如说,你可能有一个服务在某处仍在使用某个遗留数据源,但代码中并没有直接引用它。 这类内容还是值得保留在里面的。 但其他内容,比如你用的是什么技术栈,或者该去哪里查找,现在基本都不需要了。 我们还有一个命令叫 doctor prompt audit,它能让你非常轻松地针对特定模型优化你的环境。 所以如果你现在用的是 Opus 5.5,运行这个命令,它会自动检查你的 CLAUDE.md 和技能文件,看看新模型已经不再需要哪些内容。

now, auto mode is a permission mode that runs a separate classifier on pretty much everything that isn't just reading or editing files in your project. so it automatically allows commands that it knows are safe, like running tests or installing dependencies, but it still blocks commands where it's unsure whether they're safe. and normally that's pretty good. normally that's kind of, you know, what we want. but for example, here, if we ask it to ship something to staging, we would have just, you know, approved the push to our deploy repo. but by default, auto mode only trusts this folder and this repo, so it would block that command. so we're back in the loop. now, the defaults should be good in most cases, but if you still notice that you have to approve a lot of commands even in auto mode, the first thing to look at is settings here, because you can configure auto mode in your own settings just in plain english. and this is what gets sent to the classifier, which then decides whether to reject or allow certain commands. so here we can just write which repos, buckets, domains we trust, and what it should always allow or never do. okay, so honestly, this was pretty easy.

好,现在说说自动模式。它是一种权限模式,除了读取或编辑项目中的文件之外,几乎所有操作都会交给一个单独的分类器来判断。 所以它会自动放行那些它认定安全的命令,比如运行测试或安装依赖,但对于它无法确定是否安全的命令,它依然会拦截。 通常来说,这样已经相当不错了。 通常这正是我们想要的效果,你知道的。 但比如说,在这里,如果我们让它把某个东西发布到预发布环境,我们本来就会批准推送到我们的部署仓库。 但默认情况下,自动模式只信任这个文件夹和这个仓库,所以它会拦截那条命令。 这样我们又回到了需要人工介入的循环中。 现在,默认设置在大多数情况下应该够用了,但如果你仍然发现即使在自动模式下也要批准很多命令,首先应该看看这里的设置,因为你可以直接用普通英语在自己的配置中设置自动模式。 这些内容会被发送给分类器,由它决定拒绝还是放行某些命令。 所以在这里,我们可以直接写明我们信任哪些仓库、存储桶和域名,以及它应该始终允许或绝不执行哪些操作。 好,说实话,这一步其实挺简单的。

by just using today's defaults, we've already gotten rid of most of our in-the-loop stuff. because the model took over the steering and auto mode took over all the approving, so getting out of the loop is easy. but the harder question now is how do we make sure it's okay that we're not there anymore? so first is keeping it safe, and then also verification. so let's start with keeping it safe, because everything so far, so upgrading the model and using auto mode, is just working with a model. and in most cases, it does what you tell it to do, but that's not a guarantee. so in a study we published back in august, we tested auto mode versus real people in the loop, and only about 14% of people caught a clearly dangerous command. auto mode blocked 89% of them, so it is a lot better at it than we were. but about one in ten of those commands still went through. so if you do want the guarantee, you can only enforce that in the harness. and this is where some of our older best practices still matters, and that's permission. so, for example, if you have a deny rule for a specific tool call in your project, claude code looks at this rule before the auto mode classifier even looks at it. in fact, if a tool call matches a deny rule, the classifier never even sees it. so having deny rules is still the best way to make sure claude actually never does something. but then how do you know what needs to be a rule in your project versus what the model can just know because they've gotten so good at it? i think it kind of just comes down to if claude gets it wrong once, can i take it back? so if it writes the wrong code, you can still revert that. so you can still leave that to the model. but if it throws away or uncommitted changes or it reads a key that's now in your transcript and you don't want that, that should still be a rule. so for example, let's say that we just never want claude reading our . n file. now by default, auto mode is fine with this, so it would have just approved it. so if you want to make sure that claude can never read this file, you should just add a deny rule. and then commands like cat cannot open this file either. but it's not always that straightforward because sometimes certain commands can have side effects. so, for example, let's say that npm test here, a very normal command. it's just a test, so auto mode runs it. that's fine. but when the script is running, it runs code that you didn't write, like your dependencies. or maybe claude runs a script real quick that it wrote just to quickly check something. so if one of those scripts is compromised, it could just open that same end file or your ssh keys and send those to a server you've never heard of, right? and even if we were still there as humans approving everything, honestly, we would have just clicked allow because there's nothing to say no to. it's just part of the script that in this example case, npm test runs. and permissions only decide if a tool call runs, but they cannot limit what it can reach once it's running. so we want to make sure that these kinds of scripts can still run because this is just part of how claude can check its own work, running tests. So we cannot just block npm tests, but we want to limit its side effects. So really, we just want to limit the environment that it's running in. So if you're running it locally or on your own machine, you can run commands like that in a sandbox. So then you have control over which files in a command it can read, which folders it can write to, which hosts it can reach, and the operating system enforces that. also, this also applies to everything that command then starts, so any child processes. so on its own, that deny rule gets checked by claude before the command runs, but all it sees there is npm test, so it doesn't see which files that script ends up opening. but with the sandbox on, that same rule gets passed on to the operating system.

只需使用今天的默认设置,我们就已经去掉了大部分需要人工介入的环节。 因为模型接管了引导工作,自动模式接管了所有审批,所以脱离人工循环其实很容易。 但现在更难的问题是,我们如何确保即使我们不再一直盯着它,也是安全的? 所以首先是保证安全,然后是验证。 那我们先从保证安全说起,因为到目前为止,升级模型和使用自动模式,都只是在与一个模型打交道。 在大多数情况下,它会按你的指示去做,但这并不是保证。 所以在我们去年八月发表的一项研究中,我们把自动模式与有真人参与的情况进行了对比,结果只有大约14%的人发现了一条明显危险的命令。 自动模式拦截了其中的89%,所以它比我们做得好得多。 但仍有大约十分之一的此类命令被放行了。 所以如果你确实需要保证,就只能在 harness 中强制执行。 这正是我们一些较早的最佳实践仍然有用的地方,那就是权限设置。 例如,如果你在项目中为某个特定的工具调用设置了拒绝规则,Claude Code 会在自动模式分类器查看它之前先检查这条规则。 事实上,如果某个工具调用匹配了拒绝规则,分类器甚至永远不会看到它。 所以,拒绝规则仍然是确保 Claude 绝对不会执行某些操作的最佳方式。 但是,你如何判断哪些内容需要在项目中设为规则,哪些内容模型自己就能掌握,因为它们已经变得非常擅长了? 我想这基本上取决于一个问题:如果 Claude 犯了一次错,我还能收回吗? 比如它写错了代码,你仍然可以回滚。 所以这类事情仍然可以交给模型来处理。 但如果它丢弃了未提交的更改,或者读取了一个现在已经出现在你的对话记录中的密钥,而你并不希望这样,那么这就应该设为规则。 比如说,我们绝对不希望 Claude 读取我们的 .n 文件。 n 文件。 默认情况下,自动模式对此没有问题,所以它本来会直接批准这个操作。 所以,如果你想确保Claude永远无法读取这个文件,你只需添加一条拒绝规则。 然后像cat这样的命令也无法打开这个文件。 但事情并不总是这么简单,因为某些命令可能会产生副作用。 比如说,这里的npm test是一个非常普通的命令。 它只是一个测试,所以自动模式会运行它。 这没问题。 但是当脚本运行时,它会执行你没有编写的代码,比如你的依赖项。 或者Claude可能会快速运行一个它为了快速检查某些内容而编写的脚本。 所以如果其中一个脚本被入侵,它完全可能打开同一个环境文件或你的SSH密钥,并将它们发送到你从未听说过的服务器,对吧? 即使我们仍然作为人类在审批每一步,说实话,我们也很可能只是点击了允许,因为根本没有理由说不。 这只是npm test在这个例子中运行的脚本的一部分。 而权限只决定工具调用是否运行,一旦运行起来,它们无法限制其能够触及的范围。 所以我们希望确保这类脚本仍然能够运行,因为这是Claude检查自身工作的一部分,即运行测试。 因此我们不能直接阻止npm test,但我们希望限制它的副作用。 所以,我们真正要做的,是限制它运行所处的环境。 因此,如果你在本地或自己的机器上运行,可以在沙箱中运行此类命令。 这样你就能控制命令可以读取哪些文件、可以写入哪些文件夹、可以访问哪些主机,而且由操作系统强制执行。 另外,这一点也适用于该命令随后启动的所有内容,也就是所有子进程。 所以,仅靠那条拒绝规则,Claude在命令运行前会进行检查,但它看到的只是npm test,因此无法看到该脚本最终会打开哪些文件。 但是开启沙箱后,同一条规则会被传递给操作系统。

so now, when that dependency tries to open our end file, the operating system just doesn't let it. And by default, it can still read most of your machine. So you'd want to add another rule for your ssh keys if you care about that. And it also cannot reach a host that wasn't approved. But the sandbox only covers the shell commands that claude runs and whatever those start. But claude's own files, your mcp servers and all of your hooks still run outside of it. So the rest of your session still runs on your own machine and everything that's on there. So ideally you want this whole thing to run somewhere where none of that is even there in the first place. and that is a cloud session because there it gets its own machine with a fresh copy of a repo. and this runs even when we close our laptop, which is definitely something you want for these longer running sessions that run for hours. so in this case, this automatically gets rid of the end file issue because it's not in git and neither are my ssh keys or our github token. and if it still needs an api key, you can add that as a network secret where it will tell you like, hey, i'm missing an api key mid-session. so it can use it without actually ever sending it to the model. and by default, also in a cloud session, network access is limited to things like package registries and github. so you have to explicitly add those domains to your environment for claude to reach other hosts. okay, so with a cloud session, we can run these long-running sessions even with our laptop closed, and it keeps us safe because it runs in its own environment. now, it's still good to remember that this machine is disposable, but the things that leave it aren't. so a commit it pushed or a message it sent through a connector. so we still run it in auto mode with our deny rules, just commit it into the repo so they come along. So it could still catch things like a force push or a secret in a commit, all that kind of stuff.

现在,当那个依赖试图打开我们的 end 文件时,操作系统就是不允许它这么做。 而且默认情况下,它仍然可以读取你机器上的大部分内容。 所以如果你在意这一点,就应该为你的 SSH 密钥再添加一条规则。 它也无法访问未经批准的主机。 但沙箱只覆盖 Claude 运行的 shell 命令以及由这些命令派生的进程。 但 Claude 自身的文件、你的 MCP 服务器以及你所有的 hooks 仍然在沙箱之外运行。 所以会话的其余部分仍然在你自己的机器上运行,机器上的所有东西也都在。 因此,理想的做法是让整个流程运行在一个根本不存在这些东西的地方。 这就是云端会话,因为它会获得自己的机器,并带有一份全新的仓库副本。 而且即使我们合上笔记本电脑,它也会继续运行,这对于那些需要运行数小时的长时间会话来说是非常值得的。 所以在这种情况下,这会自动解决 end 文件的问题,因为它不在 git 中,我的 SSH 密钥和我们的 GitHub 令牌也不在。 如果它仍然需要 API 密钥,你可以将其添加为网络密钥,这样它会在会话中途告诉你,比如:嘿,我缺少一个 API 密钥。 这样它就能使用该密钥,而无需真正将其发送给模型。 而且默认情况下,在云端会话中,网络访问仅限于包注册表和 GitHub 等服务。 所以你必须明确地将这些域名添加到环境中,Claude 才能访问其他主机。 好的,所以使用云端会话,即使笔记本电脑合上,我们也能运行这些长时间会话,而且由于它运行在自己的环境中,也能保证我们的安全。 现在,还是要记住这台机器是一次性的,但从它那里流出去的东西并不是一次性的。 比如它推送的提交,或者通过连接器发送的消息。 所以我们仍然在自动模式下运行它,并保留我们的拒绝规则,只需将其提交到仓库中,这样规则就会随之带过去。 这样一来,它仍然可以捕获诸如强制推送或提交中包含密钥之类的问题,所有这类情况都包括在内。

And beyond just safety, we also need to make sure that Claude is actually working on the right thing. So next is verification. And the nice thing about being in a loop, like we kind of knew the work was good because we'd already kind of seen every change, we'd approved everything. But now if Claude works for hours in the background, we don't have that anymore. And we're not really going to read every file at the end either. So, you know, say that we ask it to move auth to a new API. Well, Claude is very good at understanding what we want, but there are still a lot of small decisions that it has to make along the way. So with the exact same prompt, you know, one run might move it over but leave the old API in there, or one might move it but only for new logins, and another one might move it but log everyone out. And these all look pretty reasonable, but it really helps to set up these verification points along the way. So Claude keeps verifying its own results. And those can be anything that comes back as a pass or fail. So tests, a build, a screenshot, whatever you have. So now we just want to make sure that we review these verification points. Uh, they're a lot shorter to review than if we just had to, you know, review the whole change at the end. So, so that's pretty reasonable. So if one of these runs would still log everyone out, it doesn't get past that first check and then it just has to find another way. And there's a couple ways to set this up. Um, the easiest one is of course just in your prompt. So, you know, you say what done looks like and ask it to split that into tasks so they have their own tests. and i also like to ask it to show the actual output because you weren't there to see it.

除了安全性之外,我们还需要确保Claude真正在做正确的事情。 所以接下来是验证。 在循环中工作的好处是,我们大致知道工作成果是好的,因为我们已经看过每一次修改,也批准了所有内容。 但现在如果Claude在后台工作几个小时,我们就没有这种条件了。 而且最后我们也不太可能逐个阅读每个文件。 比如说,我们让它把认证功能迁移到一个新的API上。 Claude非常擅长理解我们的需求,但在过程中它仍然需要做出许多小决定。 所以即使使用完全相同的提示词,一次运行可能会迁移过去但保留旧API,另一次可能只为新登录的用户迁移,还有一次可能迁移了但把所有人都登出了。 这些结果看起来都相当合理,但在过程中设置这些验证节点确实很有帮助。 因此,Claude会不断验证自己的结果。 这些验证可以是任何能返回通过或失败结果的东西。 比如测试、构建、截图,或者你已有的任何检查手段。 所以现在我们只需确保审查这些验证节点。 嗯,它们比在最后审查整个修改要简短得多。 所以,这是相当合理的。 因此,如果其中某次运行仍然会把所有人登出,它就通过不了第一个检查,然后只能另想办法。 设置这一点有几种方法。 嗯,最简单的方法当然就是直接写在你的提示词里。 比如,你说明完成的标准是什么,然后让它把这些标准拆分成任务,每个任务都有自己的测试。 而且我还喜欢让它展示实际的输出结果,因为你当时不在场,无法亲自看到。

but again, prompting is not a guarantee that a model will do it. so for the ones that have to run, guaranteed run, i would use hooks, which are just scripts that Claude Code runs at a specific point. Those give you a lot of control because you decide when they run and what they run and what they check. So for example, every time it edits a file, we can run our linter. Every time it wants to mark a task as complete, we can run the tests for what it changed. So you know, if it touched our off code or something, it has to pass the off tests. and when it wants to finish the whole session, we can just run the entire test suite. and if one of those fails, it goes, oh, that's still broken. it goes back until it passes. so it fixes it. now, just one thing. when a test fails, by default, most tools that exit with a one exit code. but with a one, that task by Claude Code just gets marked as completed anyway. so make sure that your scripts exit with a two exit code because that's what actually sends cloud back to fix it.

但同样,提示并不能保证模型一定会这样做。 所以对于那些必须运行、必须确保执行的事情,我会使用钩子(hooks)。钩子只是Claude Code在特定时间点运行的脚本。 它们能让你拥有很大的控制权,因为你可以决定何时运行、运行什么以及检查什么。 例如,每次它编辑文件时,我们都可以运行代码检查工具(linter)。 每次它想把任务标记为完成时,我们都可以针对其所改动的部分运行测试。 所以你知道,如果它动了我们的核心代码之类的东西,它就必须通过相关的测试。 当它想要结束整个会话时,我们可以直接运行完整的测试套件。 如果其中任何一项失败,它就会意识到:哦,还有问题没修好。 它会一直返工,直到通过为止。 于是它就会去修复问题。 还有一点需要注意。 当测试失败时,大多数工具默认会以退出码1结束。 但使用退出码1时,Claude Code仍会把该任务标记为已完成。 所以请确保你的脚本以退出码2结束,因为这才真正能让Claude回去修复问题。

so, okay, now we have one session that i'm pretty comfortable with leaving alone. so now we can start with a few more of those. because they've all got their own machine, so they're, you know, not all working in the same folder. and we don't really have to think about work trees too much ourselves anymore. but then we still start every session ourselves and we review every one of them. and honestly, this is already a pretty good place to be. we are still fully in control over what gets started and when we call a task done. but even there, you know, we're still the ones kicking off every session, and we're still in the loop for all of them. so i think the most important thing to have in place here now is your ci, because all of these sessions eventually open a pr, and your ci runs the same checks on every one of them, no matter how that session was set up or, you know, what claude decided to do along the way. and if you turn on auto fix, we have like ci auto fix, claude can also see when one of those checks fails and then go back to fix it. so you're not the one spending your review on things. that a check could have caught. and for some of them, you can even turn on merge when ready. so then github merges the pr once all of the checks have passed. so you're not in the loop to review. but again, that's not the default. and that really depends on how risky the change is. so for example, on our team, every pr gets reviewed by claude first. so not by the session that wrote it. so it comes with a fresh context and also a separate group of agents to just double check every bug it finds. and then how much we review ourselves just depends on the risk. so smaller changes like docs or copy, they don't need a person. so once the automated checks are green, we're pretty good to go.

好了,现在我们有了一个我相当放心、可以放手让它自己运行的会话。 接下来我们可以再开始几个这样的会话。 因为每个会话都有自己的机器,所以它们彼此之间并不是在同一个文件夹里工作。 这样一来,我们自己也不必太过操心工作树(work trees)的问题了。 不过,我们仍然要亲自启动每一个会话,并审查每一个会话的结果。 说实话,到了这一步,已经是相当不错的状态了。 我们仍然完全掌控着启动什么任务,以及何时将任务标记为完成。 但即便如此,你知道,每个会话仍然是我们来启动的,而且所有会话我们都还在参与其中。 所以我认为现在最重要的是建立你们的 CI,因为所有这些会话最终都会开一个 PR,而你们的 CI 会对每一个 PR 运行相同的检查,无论该会话是如何设置的,或者 Claude 在过程中做了什么决定。 如果你打开自动修复,也就是 CI 自动修复功能,Claude 还能发现某个检查失败,然后回去修复它。 所以你不必把审查精力花在那些 本可以由检查捕获的问题上。 而对于其中一些检查,你甚至可以开启“就绪后合并”。 这样,一旦所有检查都通过,GitHub 就会自动合并 PR。 所以你无需参与审查。 但同样,这不是默认设置。 这really取决于变更的风险有多高。 比如,在我们团队,每个 PR 都会先由 Claude 审查。 也就是说,不是由编写它的那个会话来审查。 这样它带着全新的上下文进行审查,同时还有一组独立的智能体专门复核它发现的每一个 bug。 然后我们自己审查多少,就完全取决于风险。 比如文档或文案这类较小的改动,不需要人工介入。 所以只要自动化检查全部通过,我们就基本可以放行了。

maybe ordinary product changes just need one reviewer, and then risky changes might need two. now, ultimately, kind of where we see things going, and we're already kind of doing more of that at anthropic, is that you're not really starting all of those sessions yourself either. because if you're anything like me, i'm terrible at context switching. so having to manage so many sessions at the same time doesn't always go well. so instead, you just have one main session that's your orchestrator. and you can already see this in things like Claude Code projects, which is still in beta. but you just tell it what it needs to be done. and the orchestrator splits it up and then starts other sessions for each task. and it keeps track of what comes back. so it automatically starts and verifies these threads, which are just... new sessions, so instead of talking to eight sessions, you're just talking to one. and the main session doesn't write the code itself. so there you want a model that's really good at deciding what to do and judging what comes back, a model like fable. and if something comes back that isn't actually done, it just, you know, sends it back. so until it's actually done and it passes everything. and the threads need a model that's good at actually doing the work, like opus 5.5. and you can set those separately. so, you know, one model for the main session and then another one for the threads. and another benefit is that with this setup, with Claude Code projects specifically, we don't manage context anymore. that's all done automatically for us. so we no longer have to think about, you know, when to compact or clear all of that stuff. okay, so if you look back at those old best practices, they're all still there, but they've just moved. so the model steers it now, auto mode approves your deny rules, and the environment restricts what's possible, your test, your hooks, and your ci checks it, and then ultimately Claude can just start them as well. so almost everything we used to do ourselves is now either the model, the harness, or the environments. and we're really just here to start that first one and to just review what comes out. so if you want to try this in your own setup, i would say just take one thing that's way bigger than you normally give claude. make sure your ci actually catches the things you care about. and then spend a bit of time just configuring your environment, like its network access, its secret, and its setup script. and then start in the cloud and see where your sessions get stuck and where you're still in the loop. because that's the next thing to hand over to claude. i also highly recommend checking out our best practices in the docs as well. Thank you so much.

普通的产品改动可能只需要一位审查者,而风险较高的改动可能需要两位。 那么,最终我们看到的发展方向是——而且我们在 Anthropic 内部已经在做更多这方面的尝试——你们自己也不必亲自启动所有这些会话。 因为如果你和我一样,我很不擅长在不同任务之间切换上下文。 所以同时管理这么多会话,并不总是顺利。 相反,你只需要一个主会话,作为你的编排器。 你已经可以在Claude Code项目之类的功能中看到这一点,它目前仍处于测试阶段。 你只需告诉它需要完成什么。 编排器会把任务拆分开,然后为每个任务启动其他会话。 它还会跟踪返回的结果。 所以它会自动启动并验证这些线程,它们其实就是新的会话。这样你不必同时和八个会话打交道,只需和一个会话交流。 而主会话本身并不编写代码。 因此,这里你需要一个非常擅长决定做什么、并判断返回结果的模型,比如fable。 如果返回的结果并未真正完成,它就会,你知道的,把它送回去。 直到真正完成并通过所有检查为止。 而这些线程则需要一个擅长实际执行工作的模型,比如opus 5.5。 你可以分别设置它们。 所以,你知道的,主会话用一个模型,线程用另一个模型。 另一个好处是,在这种设置下,尤其是使用Claude Code项目时,我们不再需要管理上下文。 这一切都会为我们自动完成。 因此,我们不必再考虑何时压缩或清空这些内容之类的事情了。 好,如果你回顾那些旧的最佳实践,它们仍然存在,只是转移到了别处。 现在由模型来引导方向,自动模式批准你的拒绝规则,环境限制哪些操作是可能的,你的测试、钩子和CI检查来验证结果,最终Claude甚至可以自己启动这些流程。 所以,我们过去自己做的几乎所有事情,现在要么由模型承担,要么由框架承担,要么由环境承担。 我们在这里其实只是为了开始第一个任务,并审查最终产出。 所以如果你想在自己的环境中尝试这个方法,我建议选一个比你平时交给 Claude 的任务大得多的事情。 确保你的 CI 真的能捕捉到你所关心的问题。 然后花点时间配置你的环境,比如网络访问权限、密钥以及设置脚本。 接着在云端启动,观察你的会话在哪里卡住,以及你在哪些地方仍需要介入。 因为那就是接下来要交给 Claude 的事情。 我也强烈推荐你查看文档中的最佳实践。 非常感谢大家。

Overview

这段演讲由 Anthropic 的 Lydia Hallie 主讲,主旨是:随着 Claude 模型能力提升,Claude Code 的最佳实践需要从“逐步盯守、频繁纠正”转向“交给模型、权限、环境和验证机制”。演讲先回顾早期会话模式与开发者的角色,再逐一说明如何调整默认模型与权限模式、精简 CLAUDE.md、用 deny 规则和沙箱约束高风险操作,并借助云端会话、验证点、hooks 与 CI 保证长时间无人值守运行的质量与安全。最后,演讲提出由主会话编排多个子会话的趋势,并建议开发者从一项较大任务开始逐步移交控制权。整体脉络清晰,对希望让 Claude Code 长时间自主工作的团队有较强的实践参考价值。

Chapters

00:00 开场:模型进步带来的会话变化

演讲者指出,Opus 5.5 与 Fable 5.2 等模型擅长长时间任务、理解代码库,Fable 还能较好地验证自身输出。随着模型变强,Claude Code 的使用方式也随之改变。

无明确视觉对象,以核心转折句作为代表性锚点

00:36 从逐步盯守到同时管理多个会话

早期的 Opus 4.5 会话较短,容易提前停止,需要不断纠正,并在 CLAUDE.md 中加入“important”“never do this”等强调语。当时没有自动模式,开发者只能逐条批准或使用危险的跳过权限方式。如今在 Anthropic 内部,会话可以同时运行数十个、持续数小时,并自行验证结果,甚至由会话编排其他会话。据其博客提到,Anthropic 每日变更数从 5 月约 2,500 增至 9 月超过 30,000。

早期会话的界面形态
早期使用的模型
与早期模型的协作画面
模型较早停止运行的表现
早期会话运行时间较短

01:43 开发者角色转变与需要替代人工监督的三个问题

过去的最佳实践主要围绕引导会话、批准命令、禁止特定操作、检查输出和启动会话,而退出循环后,这些职责需要由模型、harness 或运行环境接手。由此产生三个核心问题:在不逐条审核的情况下如何保证代码质量;长时间无人监督时如何保证安全;如何确保 Claude 做的是正确的事。演讲计划以一个旧会话为例,逐步展示需要做哪些改动。

开发效率提升的概括画面
每日变更数量从约2,500到超过30,000的数据对比
开发者关注点转变的代表画面
早期最佳实践要点概览
脱离逐条审批循环后的流程变化

02:46 使用当前默认设置:更新模型并启用自动模式

演讲者将旧会话的模型从 Opus 4.5 更新为 Opus 5.5,并把手动权限改为自动模式。Opus 5.5 更能理解意图与代码库,中途不需要频繁引导。自 8 月起,自动模式已成为默认权限模式,因此不必再逐条批准命令。这些默认设置已基本移除了大部分“在环内”的人工操作。

模型设置更新为 Opus 5.5 的操作界面

03:12 精简 CLAUDE.md:只保留 Claude 无法从代码中获知的内容

旧的 CLAUDE.md 常含“important”“never do this”和感叹号等强调语,对新模型而言不仅没有必要,还可能让模型偏离方向,导致更多工具调用和更差的结果。技术栈、代码位置等内容模型可以自行判断,无需再写。CLAUDE.md 应只保留代码中看不出来的信息,例如仍被某服务使用但代码中未直接引用的遗留数据源。运行 doctor prompt audit 命令可自动检查 CLAUDE.md 与 skills,找出新模型已不再需要的内容。

演示运行 doctor prompt audit 命令
运行该命令后自动检查 CLAUDE.md 与 skills 的过程

04:11 自动模式的分类器与配置方式

自动模式会对除读写项目文件以外的大多数操作运行独立分类器:安全的命令(如运行测试或安装依赖)自动放行,不确定的命令则被拦截。默认情况下,自动模式只信任当前文件夹和仓库,因此向 staging 环境部署等操作可能被拦截,又会让人重新回到环内。如果需要更多批准,可以在设置中用自然语言配置自动模式,说明信任哪些仓库、存储桶和域名,以及应始终允许或绝不执行的操作。这些文字会直接发送给分类器,由其决定允许或拒绝。

自动模式权限说明的开场画面
自动放行的安全命令示例
对默认分类结果的评价
默认行为符合预期的说明
把内容部署到预发布环境的操作场景

05:15 安全边界:权限规则、沙箱与子进程风险

Anthropic 的一项研究显示,人工审核时只有约 14% 的人能发现明显危险的命令,自动模式拦截了 89%,但仍约有十分之一的危险命令会通过,因此模型自身的判断不能提供绝对保证。要获得确定性保障,需要依赖 harness 中的 deny 规则:deny 规则先于分类器检查,匹配的调用根本不会被分类器看到。判断哪些需要写成规则,关键看 Claude 出错后能否撤回。代码错误可以回滚,但丢弃未提交修改或读取敏感文件(如 .env)并写入对话记录则无法挽回,应设为 deny 规则。然而 npm test 等命令会运行依赖和脚本,其副作用不受权限规则约束。此时可以开启沙箱,由操作系统限制可读文件、可写目录和可访问主机,并对子进程同样生效。不过沙箱只覆盖 Claude 执行的 shell 命令,Claude 自身文件、MCP 服务器和 hooks 仍在本机运行,且默认仍可读取大部分机器文件,需要额外配置。

人在回路与自动模式拦截危险命令的比例数据
自动模式拦截危险命令的比例数据
针对特定文件的拒绝规则示例
npm test 命令的运行示例
章节代表画面

08:53 云端会话:独立环境与网络密钥管理

在云端会话中,每个任务都有独立机器和新的仓库副本,即使笔记本合上,会话也能继续运行,适合持续数小时的任务。由于 .env 等文件不在 git 中,SSH 密钥和 GitHub token 也不在该环境内,许多本地泄露风险因此消失。若需要 API 密钥,可将其配置为网络密钥,会话中需要时模型可以使用,但不会把密钥发送给模型。云端默认只允许访问包管理源和 GitHub,其他域名需要显式添加。不过云端机器是一次性的,真正需要保留的是它推送的提交或通过连接器发出的消息,因此仍应在自动模式下使用 deny 规则,并通过提交内容让规则随仓库生效。

云端会话概念的代表性讲解画面

10:47 验证点:让 Claude 在过程中自我检查

长时间后台运行后,开发者无法再逐个查看每次修改,而同一提示词可能产生不同的实现,例如保留旧 API、只对新登录生效,或导致所有用户登出。为此需要在过程中设置验证点,即能返回通过或失败结果的检查,如测试、构建或截图。验证点比最终审查整个变更更容易审核。实现方式包括在提示词中说明完成标准、将任务拆分并附带各自测试,并要求展示实际输出,因为开发者不在场,无法亲自看到结果。

要求 Claude 展示的实际运行输出结果

12:21 Hooks:确保关键检查必然执行

提示词无法保证模型一定执行某些检查,因此需要使用 hooks,即 Claude Code 在特定时机运行的脚本。开发者可以决定其运行时机和检查内容:每次编辑文件后运行 linter,标记任务完成时运行相关测试,会话结束时运行完整测试套件。若检查失败,Claude 会返回修复。需要注意,许多工具测试失败时退出码为 1,而 Claude Code 会把这种情况当作任务已完成,因此脚本应使用退出码 2,才能真正让 Claude 返回修复。

开头说明提示词不能保证模型执行
引出 hooks 作为必定执行的检查机制
说明由用户决定 hooks 的运行时机与检查内容
编辑文件时运行 linter 的示例
标记任务完成时运行相关测试的示例

13:22 CI 与审查:将人工审核留给风险较高的变更

会话最终都会提交 PR,因此 CI 是重要的保障,它对所有会话运行相同的检查,无论会话如何设置。开启 CI auto fix 后,Claude 可以看到检查失败并自行修复,从而减少开发者需要处理的问题。对于部分任务还可开启 merge when ready,在检查全部通过后由 GitHub 自动合并。Anthropic 内部的做法是:每个 PR 先由 Claude 审查,且使用新的上下文和独立的代理组进行复核;随后根据风险决定人工审核的程度,例如文档或文案类改动无需人工,普通产品改动需一名审查者,高风险改动需两名。

讲解者强调 CI 是需要先建立的关键环节,无具体画面证据,以此句作为代表性锚点

15:04 未来方向:主会话编排子会话

演讲者认为,未来开发者不必亲自启动每个会话。可以使用一个主会话作为编排者:它将任务拆分,为每个子任务启动新会话,跟踪返回结果,并验证其是否真正完成,未完成则退回重做。主会话本身不写代码,因此适合使用擅长判断的模型(如 Fable),子会话则使用擅长执行的模型(如 Opus 5.5),两者可以分别设置。在 Claude Code projects 这类功能中,上下文的压缩与清理也由系统自动完成。演讲总结称,旧的最佳实践仍然存在,只是职责已转移:模型负责引导,自动模式负责批准,deny 规则与环境负责限制,测试、hooks 与 CI 负责检查,而 Claude 也可以启动会话;开发者只需启动第一个任务并审查结果。建议开发者先选一项远大于平时的任务,确保 CI 能检查关心的内容,配置好云端环境,再观察会话卡在哪里、哪些环节仍需人工介入。

主会话编排器的整体结构
编排器拆分任务并启动的子会话
模型、自动模式、规则与环境的分层概览

Conclusions

01:33 随着模型能力增强,开发者的角色从逐步引导和批准命令,转变为同时管理多个长时间运行的会话。

05:15 使用当前模型与默认的自动模式,就能移除大部分需要人工介入的环节,无需继续逐条批准命令。

03:37 CLAUDE.md 应只保留代码中无法体现的信息,过度强调的指令会使新模型偏离方向并导致更差的结果。

06:13 只有 deny 规则能在 harness 层面提供确定性保障,因为它会先于自动模式分类器执行,匹配的调用不会被分类器看到。

08:23 沙箱由操作系统强制执行,可以限制命令及其子进程能读取的文件、能写入的目录和能访问的主机。

09:36 云端会话在独立机器中运行,即使笔记本关闭也能继续,并且本地的 SSH 密钥和 token 不会暴露给会话。

11:40 长时间无人监督的任务需要设置验证点,并通过测试、构建或截图等通过或失败的结果来检查中间产出。

13:15 需要保证执行的检查应通过 hooks 实现,而不能只依赖提示词;hook 脚本失败时应使用退出码 2,才能让 Claude 返回修复。

14:00 CI 是所有会话的统一检查,开启自动修复和自动合并后,可以减少开发者在低风险审查上的投入。

16:40 未来的做法是由一个主会话编排多个子会话,主会话负责判断与验证,子会话负责执行,上下文管理也可自动完成。