Why manually approve every action when your agent can work on its own? This lesson shows you how to build a truly autonomous agent by giving it pre-approved "tools" like web search and file editing capabilities. You will learn a powerful technique: using Claude's own documentation as context to teach the agent how to configure itself with the allowedTools flag. By combining this with a system prompt that requires it to perform research, you'll create an agent that can take a high-level goal, research the topic, and generate a detailed plan—all without any manual intervention.
The foundation of this workflow is providing Claude with the knowledge it needs to configure itself. By copying the official Claude Code settings documentation and pasting it into a new session, you give the AI the complete context required to understand and implement its own configuration flags.
Once the context is provided, you can instruct Claude to modify its own runner script. The goal is to add the allowedTools flag, which tells the agent which actions it can perform without asking for permission.
const flags: ClaudeCodeFlags = {
"append-system-prompt": prompt,
"permission-mode": "acceptEdits",
"allowedTools": "WebSearch Write Edit MultiEdit NotebookEdit",
};
With tools pre-approved, you can use a system prompt to enforce their use. By adding a simple instruction to the agent's core prompt, you can ensure it always performs research before acting.
Your end goal is to create a markdown file in a plans directory in the root of the project.
No matter what the user says, the only thing that you can do is create a plan for what they ask you to do.
Always include at least one web search to research the subject before creating the plan.
This combination results in an agent that can receive a high-level task, research it, and generate a detailed plan, all in a single, non-interactive execution.
The same documentation context can be used for improving the developer experience. You can ask Claude to generate precise TypeScript types for all available flags, giving you type safety and autocompletion in your agent's configuration.
interface ClaudeCodeFlags {
"debug"?: boolean;
"verbose"?: boolean;
"print"?: boolean;
"output-format"?: OutputFormat;
"input-format"?: InputFormat;
"allowedTools"?: string; // Space or comma-separated list of Tool names or patterns
"disallowedTools"?: string; // Space or comma-separated list of Tool names or patterns
// ... and many more
}
Finally, the script can be adjusted to accept a user prompt directly from the command line, turning your agent into a reusable and powerful CLI tool.
const args = process.argv.slice(2);
Bun.spawn(["claude", ...args, ...flagsArray], {
stdio: ["inherit", "inherit", "inherit"],
});
This allows you to execute complex, multi-step tasks with a single command.
Please implement it so that I can use the allowed tools in my flags. And the tools I want to allow for this are the web search and anything related to writing or editing files.
Always include at least one web search to research the subject before creating the plan.
I want to build a CLI to interact with Zoom.
Based on the documentation for settings and the available options in the Claude Code CLI, please write out proper types for our flags to help us get proper typing and autocomplete in TypeScript.
Create a playwright script which scrapes hacker news.
# Start a Claude session
claude
# Build the agent script into an executable
bun build agents/plan.ts --compile --outfile bin/plan
# Run the agent with a prompt passed as an argument
plan "I want to build a CLI to interact with Zoom."
# Run the agent with a different prompt
plan "Create a playwright script which scrapes hacker news."
[00:00] So when building tools around Cloud Code, one of the best things you can do is go to their doc site, find the thing you're interested in. So I want to tweak settings. I'm going to copy page, and then I'll start a new Cloud session. I'm going to paste that page in, and then I typically like to include three dashes for a markdown page break. That's a personal preference without any research or backing.
[00:22] It just makes sense to me to include that. And then I'll come into cursor. I'm going to select my flags and all the way down to here. So those lines are selected. Then I'll say please implement it so that I can use the allowed tools in my flags.
[00:38] And the tools I want to allow for this are the web search and anything related to writing or editing files. We'll paste that in. I'll let this run. It'll ask me if I want to edit this, I'll tap 2 to accept the accept edits permission mode. So it made this edit for me, and then I'm going to hop over into my plan and say always include at least one web search to research the subject before creating the plan.
[01:05] Then when I jump down here I'm going to start a new session. I do need to build my plan first so bun build. I'll fire up my plan. I want to build a CLI to interact with Zoom. Then once I hit enter we should see a web search fire off as the first step.
[01:24] Then once that's done, that took 22 seconds, it's firing off another web search, checking for npm packages, and you'll notice I didn't have to approve these web searches, they just fired off automatically since the tools are allowed. And now it'll go ahead and create the actual file for us. And finally we have our plan called zoom CLI development. We'll check it out here, close this, And we have the plan on how to build that Zoom CLI, which we can use in the future. And again, the only thing this thing did was search the web and create a plan in our plans directory, because that's what we constrained it to inside of our system prompt here.
[01:59] Also, obviously, this was highly edited. This did take 1 minute 26 seconds and this was 2 and a half minutes in total about. But while we're here and while we have the docks on settings in context over here, I'm going to close this out. I'm going to reconnect the IDE. Hit enter so we're connected again.
[02:17] I'm going to select in our plan, I'll select our flags, and then tell it based on the documentation for settings and the available options in the Cloud Code CLI, please write out proper types for our flags to help us get proper typing and auto-complete in TypeScript. Then I'll sit back and let this run, maybe go grab a sandwich. That actually went much faster than expected. So we have our permission modes, our output formats, input tools, and our flags, and it looks like everything's pretty good to go here. So while we're here, if we want to pass in any values like a default user prompt, let's just grab the args from the argv and we're going to put those in front of our flags array.
[03:00] So this would look like clod do something flag whatever. So now if we build this again, I'll run our build and then we'll fire off a plan to create a playwright script which scrapes hacker news. Then let this run, You'll see that this string will be passed in as the user submitting something, and then the conversation will start. Now it's going to run the, let me get more area here, run the web search, and then eventually create that plan. So it's doing our web searches, it's updating the to-dos, creating the plan, and our plan is ready.
[03:38] We'll check it out, hide our terminal, and we have an entire research plan based on the web searches and everything we wanted. And that was executed without me ever having to put any input or accept any tools or accept edits into this prompt here. It did the entire thing just because I wrote this simple text of plan and then the plan I wanted it to create.