DeepSeekDSH
中文GitHub
Menu
Independent community guideNot affiliated with DeepSeek.Download versions and guide references

Run Scheduled Tasks & Cron Jobs with DeepSeek Harness (DSH)

Automate recurring audits, daily summaries, and repository checks by combining system cron or Task Scheduler with DSH headless mode.

On this page
Quick summary: which scheduler to pick?

For reliable, unattended recurring runs with clean logs, use cron / systemd timer + dsh --profile headless. Keep experimental in-app background loops for interactive desktop sessions.

Compare scheduling approaches

Match your scheduling method to the host where DSH runs:

MethodBest forStrengthsWatch-outs
Linux/macOS cron + Headless CLIServers, NAS, Docker hosts, daily repo digestsFresh process per run, predictable memory & log filesExport explicit PATH and DSH_HOME in script
Windows Task Scheduler + CLIAlways-on Windows workstationsNative OS trigger without keeping a browser openVerify workspace permissions and shell PATH
Experimental background tasksActive Desktop or Web UI sessionsQuick setup directly inside chatStops if the app closes; varies by preview build
Step 1

Verify a standalone Headless script first

Always test your command manually before adding it to cron. Save a wrapper script such as run-dsh-job.sh with explicit PATH and DSH_HOME paths:

#!/usr/bin/env bash set -euo pipefail

export PATH="/usr/local/bin:/usr/bin:/bin:$PATH" export DSH_HOME="/home/youruser/.dsh" export DEEPSEEK_API_KEY="sk-your-key"

cd /path/to/your-workspace dsh --profile headless "Inspect git status and commits from the last 24h, then write a concise summary to reports/daily.md"
>> /var/log/dsh-cron.log 2>&1

Keep API keys out of plain scripts

In production, load keys from a chmod 600 env file (source /.dsh.env) or rely on saved credentials inside DSH_HOME/.credentials.yaml.

Step 2

Wire it into cron with overlap protection

Once bash run-dsh-job.sh succeeds manually, schedule it in three steps:

  1. 01

    Make the script executable

    Run chmod +x /path/to/run-dsh-job.sh so cron does not fail with Permission denied.

  2. 02

    Add a crontab entry

    Run crontab -e and add a schedule, e.g. daily at 9:00 AM: 0 9 * * * /path/to/run-dsh-job.sh.

  3. 03

    Prevent overlapping runs

    Wrap the command with flock -n /tmp/dsh-job.lock so a slow run never collides with the next trigger.

Step 3

Set three guardrails for unattended runs

Because nobody is clicking approval dialogs during a cron run, define strict boundaries up front:

Use a dedicated workspace

Point scheduled jobs to an isolated folder or separate Git branch rather than your primary checkout.

Bound token spend

Scope prompts to specific files and output lengths, and set monthly spending limits in your API provider console.

Capture full logs

Redirect both stdout and stderr to a log file so failed runs are immediately diagnosable.

Avoid destructive unattended actions

Never instruct scheduled runs to force-push, delete databases, or overwrite unbacked directories. Have the agent write a draft report or branch for human review instead.

Scheduled tasks FAQ

Why does cron say dsh: command not found when manual runs work?

Cron runs with a minimal PATH and skips shell profiles like /.bashrc or nvm. Check which dsh and export the full Node 24 bin directory inside your script.

Can I schedule DSH jobs inside Docker?

Yes. Trigger docker compose run --rm dsh dsh --profile headless ... from your host crontab while reusing the persistent dsh_home volume. See the Docker guide.

Will headless cron runs interfere with my Web UI?

headless and web are separate profiles. Keep their target workspaces separate so a background job does not edit the same file you have open interactively.

NEXT STEPExplore Headless flags and exit behavior
Headless mode guide →
Sources & scope

Profile isolation and headless invocation follow the DSH CLI behavior reference, checked .