返回 Skill 列表
extension
分类: 开发与工程无需 API Key

claude-code-oneshot

运行Claude代码进行深度编码会话 - 一次性执行,无需来回调整。适用于具有大量上下文但易于验证的复杂任务。

person作者: jakexiaohubgithub

Claude Code One-Shot

For deep coding sessions that need lots of context and are straightforward to test. One-shot execution — no questions, no help, just results.

When to Use

  • Complex refactoring or feature implementation
  • Tasks with clear success criteria (tests pass, script runs, etc.)
  • Delegating work that would bloat your context
  • Parallel task execution across worktrees

Basic Usage

# One-shot task (exits when done)
claude --print "Your detailed task here" --dangerously-skip-permissions

# In a specific directory
cd /path/to/project && claude --print "Build X" --dangerously-skip-permissions

Key Flags

| Flag | Purpose | |------|---------| | --print "prompt" | One-shot mode, exits when complete | | --dangerously-skip-permissions | Auto-approve all file/command operations |

Prompt Style

Be explicit. Tell it exactly what to do and NOT to do:

claude --print "Create fizzbuzz.sh that prints FizzBuzz 1-30. Make it executable. ONE SHOT - no questions, just implement it." --dangerously-skip-permissions

Key phrases:

  • "No questions, just do it"
  • "ONE SHOT"
  • "Do NOT ask for clarification"

Background Execution

For longer tasks, run in background with PTY:

# Start in background
exec pty:true background:true workdir:~/project command:"claude --print 'Build a REST API for todos' --dangerously-skip-permissions"

# Monitor progress
process action:log sessionId:XXX

# Check completion
process action:poll sessionId:XXX

Parallel Tasks with Worktrees

For multiple independent tasks:

# Create worktrees
git worktree add -b feat/auth /tmp/auth-work main
git worktree add -b feat/api /tmp/api-work main

# Run Claude Code in each (parallel)
cd /tmp/auth-work && claude --print "Implement OAuth2 login" --dangerously-skip-permissions &
cd /tmp/api-work && claude --print "Add REST endpoints for users" --dangerously-skip-permissions &

# Wait for both
wait

NixOS Note

Claude Code may generate #!/bin/bash shebangs. Fix with:

sed -i '1s|#!/bin/bash|#!/usr/bin/env bash|' script.sh

Rules

  1. Verify results — run the code, check the tests, confirm it works
  2. Clear prompts — ambiguity leads to questions or wrong output
  3. Isolated workspaces — don't run in your main project directory for risky tasks
  4. Git init required — Claude Code needs a git repo to operate