win4r/claude-code-clawdbot
Run Claude Code (Anthropic) from this host via the `claude` CLI (Agent SDK) in headless mode (`-p`) for codebase analysis, refactors, test fixing, and structured output. Use when the user asks to use Claude Code, run `claude -p`, use Plan Mode, auto-approve tools with --allowedTools, generate JSON output, or integrate Claude Code into Clawdbot workflows/cron.
npx skills add https://github.com/win4r/claude-code-clawdbot-skill --skill claude-code-clawdbot
Use the locally installed Claude Code CLI reliably.
This skill supports two execution styles:
/speckit.* (Spec Kit), which can hang or be killed when run via headless -p.This skill is for driving the Claude Code CLI, not the Claude API directly.
Verify installation:
claude --version
Run a minimal headless prompt (prints a single response):
./scripts/claude_code_run.py -p "Return only the single word OK."
cd /path/to/repo
/home/ubuntu/clawd/skills/claude-code-clawdbot/scripts/claude_code_run.py \
-p "Summarize this project and point me to the key modules." \
--permission-mode plan
Claude Code supports tool allowlists via --allowedTools.
Example: allow read/edit + bash:
./scripts/claude_code_run.py \
-p "Run the test suite and fix any failures." \
--allowedTools "Bash,Read,Edit"
./scripts/claude_code_run.py \
-p "Summarize this repo in 5 bullets." \
--output-format json
./scripts/claude_code_run.py \
-p "Review the staged diff for security issues." \
--append-system-prompt "You are a security engineer. Be strict." \
--allowedTools "Bash(git diff *),Bash(git status *),Read"
> "Update your CLAUDE.md so you don't make that mistake again."
This ensures Claude Code records lessons learned and avoids repeating the same errors.
script(1) to force a pseudo-terminal./speckit.*) are best run in interactive mode; this wrapper can start an interactive Claude Code session in tmux.--permission-mode plan when you want read-only planning.--allowedTools narrow (principle of least privilege), especially in automation.Claude performs dramatically better when it can verify its work.
Make verification explicit in the prompt, e.g.:
npm test passes.”For multi-step work, start in plan mode to do safe, read-only analysis:
./scripts/claude_code_run.py -p "Analyze and propose a plan" --permission-mode plan
Then switch to execution (acceptEdits) once the plan is approved.
Long, mixed-topic sessions degrade quality.
/clear between unrelated tasks./compact Focus on <X> when nearing limits to preserve the right details.Claude checkpoints before changes.
If an approach is wrong, use /rewind (or Esc Esc) to restore:
This enables “try something risky → rewind if wrong” loops.
Best practice is a concise CLAUDE.md (global or per-project) for:
Overlong CLAUDE.md files get ignored.
In .claude/settings.json / ~/.claude/settings.json, rules match in order:
deny first, then ask, then allow.
Use deny rules to block secrets (e.g. .env, secrets/**).
Each Bash tool call runs in a fresh shell; export FOO=bar won’t persist.
If you need persistent env setup, set (before starting Claude Code):
export CLAUDE_ENV_FILE=/path/to/env-setup.sh
Claude will source it before each Bash command.
Use hooks to enforce deterministic actions (format-on-edit, block writes to sensitive dirs, etc.)
when you need guarantees.
Subagents can read many files without polluting the main context.
Use them for broad codebase research or post-implementation review.
Examples:
cat build-error.txt | claude -p "Explain root cause"
claude -p "List endpoints" --output-format json
This is ideal for CI and automation.
If your prompt contains lines starting with / (slash commands), the wrapper defaults to auto → interactive.
Example:
./scripts/claude_code_run.py \
--mode auto \
--permission-mode acceptEdits \
--allowedTools "Bash,Read,Edit,Write" \
-p $'/speckit.constitution ...\n/speckit.specify ...\n/speckit.plan ...\n/speckit.tasks\n/speckit.implement'
It will print tmux attach/capture commands so you can monitor progress.
When you want Claude Code to drive Spec Kit end-to-end via /speckit.*, do not use headless -p for the whole flow.
Use interactive tmux mode because:
1) Initialize Spec Kit (once per repo)
specify init . --ai claude
2) Ensure the folder is a real git repo (Spec Kit uses git branches/scripts):
git init
git add -A
git commit -m "chore: init"
3) Recommended: set an origin remote (can be a local bare repo) so git fetch --all --prune won’t behave oddly:
git init --bare ../origin.git
git remote add origin ../origin.git
git push -u origin main || git push -u origin master
4) Give Claude Code enough tool permissions for the workflow:
Recommended:
--permission-mode acceptEdits --allowedTools "Bash,Read,Edit,Write"
./scripts/claude_code_run.py \
--mode interactive \
--tmux-session cc-speckit \
--permission-mode acceptEdits \
--allowedTools "Bash,Read,Edit,Write" \
-p $'/speckit.constitution Create project principles for quality, accessibility, and security.\n/speckit.specify <your feature description>\n/speckit.plan I am building with <your stack/constraints>\n/speckit.tasks\n/speckit.implement'
The wrapper prints commands like:
tmux ... attach -t <session> to watch in real timetmux ... capture-pane ... to snapshot outputIf Claude Code asks a question mid-run (e.g., “Proceed?”), attach and answer.
If you expose a Vite dev server through ngrok, Vite will block unknown Host headers unless configured.
server.allowedHosts to be true or string[]. server: { host: true, allowedHosts: true }
server: { host: true, allowedHosts: ['xxxx.ngrok-free.app'] }
allowedHosts: 'all' (won't work in Vite 7).After changing vite.config.*, restart the dev server.
When you drive tmux via a shell command (e.g. tmux send-keys ...), avoid unescaped backticks and shell substitutions in the text you pass.
They can be interpreted by your shell before the text even reaches Claude Code.
Practical rule:
In automation environments, backgrounded vite / ngrok processes can get SIGKILL.
Prefer running them in a managed background session (Clawdbot exec background) or tmux, and explicitly stop them when done.
OpenSpec is another spec-driven workflow (like Spec Kit) powered by slash commands (e.g. /opsx:*).
In practice it has the same reliability constraints:
/opsx:* commands (avoid headless -p for the whole flow).Install CLI:
npm install -g @fission-ai/openspec@latest
Initialize OpenSpec with tool selection (required):
openspec init --tools claude
Tip: disable telemetry if desired:
export OPENSPEC_TELEMETRY=0
Inside Claude Code (interactive):
1) /opsx:onboard
2) /opsx:new <change-name>
3) /opsx:ff (fast-forward: generates proposal/design/specs/tasks)
4) /opsx:apply (implements tasks)
5) /opsx:archive (optional: archive finished change)
If the UI prompts you for project type/stack, answer explicitly (e.g. “Web app (HTML/JS) with localStorage”).
scripts/claude_code_run.py: wrapper that runs the local claude binary with a pseudo-terminal and forwards flags.Take win4r/claude-code-clawdbot from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference npm.
Without those the skill loads but fails at the first command.