
Anthropic在Claude Code推出实验性Code Mode
来源标题:Coding agents leave me wondering what code will do. Haskell solved it years ago
Anthropic已在Claude Code中推出实验性Code Mode,让代理编写JavaScript调用工具、处理结果并返回所需信息。该功能可减少模型往返和上下文中的中间数据,并支持并行执行独立操作。Code Mode从2.1.323版本起可用。
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
Code Mode raises a familiar question for us at Keller: how can agents work with fewer interruptions while we retain control over their actions? Some longstanding ideas from programming languages offer a useful starting point.
Anthropic recently introduced experimental Code Mode in Claude Code. The idea is straightforward: the agent writes JavaScript that calls its tools, processes the results, and returns the information it needs. It can put a loop or a conditional in that code instead of coming back to the model for every decision. The feature is available from version 2.1.323. Anthropic’s documentation explains the current behavior.
The benefits are practical: fewer model round trips, less intermediate data in context, and opportunities to run independent operations in parallel. Code can handle the bookkeeping between calls. The speedup depends on the task, but work that previously required another model response can often proceed directly. Anthropic described the broader approach in its earlier article on code execution with MCP.
As coding agents become more capable, the way we handle permissions becomes increasingly important. How can we let them work at full speed, with fewer interruptions for us, while keeping our systems safe?
For us, a recurring concern is the point where an agent interacts with an external system. Reading a document, changing a file, or sending data to a service requires a decision about whether that action is appropriate. You may be comfortable letting an agent write the code while still wanting control over those effects.
Some tasks required my agents to work outside the sandbox and make changes on my host computer. I wanted to approve those actions, but switching windows to find each prompt and understand it kept interrupting my work. I built Agent Dock, inspired by AgentPeek, to bring Claude Code and Codex permission requests into a macOS menu-bar panel.
Bringing the prompt into view reduces the interruption, but you still have to understand the proposed action.
The choice can feel like a toggle. Broad permission lets the agent proceed, including with actions you might not have intended. Requiring approval for sensitive operations preserves your opportunity to intervene, but repeatedly draws your attention back to the task. More selective rules help, though you still have to decide which categories of action to authorize in advance.
Click anywhere on the toggle to switch approaches. Off means ask about each sensitive action; on means grant broad permission. You can also use Space, Enter, or the left and right arrow keys. This illustration does not change any agent permissions.
JavaScript is off. Both approaches are shown below; enable JavaScript to switch between them.
You can judge each action in context, but must repeatedly interrupt other work.
The work continues without your involvement. An unwanted action may only become apparent afterward.
Code Mode still pauses for individual tool calls that need your approval under your permission settings. Auto mode already has a classifier review the whole snippet before execution, while deny rules, ask rules, and tool hooks still apply to individual calls. This already makes a group of operations the subject of a single review. The distinction is documented here.
We are interested in what that review could establish before execution. Alongside an assessment of the code, could the snippet carry a concise, machine-checked statement of its permitted effects?
One part of the answer comes from capability security. A capability gives its holder authority to perform particular operations on a particular resource. An open file handle that permits reading is a useful example. Possessing it lets the program read that file; it need not confer permission to open every other file on the machine.
For an agent, imagine a small service window. It can ask for a document through that window and hand back an edited version. There is no door beside it that opens onto your entire computer. In software terms, that means the program must have no alternate route through a shell, raw filesystem access, or another tool with broader authority.
Agent-written programYour computer
Isolation boundary
Granted interface
Read project documents
Project documents✓ Read access Replace an approved file
Approved file✓ Replacement allowed
Contact a server
No network capability Run a shell command
No shell capability Loops and branches can change. The available opening stays the same.
Allowed actions pass through a service window Read and replace arrows pass through the open window to your computer. Contacting a server and running a shell command stop at crosses on the wall.
Agent-writtenprogramYourcomputer
Grantedinterface
Read projectdocuments
Projectdocuments✓ Read Replace anapproved file
Approvedfile✓ Replace Contacta server
Run a shellcommand
✓ Granted operation× No capability granted
The open window represents the granted interface. Reads and approved replacements pass through; network and shell operations have no route through the wall. This illustrates a proposed restricted environment: the boundary must cover every route to the host, not just the named tools.
This has a long history. Capsicum brought capability-based compartmentalization to Unix applications. Deno provides a familiar, related example of explicit permissions: a program can be granted reads under one directory or network access to one host. Its permissions are shared by code on the same thread, so that is not the same as giving each library its own object capabilities. Deno’s security documentation makes this scope clear.
Mobile apps have made restricted access familiar too. Android and iOS combine application sandboxes with permissions or entitlements. These are related approaches to limiting authority; neither should be described simply as a pure capability system.
Linux has several relevant mechanisms with different meanings. Linux capabilities, such as CAP_NET_ADMIN, divide privileges traditionally associated with root. They are not object capabilities for individual documents or URLs.
Landlock lets an unprivileged process restrict its own access and that of its descendants. It is a practical way to reduce ambient filesystem and other rights. There was also a Capsicum port to Linux; that page describes an experimental port against Linux 3.11.1, not a claim that ordinary Linux installations provide FreeBSD’s Capsicum API.
These are useful places to look for enforcement. They answer different questions from a type checker, which can examine how a program uses the interface before execution.
Code Mode is not itself the complete boundary pictured above. Its shell sandbox does not isolate the JavaScript or its non-shell tool calls. Anthropic documents that distinction.
Confinement gives us a place to enforce permissions. We also need a way to describe a particular piece of work inside that boundary. “This program can read documents” is useful. “This program can update only documents it has already read” gives you a more specific basis for approval.
I became interested in Haskell years ago and attended conferences and a meetup in Boston. I read the monad tutorials too, including the burrito analogies and the posts explaining why those analogies were unhelpful. I was the intended audience for both.
One idea from that period is especially relevant here: a function’s type can tell you something about what it is allowed to do before you run it.
The claim in the title concerns the underlying techniques. Haskell did not solve coding-agent permissions twenty years ago, but it provided ways to separate effects and enforce abstraction boundaries that we can apply to this problem. Some of the foundations are older still: Launchbury and Peyton Jones described type-enforced encapsulation of mutable state in 1994. The examples below show how those ideas can inform agent permissions.
Let's consider a simple function that counts words:
wordCount :: String -> Int wordCount text = length (words text)
:: introduces the type. String → Int means the function takes text and returns an integer.
There is no file read in that signature. The caller supplies the text. In Haskell’s safe language subset, this function cannot open a file or send the text to a server. It can compute, fail, or run forever, but it cannot perform those external operations.
readFile :: FilePath -> IO String
This is the standard operation’s type. IO String describes an action that can return text when executed.
IO makes the distinction visible, but it is broad. A function returning IO Int could read a file, write one, or make a network request before returning its number. The type does not tell you which of those operations it uses. Haskell’s I/O model gives us the first separation; a narrower interface supplies the next one.
We can define an interface with just a read operation, and write our function against that:
class Monad m => CanRead m where readText :: FilePath -> m String
countFile :: CanRead m => FilePath -> m Int countFile path = do text <- readText path pure (wordCount text)
Illustrative library interface and client code. The examples show the relevant types and omit the trusted tool implementations; they are not a complete sandbox.
CanRead is a type class: an interface that an execution environment can implement. The variable m stands for that environment’s computation type. The part before ⇒ says what the function requires. In plain language, the function can produce a word count in any environment that supports file reading.
The body shows the sequence. do groups the actions; <- names the value returned by one; pure returns a result without adding an external operation.
The Monad constraint lets us chain actions and feed a result into the next step. It does not itself provide a file writer or a network client.
Suppose the agent inserts writeText path "" into this function. If writeText requires a separate CanWrite m constraint, the body no longer fits the declared type. The checker rejects it. The function has to work for any permitted m that supports reading, including environments that have no writer.
This guarantee depends on restricting agent code to approved imports and trusted implementations of these operations. It cannot also get arbitrary IO, an unsafe escape hatch, or the ability to redefine what a trusted operation does. Safe Haskell exists to help preserve type and module boundaries when code is untrusted. Compiling an arbitrary Haskell project with unrestricted build steps would not establish this boundary.
Within that setup, the signature gives us a checked upper bound. It says reading is available to this function. It does not say the function will read exactly once, or that every permitted read would be appropriate.
Suppose you are writing an article and ask an agent to find a few sources on a topic and save a local note with excerpts. Search once; if there are no results, try a broader query. Fetch up to three results and write the note.
In the style of Code Mode, the orchestration could look like this. These are illustrative tool names, not Anthropic’s API:
let hits = await tools.search("Haskell capability security"); if (hits.length === 0) { hits = await tools.search("typed effects security"); }
const excerpts = []; for (const hit of hits.slice(0, 3)) { const page = await tools.fetchPage(hit); excerpts.push(excerpt(page)); } await tools.writeReport(render(excerpts));
excerpt and render only process text. writeReport targets one file selected by the host, such as notes/haskell-sources.md.
The equivalent Haskell program keeps the same branch and loop. Its signature lists the three capabilities it requires:
gatherSources :: (CanSearch m, CanFetch m, CanWriteReport m) => m () gatherSources = do first <- search "Haskell capability security" hits <- if null first then search "typed effects security" else pure f
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。
