2025-05-22 | Anthropic | Mastering Claude Code in 30 minutes

Claude Code实用技巧:Anthropic专家助你精通AI编程

媒体详情

上传日期
2025-06-30 14:21
来源
https://www.youtube.com/watch?v=6eBSHbLKuN0
处理状态
已完成
转录状态
已完成
Latest LLM Model
gemini-2.5-pro

转录

下载为TXT
speaker 1: Hello everyone, I'm Boris. I'm a member of technical staff here at anthropic and I created quad good and here to talk to you a little bit about some practical tips and tricks for using quad code. It's gonna to be very practical. I'm not gonna to go too much into the history or the theory or anything like this. And Yeah before we start, actually can we get a quick show fans who has used quad code before? Yeah, all right. That's what we like to see for everyone that didn't raise your hands. I know you're not supposed to do this while people are talking, but if you can open your laptop and type this. And this will help you install quad code just so you can follow along for the rest of the talk. All you need is no js. If you have a, this should work. Yeah if have you don't have to follow along, but if you don't have it yet, Yeah this is your chance to install it so you can follow along. So what is quad code? Cloud code is a new kind of AI assistant. And there's been different generations of AI assifor coding. Most of them have been about completing like a line at a time, completing a few lines of code at a time. Qud code is not for that. It's fully agengentic. So it's meant for building features, for writing entire functions, entire files, fixing entire bugs at the same time. And what's kind of cool about quad code is it works with all of your tools and you don't have to change out your workflow. You don't have to swap everything to start using it. So whatever ide use, if you use vs code, or if you use Xcode, or if you use jet brains ids, there are some people had anthropic that you can't prive them from their cold, dead hands, but they use quad code because quad code works with every single ID, every terminal out there, itwork locally over remote ssh, over tmuwhatever environment you're in, you can run it. It's general purpose. And this is something where if you haven't used these kind of free form coding assistance in the past, it can be kind of hard to figure out how to get started because you open it up and you just see a prompt R and you might wonder like, what do I do this? What do I type in? It's a power tool, so you can use it for a lot of things, but also because it can do so much, we don't try to guide you towards a particular workflow because really you should be able to use it however you want as an engineer. As you open up quad code for the first time, there's a few things that we recommend doing to get your environment set up. And these are pretty straightforward. So run terminal seup. This will give you shift enter for new lines so you don't have to do like backsplashes enter new lines. This is, you know, it makes it a little bit nicer to use do slash theme to set light mode or dark mode or deltonzed themes. You can do slash install GitHub app. So today, once we announced a GitHub app where you can mention Claude on any GitHub issue or pull request. So to install, we'll just run this command in your terminal. You can customize the set of allowed tools that you can use so you're not prompted for it every time. This is pretty convenient for stuff that I'm prompted about a bunch. I'll definitely customize it in this way so I don't have to accept it every time. And something that I actually do is for a lot of my prompts, I won't hand type them into a cloud code. If you're on mac os, you can go into your system settings under accessibility as dictation, and you can enable it. And so something I do is you just hit like the dictation key twice, and you can just speak your prompt. And it helps a lot to have specific prompts. So this is actually pretty awesome. You can just talk to quad code and like you would another engineer, and you don't have to type a lot of code. So when you're starting out with cloud code, it's so freeform and it can do everything. What do you start with? The thing I recommend above everything else. So starting with code base Q&A. So just your asking questions to your code base. This is something that we teach new hires at anthropic. So on the first day in technical onboarding, you wern about quad code. You download it, you get it set up, and then you immediately start asking questions about the code base. And in the past, when you're doing technical onboarding, it's something that taxes the team a lot. You have to ask other engineers on the team questions. You have to look around the code, and this takes a while. You have to figure out how to use the tools. This takes a long time. With quad code, you can just ask quad code and itexplore the code base, itanswer these kind of questions. And so ananthropic onboarding use to take about two or three weeks. For technical hires, it's now about two or three days. What's also kind of cool about Q&A is we don't do any sort of indexing. So there's no remote database with your code. We don't upload it anywhere. Your code stays vocal. We do not train generative models on the code. So it's there. You control it. There's no indices or anything like this. And what that means is also, there's no setup. So you start clad, you download it, you start it, there's no indexing. You don't have to wait. You can just use it right away. This is a technical talk. So I'm going to show some very specific prompts and very specific code samples that you can use and hopefully improve and uplevel your quad code experience. So some kind of questions that you can ask is, you know how is this particular piece of code used or how do I instantiate this thing? And qud code, it won't just do like a text search and try to answer this itoften go a level deeper and ittry to find examples of how is this class instantiated, how is it used, and itgive you a much deeper answer. So something that you would get out of a wikier documentation instead of just like command f, something that I do a lot also is ask it about git history. So for example, why does this function have 15 arguments? And why are the arguments named this weird way? And this is something I've bet in all of our code bases, you have some function like this or some class like this, and cloud code can look through git history and itlook to figure out how did these arguments get introduced and who introduced them and what was the situation. What are the issues that those commits linked to and itlook through all this and summarize it. And you don't have to tell with that in all this detail. You just ask it. So just say, look through git history. And I don't know to do this. The reason it knows it, by the way, is not because we prompted it to, there's nothing in the system prompt about looking through git history. It knows it because the motto is awesome. And if you tell it to use git, don't know how to use git. So we're lucky to be building on such a good model. I often ask about GitHub issues so it can use webfetch, and they can fetch issues and woup context on issues too. And this is pretty awesome. And this is something that I do every single Monday in our weekly stand up, is I ask, what did I ship pped this week? And quad code books for the log knows my username. And itjust give me a nice readout of everything I shipped. And I'll just copy and paste that into a doswimer. So Yeah, that's tip number one for people that have not used cloud code before. If you're just showing it to someone for the first time, onboarding your team, the thing we definitely recommend is start with code debased Q&A. Don't start by using fancy tools. Don't start by editing code. Just start by asking questions about the code base and thatteach people how to prompt and itstart, teaching them this boundary of like, what can clad code do? What is it capable of versus what do need to hold this hand with dth little bit more? What can be one shoted? What can be two shotted three shoted? What do you need to use interactive mode for in a reppple? Once you're pretty comfortable with Q&A, you can dive into editing code. This is the next thing. And the cool thing about any sort of agengentic, you know, like using lm in an agenent tic way, is you give it tools and it's just like magical. It figures out how to use the tools. And with quad code, we give it a pretty small set of tools. It's not a lot. And so it has a tool to edit files. It has a tool to run dash commands. It has a tool to search files and itstring these together to explore the code, brainstorm, and then finally make edits. And you don't have to prompt it specifically to use this tool in this tool. And this tool, you just say, you know, do this thing and itfigure out how to do it, itstring it together in the right way. That makes sense for quad code. There's a lot of ways to use this. Something I like to do sometimes is before having Claude jump in to write code, I'll ask it to brainstorm a little bit or make a plan. This is something we highly recommend. And something I see sometimes is people, you know, they take quad code and they ask it, Hey, implement this enormous, like 3000 wine feature. And sometimes it gets this right on the first shot, but sometimes what happens is the thing that a build is not at all the thing that you want. And the easiest way to get the result you want is ask it to think first. So brainstorm ideas, make a plan, run it by me, ask for approval before you write code. And you don't have to use plan mode. You don't have to use any special tools to do this. All you have to do is ask clag and itknow to do this. So just say, before you write code, make a plan. That's it. This is also, I want to think with this one, this commit postsphere, this is a really common incantation that I use. There's nothing special about it, but quad is kind of smart enough to interpret this. So itmake a commit, itpush it to the branch, make a branch, and then make a pull request from your on GitHub. You don't have to explain anything itlook through the code, itlook through the history, itlook through the git log by itself to figure out the commit format and all the stuff, and itmake the commit and push it the right way. Again, we're not system prompting to do this. It just knows how to do this. The model was good. As you get a little bit more advanced, you're going to want to start to plug in your teams tools. And this is where quad code starts to really shine. And there's generally two kinds of tools. So one is bash tools. And an example of this, I just made up this like barley cli. This isn't a real thing, but you can say use the cli to do something, and you can tell quad code about this, and you can tell it to use, for example, like dash dash help to figure out how to use it. And this is efficient if you find yourself using it a lot. You can also dump this into your quad md, which we'll talk about in a bit. So quad can remember this across sessions. But this is a common pattern we follow at anthropic, and we see external customers used too. And same thing with mcp. Quad code can use bash tools. You can use mcp tools. So you just tell it about the tools, and you can add mcp tool, and you can tell it how to use it, and itjust start using it. And this is extremely powerful, because when you start to use code on a new code base, you can just give it all of your tools, all the tools your team already uses for this code base. And cocode can use it on your. There's a few common workflows, and this is the one that I talked about already. So kind of do a little bit of expiration, do a little bit of planning and ask me for confirmation before you start to write code. These other two on the right are extremely powerful when Clauda has some way to check its work. So for example, by writing untests or screenshotting and puppeteer or screenshotting, the iOS simulator, then it can iterate. And this is incredible because if you give it, for example, a mock and you say, build this web ui itget it pretty good. But if you had to iterate two or three times, often, it gets it almost perfect. So the trick is give it some sort of tool that it can use for feedback to check its work, and then based on that, it will iterate by itself and you're going to get a much better result. So whatever your domain is, if it's unit test or integration test or screenshots for apps or web or anything, just give it a way to see its result and ititerate and get better. So these are the next tips, teach quad how to use your tools and figure out the right workflow. If you want quad to jump in a code, if you want it to brainstorm a little bit, make a plan, if you want to iterate, kind of have some sense of that. So you know how to prompt quad to do what you want. As you go deeper beyond tools, you want to start to give Claude more context. And the more context, the smarter the decisions will be. Because as an engineer working in a good ways, you have a ton of context in your head about your systems and all the history and everything else. There's different ways to give this to Claude. And as you give clad more context, itdo better. There's different ways to do this. The simplest one is what we call quad md. And quad md is the special file name. The simplest place to put it is in the project route. So the same director, you start quad in, put a qumd in there, and thatget automatically read into context at the start of every session. And essentially, the first user turn will include the quad md. You can also have a local qulot md. And this one, you don't usually check into source control. So qumd, you should check into source control share with your team so that you can write it once and share it with your team. This one, you don't check in. It's just for you the kinds of things you put in quatmd. It's like common bash commands, common mcp tools, architectural decisions, important files, anything that you would kind of typically need to know in order to work in the school base. Try to keep it pretty short because if it gets too long, it's just going to use up a bunch of context and it's usually not that useful. So just try to keep it as short as you can. And for example, in arco base, we have common on bash commands. We have a style guide. We have a few core files, kind of things like that. Although other quad mds, you can put them in other nested child directories and Claude will pull them in on demand. So these are the qumds that will get pulled in automatically. But then also you can put quadmds in nested directories and those will get automatically pulled when quad works in those directories. And of course, if you're a company, maybe you want a qumd that's shared across all the different code bases and you want to manage it on behalf of your users and you can put it in your enterprise route and thatget pulled in automatically. There's a ton of ways to pull in context. I actually had a lot of trouble putting this fight together just to communicate the breadth of ways you can do this. But quatum d is pulled in automatically. You can also use flash commands. So this is dark quad slash commands. And this can be in your home directory, or it can be checked into your project. And this is for sh commands. And over here, we have a few examples of the slash commands that we have in cloud code itself. And so for example, if you're in the cloud code repo and you see issues getting labeled, that's actually this workflow running here. It's labeled GitHub issues. And we have a GitHub action running the same one we talked about this morning, where crod code will run this command. And it's just a splash command, itrun and itwaive, all the issues. So humans don't have to. It just saves us a bunch of time. And of course, you can add mention files to pull them into context. And like I said before, quad md's in an nested directory get pulled in when quad works in that directory. So give quad more context, and it's definitely worth taking the time to tune context. If you can run it through a prompt improver, consider who the context is for. If you want to put it in every time, if you want na put it in on demand, if you want to share it with a team, if it's a personal preference, definitely take the time to tune it. This will improve performance dramatically if you do it right. As you get more advanced, you're going to want to think about this a little bit more, this kind of hierarchy of different ways to pull in everything. So like not just quatum d, but also config and kind of everything about quad, you can pull in in this hierarchical way. So projects are specific to your git repo. And this you can check in or you can make it just for you. You can also have global configs that are across all your projects, or you can have enterprise policies. And this is essentially a global config that you row up for all of your employees, everyone on your team automatically. And the slide is like pretty information dense. But the point is this applies to a lot of stuff. So you can do this for ssh commands. You can do it for permissions. So for example, if you have a bash command that you would run for all your employees, like all your employees use this like test command, for example, you can actually just check it into this enterprise policies file. And then any employee, when they run this command, it will be auto approved, which is pretty convenient. And you can also use this to block commands. So for example, let's say there's a euro that should never be fetched. Just add it to this config and thatmake it so an employee cannot override it, and that that euro can never be fetched. So pretty convenient both to unblock people and also just to keep your code base safe. And then same thing for mcp servers. Have a mcp json file, check it into the code base. That way, anytime someone runs quad code in your code base, theybe prompted to install the mcp servers and share it with the team. If you're not sure which of these to use, this is like a kind of an insane matrix because we support a lot of stuff and engineer workflows are very flexible and every company is different. So we kind of want to support everything. So if you're not sure how to get started, I would recommend start with shared project. You write this once and then you share it with everyone on the team, and you get this kind of network effect where someone does a little bit of work and everyone on the team benefits. There's a lot of tools built into qud to manage this. So as an example, if you run slash memory, you can see all the different memory files that are getting pulled in. So maybe I have an enterprise policy, I have my user memory, I have project quadmd, and then maybe there's a nested quad md that's only pulled in for certain directories. And then similarly, when you do slamemory, you can edit particular memory files. When you type pound sign to remember something, you can pick which memory you want it to go to. So Yeah, that's the next step. Take the time to configure qumd, mcp servers, all the stuff that your team uses so that you can use it once, configure it once, and then share it with everyone. An example of this is in our apps repo for anthropic. This is like the repo that we have all of our web and apps coden. This is a puppeteer mcp server, and we share this with the team and there's a mcp jsonchecktin. So any engineer working that repo can use puppeteer in order to pilot end to end test and to screenshot automatically and iterate so that every engineer doesn't have to install it themselves. This is a talk about pro tips. So I just want to take a quick interruto talk about some common key bindings that people may not know. It's very hard to build for terminal. It's also very fun. It feels like rediscovering this new design language. But something about terminals, it's extremely minimal. And so sometimes it's hard to discover these key bindings. And here's just a quick reference sheet. So anytime you can hit shift tab to accept edits, and this switches you into auto accept edits mode. So bash commands still need approval, but edits are auto accepted and you can always ask quad to undo them later. For example, I'll do this if I know quads on the ray track, or if it's writing unit tests and iterating on tests. I'll usually just switch into auto accept mode so I don't have to ok every single item anytime you want cloud to remember something. So for example, if it's not using a tool correctly and you wanted to use it correctly from then on, just type the pound sign and then tell it what to remember and ititincorporate it into quamd automatically. If you ever want to drop down to bash mode, so just run a bash command. You can hit the exclamation mark and type in your command that run locally, but that also goes into the context window. So Claude will see it on the next turn. And this is pretty good for long running command, if you know exactly what you want to do or any command that you want to get into context and quad will see the command and the output. You can add mention thousand folders anytime you can hit escape to stop what quad is doing. No matter what quad is doing, you can always safely hit escape. It's not going to corrupt the session and it's not going to mess anything up. So maybe quad is doing a File Edit. I'll hit escape. I'll tell you what to do differently. Or maybe it suggested a 20 wedit. And I'm like, actually 19 of these lines were perfect, but one line you should change. I'll hit escape. I'll tell what that, and then I'll tell it to redo that. You can hit escape twice, to jump back in history. And then after you're done with the session, you can start quad with a resume to resume that session if you want or asdash continue. And then anytime, if you want to see more output, hit controller and thatshow you the entire output, the same thing that Claude sees in its context window. The next thing I want to talk about is the cloud code sdk. So we talked about this at the top right after this. It is doing a session, I think, just across the hallway. And he's gonna to go super deep on the sdk. If you hahim played around with us, if you use the dash p flag and claug, this is what the sdk is. And we've been wina bunch of features over the last few weeks to make it even even better. So Yeah, you can build on top of this. You can do cool stuff. This is exactly the thing that quad code uses. It's exactly the same sdk. And so for example, something you can do is claw dash p. So this is the cli sdk. You can PaaS a prompt. You can PaaS some allowed tools, which could include specific bath commands, and you can tell it which format you want. So you might want json or you might want streaming json if you want na process this somehow. So this is awesome for building on. We use this in ci all the time. We use this for incident response. We use this in all sorts of pipelines. So really convenient. Just think of it as like a unix utility. You give it a prompt, it gives you json. You can use this in any way. You can pipe into it. You can pipe out of it. The piping is also pretty cool. So you can use, like, for example, git status and pipe this in and use jq to select the result. The combinations are n of us. And it's sort of this new idea. It's like a super intelligent unix utility. And I think we barely scratch the surface of how to use this. We're just figuring this out. You can read from like a gcp bucket, read like a giant log, and pipe it in and tell quad to figure out what's interesting about this log. You can fetch data from like the sentry cli. You can also pipe it in and have quad do something about. The final thing, and this is probably like the most advanced use case as we see, I'm sort of a quad normy. So I'll have usually like one quad running at a time, and maybe I'll have like a few terminal tabs for a few different reppos running at a time. When I look at power users in and out of anthropic, almost always they're gonna to have like sa sessions, theyhave like tmux tunnels into their quad sessions. They're going to have a bunch of checkouts of the same repo so that they can run a bunch of quads in parallel in that repo, or they're using git work trees to have some kind of isolation as they do this. And we're actively working on making this easier to use. But for now, these are some ideas for how to do more work in parallel with quad. You can run as many sessions as you want and there's a lot that you can get done in parwell. So Yeah, that's it. I wanted to also leave some time for Q&A. So I think this is the last slide that I have. And Yeah if folks have questions, there's mics on both sides and Yeah welove to answer any questions. I did. Hey, worries. Thanks for building a cloud code. And I was wondering what was the hardest implementation, like part of the implementation for you of building it? I think there's a lot of tricky parts. I think one part that is especially tricky is the things that we do to make bash command safe. Bash is inherently pretty dangerous, and it can change system state in unexpected ways. But at the same time, if you have to manually approve every single bash command, it's super annoying as an engineer and you can't really be productive because you're just constantly approving every command and just kind of navigating how to do this safely in a way that scales across the different kinds of code baspeople have because not everyone runs their code in a docker container was pretty tricky. And essentially, the thing we've landed on is there's some commands that are read only. There's some static analysis that we do in order to figure out which commands can be combined in safe ways. And then we have this pretty complex tiered permission system so that you can allow list and blolist commands at different levels. Hi, Boris. You mentioned giving an image to cloud code, which made me wonder if there's some sort of multimodal functionality that I'm not aware of. Is that are you just pointing it at an image on the file system or something? Yes. So cloud code is fully multimodal. It has been from the start. It's in a terminal, so it's a little hard to discover. But Yeah, you can take an image and just drag and drop it in thatwork. You can give it a file path thatwork, you can copy and paste imain, and that works too. So I'll use this pretty often for if I have like a mock of something, I'll just drag and drop in the mock, I'll tell it to implement it, I'll give it up up a tier server so we can iterate against it. And Yeah, it's just fully automated. Okay, why did you build a cli tool instead of an ide? Yeah, it's a good question. I think there's probably two reasons. One is we started this ad anthropic. And ad anthropic people use a broad range of iand. Some people use vcode, other people use said or x code, or vim, or emacs. And it was just hard to build something that works for everyone. And so terminal is just the common denominator. The second thing is at anthropic, where we see up close how fast the model is getting better. And so I think there's a good chance that by the end of the year, people aren't using ids anymore. And so we want to get ready for this future and we want to avoid overinvesting in ui and other layers on top given that the way the models are progressing just it may not be useful work pretty soon. Yeah how much of you I don't know if is this on how much have you used pcode for machine learning modeling and almost that auto ml experience. I was curious what the experience has been so far with that. Yeah, I think I think the question was how much are we using cloud code for machine learning and modeling? We actually use it for this a bunch. So both engineers and researchers at anthropic use qud code every day. I think about 80% of people at anthropic that are technical use cloud code every day. And hopefully you can see that in the product and kind of the amount of love and dog footing we've put into it. But this includes researchers who use tools like the notebook notebook tool to edit and run notebooks. Okay, very cool. Thank you. All right. I think that's it. Thanks.

最新摘要 (详细摘要)

生成于 2025-06-30 14:28

概览/核心摘要 (Executive Summary)

Claude Code是Anthropic开发的一种新型“代理式”(Agentic)AI编程助手,旨在处理构建完整功能、编写整个文件或修复大型bug等复杂开发任务,而非简单的代码补全。其核心优势在于能与现有开发工具和工作流程无缝集成,支持VS Code、Xcode、JetBrains、Vim、Emacs等多种IDE和所有终端环境,并完全在本地运行,确保代码不被上传,保障安全与隐私。该工具通过其代理能力,能自主理解并串联使用文件编辑、运行Bash命令和搜索文件等内置工具。

Anthropic强烈推荐用户从“代码库问答”(Codebase Q&A)功能起步,该功能可显著缩短技术人员的入职时间(从2-3周缩短至2-3天)。它允许新员工直接向代码库提问,并获取关于代码用法、Git历史和相关问题的深入解答。Claude Code不进行代码索引或上传,确保了用户代码的本地性和隐私安全。

进阶用法包括:让Claude Code在编码前进行“头脑风暴”或制定“计划”以确保方向正确;通过提供单元测试、截图工具等反馈机制,使其能够自主迭代和优化代码。用户还可集成团队的Bash和MCP工具,并通过claude.md文件、斜杠命令等方式提供上下文,甚至配置分层策略来管理团队工具和权限。其SDK可作为强大的Unix工具集成到CI/CD流程中。Anthropic选择CLI而非IDE形态,是基于对AI模型快速发展可能使传统IDE过时的前瞻性判断,并强调其在内部(包括机器学习建模)的广泛应用。

Claude Code 简介与安装

Boris,Anthropic的技术人员及Claude Code的创建者,介绍了这款侧重于实用技巧的工具。

  • 定位:Claude Code被定义为“一种新型的AI助手”,区别于以往仅完成单行或几行代码补全的AI工具。
  • 核心特点
    • 完全“代理式”(fully agentic):旨在构建完整功能、编写整个文件、修复整个bug。
    • 无缝集成:与用户现有的所有工具和工作流程兼容,无需更换IDE(支持VS Code, Xcode, JetBrains, Vim, Emacs等)。
    • 环境通用性:可在本地、远程SSH或TMUX等任何终端环境中运行。
    • 通用目的工具:作为一个强大的工具,它不强制用户遵循特定工作流程,提供高度自由度。
  • 安装方式:可通过包管理器进行安装(如npm),仅需Node.js环境即可运行。

环境设置与基础操作

首次使用Claude Code时,建议进行以下环境设置以优化体验:

  • 终端设置:运行 /terminal setup 命令,启用Shift+Enter键进行换行输入。
  • 主题设置:使用 /theme 命令切换亮色、暗色或Daltonized主题。
  • GitHub应用集成:运行 /install GitHub app 命令,以便在GitHub issue或pull request中直接提及Claude。
  • 工具权限定制:可自定义允许使用的工具集,避免重复确认。
  • 语音输入(macOS):在macOS系统设置中启用听写功能,可直接语音输入提示词,尤其适合输入具体、详细的需求。

推荐的起始点:代码库问答 (Codebase Q&A)

Boris强烈推荐将“代码库问答”作为Claude Code的第一个使用场景,尤其适合新用户或团队入职培训。

  • Anthropic内部实践:新入职的技术人员在第一天就会学习并使用Claude Code进行代码库问答。
  • 显著效益
    • 减轻团队负担:减少新员工向团队成员提问的频率。
    • 加速入职进程:技术人员的入职时间从过去的2-3周缩短至2-3天
  • 数据安全与隐私
    • 无索引、无上传:不创建远程数据库或索引,用户代码始终保留在本地,不用于训练模型。
    • 即时可用:无需等待索引或设置,下载后即可立即使用。
  • 问答示例
    • 代码用法:询问“如何实例化这个对象?”Claude Code会深入分析并提供实例化和使用示例。
    • Git历史分析:询问“为什么这个函数有15个参数?”Claude Code能查阅Git历史,总结参数引入的原因、引入者及相关联的issue。Boris强调,这得益于模型自身强大的能力,而非特定的系统提示。
    • GitHub Issue上下文:利用webfetch功能获取GitHub issue的上下文信息。
    • 个人工作总结:可询问“我这周发布了什么?”Claude Code会根据Git日志和用户名,提供一份详细的发布清单。
  • 教学建议:从代码库问答开始,有助于用户理解如何有效提问以及Claude Code的能力边界。

代码编辑与迭代

熟悉问答功能后,用户可以进入代码编辑阶段。Claude Code拥有一套精简的工具集(编辑文件、运行Bash、搜索文件),并能自主串联使用。

  • 头脑风暴与计划(强烈推荐):在让Claude Code编写代码前,建议先要求它进行“头脑风暴”或“制定计划”。这有助于确保最终结果符合预期,尤其是在处理大型功能时。用户只需简单提示“在你编写代码之前,先制定一个计划”即可。
  • 自动化Git操作:通过简单的自然语言提示(如演讲者提到的“commit postsphere”[注:可能为口误或特定术语]),Claude Code能自动完成提交、创建分支并在GitHub上创建Pull Request等一系列操作。它能自行分析代码和Git日志来遵循正确的提交格式。

集成团队工具与上下文管理

为了进一步提升Claude Code的智能决策能力,用户可以集成团队的特定工具并提供更多上下文信息。

集成团队工具与优化工作流

  • 工具集成:支持集成团队自定义的Bash工具MCP工具。用户只需告知Claude Code工具的存在及其用法(如通过--help命令学习),它便能直接调用。
  • 迭代优化:通过提供反馈机制(如单元测试、Puppeteer或iOS模拟器截图),Claude Code能够检查自己的工作并进行迭代。这对于从模型构建Web UI等任务尤其有效,通过2-3次迭代通常能达到近乎完美的结果。核心技巧是:提供一个让Claude Code能够“检查其结果”的方式。

提供更多上下文

更多的上下文能帮助Claude Code做出更明智的决策。
* claude.md 文件:这是一个特殊的Markdown文件,用于提供上下文。
* 项目级 claude.md:放置在项目根目录,自动加载,建议提交到版本控制中与团队共享。
* 本地 claude.md:供个人使用,不提交到版本控制。
* 嵌套 claude.md:放置在子目录中,当Claude Code在该目录工作时按需加载。
* 企业级 claude.md:由企业统一管理,自动应用于所有员工。
* 内容建议:包含常用命令、架构决策、重要文件等核心信息,并保持简短以节省上下文空间。
* 其他方式:可通过斜杠命令(在.claude/commands中定义)和随时@mention文件来动态提供上下文。

分层配置 (高级)

Claude Code支持分层配置,以更精细地管理工具和权限。
* 配置层级:支持项目特定配置、用户全局配置和企业策略配置。
* 应用范围:可用于管理Bash命令权限(如自动批准安全命令、阻止危险命令)和MCP服务器配置等。
* 起始建议:建议从“共享项目配置”(如共享的claude.md)开始,以实现“一人配置,全员受益”的网络效应。
* 内存管理:使用/memory命令可查看所有已加载的上下文文件,并可通过#(井号)将信息存入指定内存文件。

专业技巧与快捷键

  • Shift+Tab:接受编辑并切换到“自动接受编辑”模式(Bash命令仍需批准),在迭代测试时非常有用。
  • # (井号):告诉Claude Code记住某条信息(如工具的正确用法),它会自动将其整合到claude.md中。
  • ! (感叹号):进入Bash模式,运行本地命令,其输出会进入上下文。
  • @mention:随时提及文件或文件夹,将其内容拉入上下文。
  • Escape:安全地停止Claude Code的当前操作,不会损坏会话。
  • Escape两次:回溯历史。
  • claude --resume / --continue:恢复之前的会话。
  • Ctrl+R:显示完整的上下文窗口内容。

Claude Code SDK

  • SDK介绍:通过claude -p标志使用,Anthropic内部在CI/CD、事件响应等自动化流程中广泛使用该SDK。
  • 功能:可将其视为一个“超级智能的Unix工具”。用户可以向其传递提示、允许的工具,并指定JSON等输出格式。
  • 灵活性:支持管道操作,可将其他命令(如git status)的输出通过管道传递给SDK进行处理,其应用潜力巨大。

高级用例与并行工作

资深用户通常会通过SSH会话、TMUX、多个代码库检出或Git工作树(worktrees)等方式,同时运行多个Claude Code会话以实现并行工作。Anthropic正在努力使这种并行工作模式更易于使用。

问答环节

  • 最困难的实现部分安全地执行Bash命令。解决方案是一个复杂的分层系统,具体包括:
    • 识别只读命令。
    • 进行静态分析,以确定哪些命令可以安全地组合使用。
    • 建立一个分层权限系统,允许在企业、项目或用户级别上设置命令的白名单和黑名单。
  • 多模态功能Claude Code从一开始就完全支持多模态。用户可以通过拖放、文件路径或复制粘贴的方式输入图像。例如,可以拖入一个UI模型图,要求Claude Code实现它,并结合Puppeteer进行迭代。
  • 为何选择CLI工具而非IDE集成
    • 内部多样性:Anthropic工程师使用多种IDE,CLI是所有人的共同分母。
    • 模型发展速度:Boris预测AI模型发展极快,“到今年年底,人们可能不再使用IDE了。” 团队希望为这一未来做好准备,避免在可能很快过时的UI上过度投入。
  • 在机器学习建模中的应用:Anthropic内部约80%的技术人员(包括研究人员)每天都使用Claude Code,并利用其工具(如notebook tool)来编辑和运行Jupyter Notebook。

结论

Claude Code是一款功能强大且高度灵活的“代理式”AI编程助手。它通过与现有工具链的无缝集成、对代码的本地化处理、强大的上下文理解能力以及对团队协作的支持,显著提升了开发效率。其CLI形态体现了对AI技术未来发展趋势的深刻洞察,而强大的SDK则使其能够深入集成到企业级的自动化流程中,发挥关键作用。