@papaoloba/nightly-code-orchestrator
Automated 8-hour coding sessions using Claude Code - a comprehensive npm package that enables unattended development work.

Overview
The Nightly Code Orchestrator transforms your development workflow by automating coding sessions while you sleep. Define tasks in simple YAML files, and wake up to completed features, fixed bugs, and comprehensive reports.
Key Features
- 🤖 Automated 8-hour coding sessions using Claude Code
- 📋 YAML/JSON task management with dependency resolution
- 🔀 Advanced git integration with automatic branching and PR creation
- 📝 Commit message convention for task tracking
- ✅ Comprehensive validation system for code quality
- 📊 Detailed reporting and notifications
- ⏰ Cross-platform scheduling (cron, Task Scheduler)
- 🔒 Security-first approach with sandboxing options
- 🏗️ Production-ready with extensive error handling
- 🧠 SuperClaude integration for automatic prompt optimization
- ✨ Automatic improvements when tasks complete early with time remaining
Quick Start
Installation
npm install -g @papaoloba/nightly-code-orchestrator
npm install --save-dev @papaoloba/nightly-code-orchestrator
Prerequisites
- Node.js 18 or higher
- Claude Code CLI installed and configured
- Git repository
- GitHub CLI (optional, for automatic PR creation)
Initialize Your Project
If installed globally:
cd your-project
nightly-code init
code nightly-code.yaml nightly-tasks.yaml
nightly-code validate
nightly-code run --dry-run
nightly-code schedule
If installed locally as a dev dependency:
cd your-project
npx nightly-code init
code nightly-code.yaml nightly-tasks.yaml
npx nightly-code validate
npx nightly-code run --dry-run
npx nightly-code schedule
Note: When installed locally, you can either:
Configuration
Session Configuration (nightly-code.yaml
)
session:
max_duration: 28800
time_zone: "UTC"
max_concurrent_tasks: 1
checkpoint_interval: 300
project:
root_directory: "./"
package_manager: "npm"
test_command: "npm test"
lint_command: "npm run lint"
build_command: "npm run build"
setup_commands:
- "npm install"
git:
branch_prefix: "nightly/"
auto_push: true
create_pr: true
pr_template: ".github/pull_request_template.md"
notifications:
email:
enabled: false
slack:
enabled: false
superclaude:
enabled: false
planning_mode: intelligent
execution_mode: assisted
task_management: hierarchical
integration_level: deep
Task Definition (nightly-tasks.yaml
)
version: "1.0"
tasks:
- id: "implement-user-auth"
type: "feature"
priority: 8
title: "Implement User Authentication System"
requirements: |
Implement a complete user authentication system with:
1. User registration with email verification
2. Login with JWT tokens
3. Password reset functionality
4. Protected routes middleware
Use bcrypt for password hashing and follow security best practices.
acceptance_criteria:
- "User can register and receive verification email"
- "Login returns valid JWT token"
- "Protected routes reject unauthenticated requests"
- "Password reset flow works end-to-end"
- "All security tests pass"
minimum_duration: 180
dependencies: []
tags: ["backend", "security", "authentication"]
files_to_modify:
- "src/auth/"
- "src/middleware/"
- "test/auth/"
custom_validation:
script: "./scripts/validate-auth.js"
timeout: 300
enabled: true
- id: "fix-memory-leak"
type: "bugfix"
priority: 9
title: "Fix Memory Leak in Data Processing"
requirements: |
Investigate and fix memory leak in data processing module.
Memory usage increases by ~50MB/hour during operation.
Issue appears related to event listeners not being cleaned up.
acceptance_criteria:
- "Memory usage remains stable during extended operation"
- "Event listeners are properly cleaned up"
- "Unit tests verify proper cleanup"
- "Application can run 24+ hours without issues"
minimum_duration: 90
dependencies: []
tags: ["bugfix", "performance", "memory"]
files_to_modify:
- "src/processors/"
enabled: true
CLI Commands
nightly-code init
Initialize configuration in the current repository.
nightly-code init
nightly-code init --force --template python
npx nightly-code init
npx nightly-code init --force --template python
Options:
--force, -f
- Overwrite existing configuration
--template, -t
- Use predefined template (node, python, go)
nightly-code run
Execute a coding session manually.
nightly-code run
nightly-code run --max-duration 240 --dry-run
nightly-code run --resume checkpoint-123
npx nightly-code run
npx nightly-code run --max-duration 240 --dry-run
npx nightly-code run --resume checkpoint-123
Options:
--config, -c
- Path to configuration file
--tasks, -t
- Path to tasks file
--max-duration
- Maximum duration in minutes
--dry-run
- Validate without executing
--resume
- Resume from checkpoint
nightly-code schedule
Set up automated scheduling.
nightly-code schedule
nightly-code schedule --cron "0 22 * * *" --timezone "America/New_York"
npx nightly-code schedule
npx nightly-code schedule --cron "0 22 * * *" --timezone "America/New_York"
Options:
--cron, -c
- Cron expression for scheduling
--timezone, -t
- Timezone for scheduling
--dry-run
- Show what would be scheduled
nightly-code status
Check the last session results.
nightly-code status
nightly-code status --verbose --json
npx nightly-code status
npx nightly-code status --verbose --json
Options:
--verbose, -v
- Show detailed information
--json
- Output in JSON format
nightly-code validate
Validate current configuration and environment.
nightly-code validate
nightly-code validate --fix
npx nightly-code validate
npx nightly-code validate --fix
Options:
--config, -c
- Path to configuration file
--tasks, -t
- Path to tasks file
--fix
- Attempt to fix common issues
nightly-code describe
Describe work to be done in natural language and generate optimized nightly-tasks.yaml
file.
nightly-code describe "Implement user authentication with email verification"
nightly-code describe --interactive
nightly-code describe --file tasks.txt
npx nightly-code describe "Fix the memory leak in data processing"
npx nightly-code describe --interactive
Options:
--output, -o
- Output file path (default: nightly-tasks.yaml)
--interactive, -i
- Interactive mode for entering multiple tasks
--file, -f
- Read descriptions from a text file
--append
- Append to existing tasks file instead of overwriting
Examples:
-
Simple task description:
nightly-code describe "Fix the critical bug in payment processing"
-
Complex feature with details:
nightly-code describe "Implement user authentication system with:
- Email and password registration
- JWT token generation
- Password reset functionality
- Email verification
- Protected routes middleware"
-
Load multiple tasks from file:
nightly-code describe --file task-descriptions.txt
-
Interactive mode:
nightly-code describe --interactive
The AI will automatically:
- Detect task type (feature, bugfix, refactor, test, docs)
- Assign appropriate priority based on keywords (critical, urgent, high, etc.)
- Extract relevant tags from the description
- Estimate duration based on complexity indicators
- Generate acceptance criteria
- Identify files that may need modification
nightly-code report
Generate and view session reports.
nightly-code report
nightly-code report 2024-01-15 --format markdown
nightly-code report --last 5 --output report.json
npx nightly-code report
npx nightly-code report 2024-01-15 --format markdown
npx nightly-code report --last 5 --output report.json
Options:
--format, -f
- Output format (json, markdown, table)
--output, -o
- Output file path
--last
- Show last N sessions
Advanced Usage
Programmatic API
const { Orchestrator, TaskManager } = require('@papaoloba/nightly-code-orchestrator');
const orchestrator = new Orchestrator({
configPath: 'custom-config.yaml',
tasksPath: 'custom-tasks.yaml',
maxDuration: 14400
});
orchestrator.run()
.then(result => {
console.log(`Session completed: ${result.completedTasks}/${result.totalTasks} tasks`);
})
.catch(error => {
console.error('Session failed:', error);
});
const taskManager = new TaskManager();
const tasks = await taskManager.loadTasks();
const ordered = await taskManager.resolveDependencies(tasks);
Automatic Code Improvements
When all scheduled tasks complete successfully but time remains in the session, the orchestrator automatically triggers general code improvement tasks. This feature maximizes the value of your 8-hour coding sessions.
How It Works
- Automatic Trigger: After all tasks complete, if 5+ minutes remain in session
- Intelligent Selection: Uses SuperClaude
/sc:improve
command when available, falls back to standard improvement prompts
- Quality Focus: Automatically focuses on code quality, performance, documentation, and security
- Safe Execution: Includes validation and rollback if improvements fail
- Git Integration: Commits improvements with automatic tagging
SuperClaude Integration
When SuperClaude is enabled, automatic improvements use the optimized command:
/sc:improve --scope project --focus quality --iterative --validate
This leverages the SuperClaude framework's intelligent analysis and improvement patterns.
Configuration
Automatic improvements can be controlled via configuration:
session:
max_duration: 28800
auto_improvements: true
min_improvement_time: 300
superclaude:
enabled: true
Dry Run Mode
In dry run mode, automatic improvements are logged but not executed:
npx nightly-code --dry-run
Custom Validation Scripts
Create custom validation scripts for specific requirements:
const { spawn } = require('child_process');
async function validateAuth() {
console.log('Running authentication validation...');
const audit = spawn('npm', ['audit', '--audit-level', 'high']);
await new Promise((resolve, reject) => {
audit.on('close', code => code === 0 ? resolve() : reject());
});
const tests = spawn('npm', ['test', '--', '--grep', 'auth']);
await new Promise((resolve, reject) => {
tests.on('close', code => code === 0 ? resolve() : reject());
});
console.log('Authentication validation passed!');
}
validateAuth().catch(error => {
console.error('Validation failed:', error);
process.exit(1);
});
GitHub Actions Integration
name: Nightly Code Session
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
jobs:
nightly-code:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Nightly Code
run: npm install -g @papaoloba/nightly-code-orchestrator
- name: Run Nightly Code Session
run: nightly-code run --max-duration 240
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Docker Integration
# Dockerfile.nightly
FROM node:18-alpine
# Install system dependencies
RUN apk add --no-cache git openssh-client
# Install Claude Code and Nightly Code
RUN npm install -g claude-code @papaoloba/nightly-code-orchestrator
# Set up working directory
WORKDIR /workspace
# Copy configuration
COPY nightly-code.yaml nightly-tasks.yaml ./
# Set up git configuration
RUN git config --global user.name "Nightly Code Bot" && \
git config --global user.email "nightly@example.com"
# Run nightly session
CMD ["nightly-code", "run"]
Task Types and Templates
Feature Tasks
For implementing new functionality:
- id: "add-payment-integration"
type: "feature"
priority: 7
title: "Add Stripe Payment Integration"
requirements: |
Integrate Stripe payment processing with:
- Payment form with validation
- Webhook handling for payment events
- Error handling and retry logic
- Invoice generation
acceptance_criteria:
- "Payment form accepts credit cards"
- "Successful payments create invoices"
- "Failed payments show appropriate errors"
- "Webhook events are processed correctly"
minimum_duration: 240
tags: ["backend", "payments", "integration"]
Bug Fix Tasks
For resolving issues:
- id: "fix-search-performance"
type: "bugfix"
priority: 8
title: "Fix Slow Search Performance"
requirements: |
Search queries are taking 5+ seconds on large datasets.
Investigation shows missing database indexes and inefficient queries.
Root causes:
- No index on search columns
- N+1 query problem in results
- No query result caching
acceptance_criteria:
- "Search completes in under 500ms"
- "Database queries are optimized"
- "Caching reduces repeat query time"
minimum_duration: 120
tags: ["bugfix", "performance", "database"]
Refactoring Tasks
For improving code structure:
- id: "extract-service-layer"
type: "refactor"
priority: 4
title: "Extract Business Logic to Service Layer"
requirements: |
Controllers have become too large with business logic mixed in.
Extract to dedicated service classes for better separation of concerns.
Goals:
- Thin controllers focused on HTTP concerns
- Testable service classes
- Consistent error handling
- Improved code organization
acceptance_criteria:
- "Controllers are under 100 lines each"
- "Business logic is in service classes"
- "Service classes have 90%+ test coverage"
- "All existing functionality still works"
minimum_duration: 180
tags: ["refactor", "architecture"]
Git Integration and Commit Convention
Commit Message Convention
Nightly Code uses a structured commit message convention for tracking task completion. This provides better integration with standard git workflows and improved searchability.
Convention Format
<type>(<scope>): <description> [task:<task-id>]
<body>
Task-ID: <task-id>
Task-Title: <full task title>
Task-Type: <feature|bugfix|refactor|test|docs>
Task-Status: completed
Task-Duration: <duration in seconds>
Task-Session: <session-id>
Task-Date: <ISO timestamp>
Example Commits
Single Commit Task:
feat(auth): implement user login [task:auth-001]
Implemented JWT-based authentication with refresh tokens.
Task-ID: auth-001
Task-Title: Implement user authentication system
Task-Type: feature
Task-Status: completed
Task-Duration: 3600
Task-Session: session-2024-01-20-120000
Task-Date: 2024-01-20T12:00:00Z
Multi-Commit Task:
# Progress commits
feat(ui): add dashboard layout [task:ui-005] [1/3]
feat(ui): implement dashboard widgets [task:ui-005] [2/3]
# Final commit
feat(ui): complete dashboard implementation [task:ui-005] [3/3]
Finalized dashboard with all widgets and responsive design.
Task-ID: ui-005
Task-Title: Create user dashboard with analytics widgets
Task-Type: feature
Task-Status: completed
Task-Duration: 7200
Task-Session: session-2024-01-20-090000
Task-Date: 2024-01-20T11:00:00Z
Finding Task Commits
git log --grep="\[task:" --oneline
git log --grep="\[task:auth-001\]"
git log --grep="Task-Status: completed" --pretty=format:"%h %s %ad" --date=short
git log --grep="Task-Status: completed" --pretty=format:"%h|%s|%ad" --date=short > tasks.csv
Git Hook Installation
Install the commit-msg hook to validate task commits:
cp node_modules/@papaoloba/nightly-code-orchestrator/hooks/commit-msg .git/hooks/
chmod +x .git/hooks/commit-msg
The hook validates:
- Proper commit format for task completions
- Required metadata in commit footer
- Task ID format and consistency
- Conventional commit compliance
Security and Safety
Sandboxing
Enable sandbox mode for additional security:
security:
sandbox_mode: true
allowed_commands:
- "npm"
- "node"
- "git"
blocked_patterns:
- "rm -rf"
- "sudo"
- "curl"
max_file_size: 10485760
File Access Control
Restrict file modifications:
tasks:
- id: "safe-task"
files_to_modify:
- "src/components/"
- "test/"
Command Validation
All commands are validated before execution:
- Commands must be in the allowed list (if specified)
- Blocked patterns are rejected
- File size limits are enforced
- Network access can be restricted
Performance and Monitoring
Resource Monitoring
The orchestrator continuously monitors:
- CPU usage - Warns if consistently above 90%
- Memory usage - Alerts on excessive memory consumption
- Disk space - Ensures adequate space for operations
- Network connectivity - Validates access to required services
Checkpointing
Automatic checkpoints every 5 minutes (configurable) include:
- Current task state
- Completed/failed tasks
- Resource usage history
- Git branch information
- Time elapsed
Performance Metrics
Each session tracks:
- Tasks completed per hour
- Average task duration
- Time utilization percentage
- Error rate
- Resource efficiency
Troubleshooting
Common Issues
"Claude Code CLI not found"
npm install -g claude-code
claude-code --version
"Configuration validation failed"
nightly-code validate
npx nightly-code validate
nightly-code validate --fix
npx nightly-code validate --fix
"Git repository not found"
git init
git add .
git commit -m "Initial commit"
"Task dependencies cannot be resolved"
Check for circular dependencies:
tasks:
- id: "task-a"
dependencies: ["task-b"]
- id: "task-b"
dependencies: ["task-a"]
Dependency-Aware Branching
Nightly Code now supports intelligent Git branching that respects task dependencies. When a task depends on another task, it will automatically branch from the dependency's branch instead of main, ensuring all dependent code is available.
How It Works
- Independent Tasks: Branch from main as usual
- Dependent Tasks: Branch from the last dependency's branch
- Missing Dependencies: Fall back to main with a warning
Example workflow:
main
└─ task/setup-db (Task A)
└─ task/create-api (Task B depends on A)
└─ task/add-tests (Task C depends on B)
Configuration
Control dependency branching behavior in nightly-code.yaml
:
git:
dependency_aware_branching: true
merge_dependency_chains: false
strict_dependency_checking: false
Task Dependencies Example
tasks:
- id: "setup-database"
type: "feature"
title: "Set up database schema"
requirements: "Create initial database tables and migrations"
dependencies: []
- id: "create-api"
type: "feature"
title: "Create REST API"
requirements: "Implement CRUD endpoints for database entities"
dependencies: ["setup-database"]
- id: "add-authentication"
type: "feature"
title: "Add authentication"
requirements: "Implement JWT authentication for API"
dependencies: ["create-api"]
- id: "add-tests"
type: "test"
title: "Add integration tests"
requirements: "Test API endpoints with authentication"
dependencies: ["create-api", "add-authentication"]
Debug Mode
Enable detailed logging:
export NIGHTLY_CODE_LOG_LEVEL=debug
nightly-code run --verbose
npx nightly-code run --verbose
Log Files
Logs are stored in .nightly-code/logs/
:
nightly-code.log
- General application logs
sessions.log
- Detailed session logs
scheduler.log
- Scheduling and cron logs
Best Practices
Task Design
- Be Specific: Write detailed requirements and acceptance criteria
- Keep Tasks Focused: Aim for 1-3 hours per task
- Define Dependencies: Clearly specify task relationships
- Include Validation: Add custom validation scripts for complex tasks
- Test Thoroughly: Ensure acceptance criteria are testable
Configuration Management
- Version Control: Commit configuration files to git
- Environment Specific: Use different configs for dev/staging/prod
- Secret Management: Use environment variables for sensitive data
- Regular Validation: Run
nightly-code validate
after changes
Security Guidelines
- Principle of Least Privilege: Only allow necessary commands
- Regular Updates: Keep dependencies and tools updated
- Code Review: Review generated code before merging
- Backup Strategy: Maintain regular backups of important data
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/papaoloba/nightly-code-orchestrator.git
cd nightly-code-orchestrator
npm install
npm test
npm run test:watch
npm run lint
npm run build
Running Tests
npm test
npm run test:coverage
npm test -- orchestrator.test.js
npm run test:watch
License
MIT License - see LICENSE file for details.
Support
Changelog
See CHANGELOG.md for version history and updates.
Transform your development workflow with automated coding sessions
Made with ❤️ by the Paolo Barbato