I Started Using /clear After Testing with Playwright MCP
I Started Using /clear After Testing with Playwright MCP
在测试 Playwright MCP 后,我开始使用 /clear 命令
Long Story Short: After using tools like Playwright MCP that can return large tool results, continuing to work with that context still in the session can make subsequent processing heavier. Since then, when I finish testing with Playwright MCP and do not need that context for the next task, I use /clear. My rule is simple: “Will I need this context for the next task?”
简而言之:在使用像 Playwright MCP 这样会返回大量工具结果的工具后,如果继续在同一会话中保留这些上下文进行工作,会增加后续处理的负担。因此,当我完成 Playwright MCP 测试且后续任务不再需要这些上下文时,我会使用 /clear 命令。我的原则很简单:“我接下来的任务还需要这些上下文吗?”
Context
背景
Recently, I hit the usage credits limit in Claude Code, which I use at work. What confused me was that my plan usage still had plenty of room, while the additional usage credits I had configured had already reached their limit. After looking into it, I realized that Fable usage was what had caused me to go beyond the included usage and consume additional credits. That explained why the credits had run out. But it also made me ask a different question: Why was I consuming so much usage in the first place?
最近,我在工作中使用的 Claude Code 达到了使用额度上限。令我困惑的是,我的套餐额度明明还有很多剩余,但我配置的额外使用额度却已经耗尽。深入调查后,我发现是 Fable 的使用导致我超出了套餐包含的额度,从而消耗了额外额度。这解释了额度耗尽的原因,但也引发了我的另一个思考:为什么我的使用量会这么大?
Until then, I had been using Claude Code every day without paying much attention to what was actually driving my usage. So I started looking more closely at /usage and reviewing how I had been working. One thing that stood out was Playwright MCP. That did not mean Playwright MCP itself was the reason I had exceeded my usage limit. Rather, it made me notice how much context could accumulate during browser testing, and how that context could continue to affect subsequent work if I kept using the same session. The habit I eventually changed was very simple: After finishing a test with Playwright MCP, if I do not need that context for the next task, I use /clear. This article is a short learning log about how I got there.
在此之前,我每天都在使用 Claude Code,却从未关注过到底是什么在消耗我的额度。于是,我开始仔细查看 /usage 并回顾我的工作方式。其中一个引起我注意的点是 Playwright MCP。这并不是说 Playwright MCP 本身就是我超出额度的原因,而是它让我意识到在浏览器测试过程中会积累多少上下文,以及如果我一直使用同一个会话,这些上下文会如何持续影响后续的工作。我最终改变的习惯非常简单:在使用 Playwright MCP 完成测试后,如果后续任务不再需要这些上下文,我就使用 /clear。本文是我对此过程的一段简短学习记录。
Usage Is Not Just About How Many Times You Talk to Claude
使用量不仅仅取决于你与 Claude 对话的次数
I used to think about Claude Code usage in a fairly simple way: The more questions I ask, the more expensive it gets. That is not entirely wrong. But the size of the context Claude is working with also matters. Claude Code is not looking only at the latest sentence I type. It works with the context needed for the current task, including previous conversation history, files it has read, and tool results. So, if I simplify my understanding quite a bit: The larger the context is, the heavier it can become to keep processing within that context.
我过去对 Claude Code 使用量的理解相当简单:问的问题越多,成本就越高。这并不完全错误,但 Claude 处理的上下文大小同样重要。Claude Code 不仅仅是在看我输入的最后一句,它是在处理当前任务所需的整个上下文,包括之前的对话历史、已读取的文件以及工具结果。因此,如果简化一下我的理解:上下文越大,在其中进行持续处理的负担就越重。
/usage Made Me Look at Playwright MCP
/usage 命令让我关注到了 Playwright MCP
When I checked /usage, I saw results like these:
- 79% of your usage was at >150k context
- 61% of your usage came from subagent-heavy sessions
- 36% of your usage came from the MCP server “playwright”
当我检查 /usage 时,我看到了这样的结果:
- 79% 的使用量处于 >150k 的上下文规模
- 61% 的使用量来自大量使用子代理(subagent)的会话
- 36% 的使用量来自 MCP 服务器 “playwright”
At first, I thought these were three separate problems: My context was too large, I was using too many subagents, and Playwright MCP was expensive. But after looking at how I had been working, they seemed more connected than I initially thought. When using Playwright MCP for E2E checks, I repeatedly do things like: Open a page, Inspect elements, Click a button, Fill in a form, Check the state after navigation, Fix something and try again if necessary.
起初,我以为这是三个独立的问题:上下文太大、子代理使用过多、Playwright MCP 成本高。但回顾我的工作方式后,它们似乎比我最初想象的联系更紧密。在使用 Playwright MCP 进行端到端(E2E)检查时,我反复执行以下操作:打开页面、检查元素、点击按钮、填写表单、检查导航后的状态、修复问题并根据需要重试。
For Claude to understand the browser state, relatively large tool results can be added to the context during these interactions. Each individual operation may feel like a simple browser check. But after repeating them several times, browser-related context can accumulate quickly. That part can be considered a necessary cost of testing. The more interesting problem for me was what happened afterward.
为了让 Claude 理解浏览器状态,在这些交互过程中,相对较大的工具结果会被添加到上下文中。每一个单独的操作看起来可能只是简单的浏览器检查,但重复多次后,与浏览器相关的上下文会迅速积累。这部分可以被视为测试的必要成本。对我来说,更有趣的问题是之后发生了什么。
The Test Was Finished, but the Context Wasn’t
测试结束了,但上下文没有结束
From my perspective, once I reach: “Test complete. Time to move on to the next task,” much of the information generated during the Playwright session has already served its purpose. But if I continue using the same session, I also continue working with that context. For example: Implement a feature, Verify it with Playwright MCP, Confirm that it works, Start implementing another feature.
从我的角度来看,一旦我达到“测试完成,是时候进行下一个任务了”的阶段,Playwright 会话期间产生的大部分信息就已经完成了使命。但如果我继续使用同一个会话,我也会继续带着这些上下文工作。例如:实现一个功能、用 Playwright MCP 验证它、确认它能工作、开始实现另一个功能。
I used to move directly to step 4 without resetting the session. But when working on the next feature, I may no longer need all the browser information generated during the previous E2E test. There is a gap between: “This context is no longer useful to me” and: “Claude Code is no longer carrying this context.” Looking into my usage made me much more aware of that difference.
我过去通常会直接跳到第 4 步而不重置会话。但在处理下一个功能时,我可能不再需要之前 E2E 测试中产生的所有浏览器信息。“这些上下文对我没用了”与“Claude Code 不再携带这些上下文”之间存在差距。深入研究我的使用情况让我更加意识到这种差异。
After Playwright MCP Testing, I Use /clear
在 Playwright MCP 测试后,我使用 /clear
So I now follow one simple rule: After finishing a Playwright MCP test, if I do not need that context for the next task, I use /clear. I do not clear the session mechanically after every test. My rule is simply: Will I need this context for the next task? If not, I clear it.
所以我现在遵循一个简单的规则:在完成 Playwright MCP 测试后,如果下一个任务不需要这些上下文,我就使用 /clear。我不会在每次测试后机械地清除会话。我的原则很简单:我接下来的任务还需要这些上下文吗?如果不需要,我就清除它。
Conclusion
总结
When I first started using Claude Code, I tended to think of context as something that was simply better to have more of. And of course, having the right context is important. But after looking into my usage, I started thinking about the cost of keeping context that is no longer useful. This feels especially relevant with tools like Playwright MCP, where repeated browser interactions can add a lot of information to the session in a relatively short period of time. And once the test is finished, that information may no longer be useful for the next task.
刚开始使用 Claude Code 时,我倾向于认为上下文越多越好。当然,拥有正确的上下文很重要。但在查看了我的使用情况后,我开始思考保留不再有用的上下文所带来的成本。这在使用 Playwright MCP 等工具时尤为重要,因为反复的浏览器交互会在短时间内向会话中添加大量信息。而一旦测试完成,这些信息对于下一个任务可能就不再有用了。
This experience made me start thinking of Claude Code context as having a kind of lifecycle: Collect it when needed. Keep it while it is useful. Let it go when its job is done. For now, that is the rule I am following.
这次经历让我开始将 Claude Code 的上下文视为一种具有生命周期的事物:需要时收集,有用时保留,任务完成后释放。目前,这就是我正在遵循的规则。