Most Claude Code users run it interactively — ask a question, get a response, confirm an action, repeat. That’s the right starting point. But once you know which tasks you run repeatedly on the same repository, you can script them.
Scripted Claude Code calls let you automate the repetitive, predictable parts of repository maintenance: adding missing frontmatter fields, fixing formatting across multiple files, generating file lists, running validation passes. These become one-line commands instead of multi-step interactive sessions.
Quick Answer: Claude Code supports non-interactive mode via
--no-confirmflags, which let you call it from shell scripts and pipe its output. For batch operations — running the same task across multiple files — wrap Claude Code calls in a shell loop with a task template. The key constraint: non-interactive mode works best for well-defined, idempotent tasks. Avoid using it for tasks that require judgment on edge cases.
How Claude Code’s non-interactive mode works
Standard Claude Code usage is interactive: it prompts you to confirm before making changes. Non-interactive mode bypasses that loop.
The key flags:
claude --print "your task description"
--print sends the task and prints the response to stdout without starting an interactive session. Useful for read-only queries: “list all files missing the slot field” outputs a list you can use in the next step.
claude --no-confirm "your task description"
--no-confirm applies changes without asking for confirmation. Use carefully — errors apply immediately without a review step.
For batch operations, the pattern is:
- Use
--printto generate a list or plan - Review the output manually or pipe it to a check
- Use
--no-confirmonly after confirming the task is well-defined
A basic shell script for batch frontmatter fixes
Scenario: you have 20 blog posts missing the slot field in their frontmatter. You want to add slot: morning to each one.
#!/bin/bash
# fix-missing-slot.sh
# Adds slot: morning to all .md files missing a slot field
BLOG_DIR="src/content/blog"
for file in "$BLOG_DIR"/*.md; do
if ! grep -q "^slot:" "$file"; then
echo "Adding slot field to: $file"
claude --no-confirm "Add 'slot: morning' to the frontmatter of $file, immediately after the 'draft:' line. Do not change any other content."
fi
done
echo "Done. Review changes with: git diff src/content/blog/"
This script:
- Iterates over every
.mdfile in the blog directory - Checks if the file has a
slot:field - If not, calls Claude Code to add it
- Prints the file name for each change made
The git diff at the end is your review step. Run the script, then inspect what changed before committing.
A script for description length validation and fixing
Scenario: some posts have descriptions over 160 characters. You want to identify them and shorten each one.
#!/bin/bash
# fix-long-descriptions.sh
# Finds and shortens descriptions over 160 characters
BLOG_DIR="src/content/blog"
for file in "$BLOG_DIR"/*.md; do
desc=$(grep "^description:" "$file" | sed 's/description: "//' | sed 's/"//')
len=${#desc}
if [ "$len" -gt 160 ]; then
echo "[$len chars] $file"
claude --no-confirm "The description field in $file is $len characters, which exceeds the 160-character limit. Shorten it to under 160 characters while preserving the core meaning. Do not change any other field."
fi
done
This script uses shell string length to check description length before passing to Claude Code. Only files with violations get a Claude Code call — keeping API usage minimal.
Piping Claude Code output for decision logic
For more complex workflows, you can pipe --print output into shell logic.
#!/bin/bash
# audit-missing-fields.sh
# Checks all posts and lists those missing required fields
REQUIRED_FIELDS=("slot" "cluster" "keyword" "ogImage")
BLOG_DIR="src/content/blog"
for file in "$BLOG_DIR"/*.md; do
missing=()
for field in "${REQUIRED_FIELDS[@]}"; do
if ! grep -q "^${field}:" "$file"; then
missing+=("$field")
fi
done
if [ ${#missing[@]} -gt 0 ]; then
echo "$file: missing ${missing[*]}"
fi
done
This one doesn’t call Claude Code at all — it uses shell logic for the check. Call Claude Code only when you need it to generate content or make file edits. For validation and auditing, shell logic is faster and doesn’t consume API tokens.
Safety practices for batch automation
Always review before committing. End every batch script with git diff and review the output before git commit. Batch errors apply to multiple files simultaneously.
Scope tasks narrowly. The more specific the task instruction, the more predictable the output. “Add slot: morning after the draft: line” is safer than “fix the frontmatter.”
Run on a subset first. Before running a batch script on 50 files, run it on 3–5 files. Verify the output looks correct, then run on the full set.
Use version control as your undo. If a batch operation goes wrong, git checkout -- src/content/blog/ reverts all changes to the last commit. This is your safety net.
Log what you changed. Append change logs to a temp file during the run. After reviewing, you have a record of what was modified.
Integrating batch scripts into a publishing pipeline
For a daily publishing pipeline, batch automation is most useful at the validation stage. Before the CI/CD workflow runs, a validation script can:
- Check all draft posts for missing fields
- Verify description lengths
- Confirm slot fields match the publishing schedule
- Flag any file that hasn’t been committed in the current batch
Run this as a pre-commit hook or as the first step of the GitHub Actions workflow. If validation fails, the workflow aborts before attempting to publish.
For setup context on Claude Code’s interactive capabilities, see what Claude Code is and how it fits a non-developer’s workflow. For the broader question of which AI dev tools suit operators, see best AI dev tools for non-developers.
Frequently Asked Questions
Does Claude Code batch mode cost more in API tokens?
Yes — each claude call consumes tokens. For large batches (50+ files), token costs add up. Mitigate by using shell logic for simple checks and calling Claude Code only for tasks that require language understanding.
Can I run these scripts in GitHub Actions?
Yes, with setup. You need to install Claude Code in the runner and provide an API key as a GitHub secret. The same claude --no-confirm commands work in CI environments.
What’s the difference between —no-confirm and —dangerously-skip-permissions?
--no-confirm skips the per-action confirmation prompt but still respects permission settings. --dangerously-skip-permissions removes permission guardrails entirely. Use --no-confirm for scripts; avoid --dangerously-skip-permissions unless you have full control of the environment.
How do I handle errors in batch mode?
Claude Code exits with a non-zero status code on error. In shell scripts, use set -e to abort on first error, or check $? after each call and log failures to a file.
Can I schedule these scripts to run automatically? Yes — via cron (local) or GitHub Actions (cloud). For a daily publishing pipeline, scheduled batch scripts run automatically and push results to the repository.
Explore AI tools for operators
If you’re building out an operator stack that includes Claude Code alongside other tools, the tools overview covers the full landscape with affiliate context — so you can evaluate and compare without starting from scratch.