# Example 02: Shell Execution and File I/O **Capability:** Claude Code runs shell commands and reads/writes files as part of the same task. Shell output becomes input to the next step automatically. **OpenClaw equivalent:** `exec` tool with PTY support + read/write/edit file tools. > **Building on Example 01.** You produced `research-output.md` with raw research data. This example shows how Claude organizes files and runs shell commands. In the Cumulative Path below, you turn that raw research into a structured report directory. --- ## The Prompt ``` Create a directory called 'project-scaffold', add these files inside it: 1. package.json with name "my-project", version "0.1.0", and description "A scaffolded project created by Claude Code" 2. README.md with a project overview section and a "Getting Started" section with placeholder install instructions 3. .gitignore for Node.js (node_modules, .env, dist, .DS_Store) Then run 'find project-scaffold -type f' to verify all three files exist and show me the contents of package.json. ``` --- ## What Happens Claude Code will: 1. Use Bash to run `mkdir project-scaffold` 2. Use Write to create each of the three files 3. Use Bash to run `find project-scaffold -type f` and capture the output 4. Use Read to show the contents of `package.json` 5. Report back with the directory tree and file verification --- ## Expected Output You should see Claude use 5 tool calls in sequence. The final output includes a directory tree and file contents: ``` project-scaffold/package.json project-scaffold/README.md project-scaffold/.gitignore ``` And the package.json contents: ```json { "name": "my-project", "version": "0.1.0", "description": "A scaffolded project created by Claude Code" } ``` **How you know it worked:** - A `project-scaffold/` directory exists with 3 files inside - You saw Bash (mkdir), Write (x3), Bash (find), and Read tool calls - No permission prompts appeared for these safe operations (they are pre-approved in settings.json) --- ## Why This Matters Shell execution and file I/O are the foundation of every automation. Claude Code handles both in the same task context, so shell output can feed directly into file content decisions. The permission system controls what shell commands are allowed. In the `settings.json` in this repo, `rm -rf` and a handful of other destructive patterns are blocked by the `pre-tool-use.sh` hook before execution reaches the shell. See `examples/09-security-hooks/` for details. --- ## Carry Forward You now know how to create directories, write files, verify structure, and read back content. Every example from here uses this foundation: - **Example 03** writes enriched research files with source attribution - **Example 05** writes memory files that persist across sessions - **Example 10** writes pipeline output and execution logs --- ## The Cumulative Path > If you ran Example 01, you have `research-output.md`. This prompt turns > it into a structured report. ``` Read research-output.md. Create a directory called 'pipeline-output/research-report/' and organize the research into three files: 1. README.md - topic overview, date researched, number of items found 2. findings.md - the research content reformatted with proper headings, one section per item 3. sources.md - all URLs and references extracted into a clean list Then run 'find pipeline-output/research-report/ -type f' to verify all three files exist. Show me the contents of README.md. ``` After running this, your raw research is organized into a report that agents can work with in later examples. --- ## Now Try It Yourself Replace the demo scaffold with a project structure you actually need: ``` Create a directory called '[your-project-name]/' with: 1. [file 1 with specific content] 2. [file 2 with specific content] 3. [file 3 with specific content] Verify the structure and show me [the most important file]. ``` **The pattern you just learned:** describe the directory structure + file contents + verification step. Claude creates it all in one pass and confirms. Ideas worth trying: - A blog post draft with frontmatter and image placeholders - A report template with sections matching your company format - A project kickoff folder with charter, timeline, and stakeholder list