Unofficial
On this page
  1. 01Before you start
  2. 02Start a session
  3. 03Ask for HelloPublic
  4. 04Ask for CronEdit
  5. 05The crontab rules in the code
  6. 06Review what Claude Code wrote
  7. 07Build the package
  8. 08Install and check it
  9. 09What the test showed
  10. 10Download the sources

Ask Claude Code for a QPKG: Hello world on Public and a crontab editor

Claude Code runs on your NAS in an environment of Bucket & Code Server IDE. You start a session from the panel, the editor's terminal, claude.ai/code or the phone app, and describe the package in plain words. This guide shows two real requests. HelloPublic writes "Hello world" into a file on the Public share. CronEdit puts its own lines into the NAS's crontab by QNAP's rules.

  1. Sessionin the project's folder
  2. Promptwhat the package does
  3. Reviewread and test the code
  4. Buildbvs qbuild
  5. Installand check it

The pictures come from Bucket & Code Server IDE 1.0.0-102 with the account ola. Claude Code is installed in the environment and nobody is signed in, so the session itself is shown as text. The prompts and the answers are from real Claude Code runs.

01Before you start

  • A project made by New project with the template QPKG package. It holds the skill .claude/skills/qnap-dev and AGENTS.md. Claude Code reads the skill and writes for the NAS: BusyBox sh, /etc/config, System Logs.
  • Claude Code in an environment: Toolchains → the environment → AI tools → Claude Code → Install. Then Sign in to Claude in the same dialog, with your own account.
  • A developer or admin account. Installing a package on the NAS is an admin's step.

02Start a session

Every way below starts the same Claude Code in the environment. Start it in the project's folder, so it reads the project's skill.

  • In the panel. On the Claude Code tab of AI tools, choose the project under Folder and press Start a new session. The session runs in the environment's jail and keeps running when you close the page. Terminal finds it again. AI tools in ubuntu2404-builder, the Claude Code tab: installed, Account Not signed in with Sign in to Claude, Start a session with Folder All projects and Start a new session, Continue a conversation, Session settings
  • In the editor's terminal. The link Or start it in the editor's terminal under the button opens it there. That session ends when you close the editor's tab.
  • From claude.ai/code or the Claude app. Once you are signed in, the same tab shows Remote Control: "Sessions of this environment can be started and steered from claude.ai/code and the Claude app." Turn it on, then pick this environment there.
  • From your phone. The Bucket & Code phone app, paired on the panel's Phone app page, has an AI tab. Choose the environment, the folder and the tool, then Start a new conversation.

03Ask for HelloPublic

The prompt, word for word, in the folder of a new project named HelloPublic:

This folder is a QPKG project that Bucket & Code's New project made. Make the package HelloPublic: when it starts, it writes the line "Hello world" into the text file hello.txt in the Public shared folder.

- Take the Public folder's path from QTS: getcfg Public path -f /etc/config/smb.conf. Never a fixed volume such as /share/CACHEDEV1_DATA.
- If the NAS has no Public share, the start says so in the NAS's System Logs and fails.
- Stop and uninstall leave hello.txt where it is: it is the user's file then.
- Follow the qnap-dev skill in .claude/skills.

Do not build or install anything: I build it with bvs qbuild and install it myself. At the end, tell me which files you changed, how to build it and how to check it on the NAS.

Claude Code wrote the start into shared/HelloPublic.sh. The path of Public comes from QTS, and the file is overwritten, so a second start still leaves one line:

service_start() {
  local dir file
  dir=$("$QPKG_SYS/sbin/getcfg" Public path -f "$QPKG_SYS/etc/config/smb.conf")
  if [ -z "$dir" ]; then
    qpkg_log error "this NAS has no Public shared folder (no path for [Public] in /etc/config/smb.conf); hello.txt is not written"
    return 1
  fi
  qpkg_sys "$dir"
  if [ ! -d "$QPKG_P" ]; then
    qpkg_log error "the Public shared folder $dir does not exist or its volume is not mounted; hello.txt is not written"
    return 1
  fi
  file=$QPKG_P/hello.txt
  …
  if ! echo "Hello world" >"$file"; then
    qpkg_log error "cannot write $dir/hello.txt"
    return 1
  fi
  # the user's file: not only root may change it (root writes it, with the umask 022 qpkg_init set)
  chmod 666 "$file"
  qpkg_log info "wrote \"Hello world\" into $dir/hello.txt"
}
}

Its answer, shortened. In this run Claude Code could edit files and check their syntax, but not run them, and it says so:

HelloPublic now writes "Hello world" into `hello.txt` in the Public shared folder when it starts. I haven't run it: the syntax check (`sh -n`) passes, but the test against a fake NAS folder needed your approval and wasn't run. Nothing is built, installed or committed.

## Files changed

- **`shared/HelloPublic.sh`** (the start script):
  - **Start** gets the Public folder's path from `/sbin/getcfg Public path -f /etc/config/smb.conf`, with no fixed volume anywhere. It then overwrites `hello.txt` there with the one line, so starting twice still leaves one line. It sets the file to mode 666 so other users can change it, not only root.
  - **Start fails** (exit 1, with an error in System Logs) when:
    - the NAS has no Public share;
    - Public's folder doesn't exist, for example because its volume isn't mounted. The script never creates that folder, because a folder made then would land in RAM;
    - `hello.txt` is a link or not a regular file. Public is open to every user, so this stops anyone tricking the root-run start into overwriting some other file.
  - **Stop and uninstall** don't touch `hello.txt`.
…

## Check it on the NAS

1. Install it: `qpkg_cli -m /share/<folder>/HelloPublic_0.1.0_<arch>.qpkg --keep`, or use App Center's manual install. The start runs as part of the install.
…

04Ask for CronEdit

The prompt lists QNAP's rules for cron one by one, so each rule can be found in the code afterwards:

This folder is a QPKG project that Bucket & Code's New project made. Make the package CronEdit, a small crontab editor for a QNAP NAS that follows QNAP's rules for cron:

1. The app keeps its own schedule lines in a file of its own in the package's folder, one cron line per line. A command, cronedit, manages them: cronedit add "<five time fields> <command>", cronedit list, cronedit remove <number>.
2. The lines go into /etc/config/crontab, the file that survives a restart of the NAS. Never crontab -e, never the files under /tmp/cron or /var/spool/cron.
3. Every line the app writes into /etc/config/crontab ends with the app's own tag, so its lines can always be told from the others.
4. At every start, the service script checks each of the app's lines and adds it only when /etc/config/crontab does not have it yet. A second start adds nothing: never a duplicate.
5. On stop and on uninstall it removes its own tagged lines, and only those (cleanup), including lines that are no longer in its own file.
6. After every change of /etc/config/crontab it reloads cron the QNAP way: crontab /etc/config/crontab && /etc/init.d/crond.sh restart. When nothing changed, it does not reload.
7. It never changes, moves or removes a line it did not write.
8. cronedit add and cronedit remove change the app's file and, while the app is started, bring /etc/config/crontab in line at once, by the same rules.

Follow the qnap-dev skill in .claude/skills (the NAS has BusyBox and no bash; cron runs commands with a short PATH).

Do not build or install anything: I build it with bvs qbuild and install it myself. At the end, tell me which files you changed, how to build it and how to check it on the NAS.

The answer, shortened:

I've written CronEdit, but **I haven't run it.** Running scripts needed an approval this session didn't give, so the only check was a syntax check with `sh -n`, which passed for both scripts. Everything else comes from reading the code. A test script for a fake NAS file tree is in `build/t/run.sh` (git ignores `build/`), so you can run it with `sh build/t/run.sh`. Nothing is committed.

## Files changed
- **`shared/bin/cronedit`** (new, POSIX `sh` for BusyBox): the `add`, `list` and `remove <number>` commands, plus `sync`, `cleanup` and `check`, which the service script calls.
  - **Its own file:** the lines live in `<install folder>/cronedit.tab`. The package doesn't ship that file, so an upgrade can't overwrite it.
  - **Tag:** every line it writes into `/etc/config/crontab` ends in `# managed-by:CronEdit`. It rejects a line that is badly formed, starts with `@reboot` or `#`, contains the tag, or ends in `\`. It also rejects a line that is already in its file.
  - **Other lines are safe:** before it replaces `/etc/config/crontab`, it checks that every untagged line is still there, unchanged and in the same order. If not, it leaves the file alone. It keeps a backup while writing and puts it back if the write fails.
  - **Reload:** it runs `crontab /etc/config/crontab && /etc/init.d/crond.sh restart` only when lines were actually added or removed.
  - **Started or stopped:** `add` and `remove` update `/etc/config/crontab` straight away only while the package is started. While it's stopped, the change waits for the next start.
  - A command that doesn't start with `/` gets a note that cron's PATH is short.
- **`shared/CronEdit.sh`**: the service script, written by hand on top of `lib/bvs-qpkg.sh`.
  - **start:** runs `sync`, which adds only the missing lines, so a second start adds nothing. It also removes tagged lines that are no longer in `cronedit.tab`, and links `/usr/bin/cronedit`.
  - **stop and remove (uninstall):** run `cleanup`, which removes every tagged line and only those.
  - **status:** runs `check`.
  - **Switched-off package:** if a start is refused because the package is off, it still removes the tagged lines first, in case a power cut skipped the stop.
…

**One thing for you:** deleting the template placeholder `shared/bin/CronEdit` needed an approval I didn't get, so it's still there. It does no harm, but you can remove it with `git rm shared/bin/CronEdit`.

05The crontab rules in the code

CronEdit keeps its lines in cronedit.tab in the package's folder. The program bin/cronedit writes them into /etc/config/crontab, the file that outlives a restart. Each line it writes ends with the tag, and it changes only lines that end with it:

TAG_WORD='managed-by:CronEdit'
TAG="# $TAG_WORD" # the end of every line CronEdit writes; a user's line may not hold TAG_WORD
SYS=${BVS_QPKG_SYSROOT-}
CONF=$SYS/etc/config/qpkg.conf
CRONTAB=$SYS/etc/config/crontab

One awk pass makes the new file. It keeps every line without the tag where it is. Of the tagged lines it keeps the first copy of each line the package wants and drops the rest, also lines that left cronedit.tab. Wanted lines the file lacks go at its end:

  changes=$(awk -v tag="$TAG" -v out="$new" "$AWK_OURS"'
    FILENAME == ARGV[1] { if (!($0 in want)) { want[$0] = 1; order[++n] = $0 }; next }
    ours($0) {
      if (($0 in want) && !($0 in seen)) { seen[$0] = 1; print > out } else { dropped++ }
      next
    }
    { print > out }
    END {
      for (i = 1; i <= n; i++) if (!(order[i] in seen)) { print order[i] > out; added++ }
      print dropped + 0, added + 0
    }' "$want" "$old")

When nothing was added or dropped, the file stays as it is and cron is not restarted:

  set -- $changes
  DROPPED=${1:-0}
  ADDED=${2:-0}
  if [ "$DROPPED" = 0 ] && [ "$ADDED" = 0 ]; then
    rm -f "$new"
    return 0
  fi

Before it writes, a second awk pass checks that every line without the tag is still there, unchanged and in the same order. Otherwise the file is left alone. After a write, cron is reloaded the QNAP way:

reload() {
  # on the NAS: /usr/bin/crontab /etc/config/crontab && /etc/init.d/crond.sh restart
  if "$SYS/usr/bin/crontab" "$CRONTAB" && "$SYS/etc/init.d/crond.sh" restart >/dev/null 2>&1; then
    return 0
  fi
  say "the reload of cron failed (crontab /etc/config/crontab && /etc/init.d/crond.sh restart)"
  event 2 "the reload of cron failed (crontab /etc/config/crontab && /etc/init.d/crond.sh restart)"
  return 1
}

The service script calls it: start brings the file in line, stop and remove (the uninstall) take out every tagged line. A start that App Center's switch refuses takes them out too, in case a power cut skipped the stop:

service_start() {
  # the command on PATH; a file of another at /usr/bin/cronedit is left alone, and bin/cronedit still works
  qpkg_link "$CRONEDIT" /usr/bin/cronedit || :
  "$CRONEDIT" sync
}

service_stop() {
  "$CRONEDIT" cleanup
  qpkg_unlink /usr/bin/cronedit "$CRONEDIT"
  return 0
}
…
service_remove() {
  "$CRONEDIT" cleanup
  qpkg_unlink /usr/bin/cronedit "$CRONEDIT"
  return 0
}

# A switched-off package's start is refused by qpkg_start; its tagged lines must not run either (a power cut skips
# the stop), so they go first.
if [ "${1-}" = start ] && ! qpkg_enabled; then
  "$CRONEDIT" cleanup
fi

While the package is started, cronedit add and cronedit remove change cronedit.tab and bring /etc/config/crontab in line at once. While it is stopped, the change waits for the next start.

06Review what Claude Code wrote

Read the diff, then run what the session could not. For CronEdit that is its own test on a fake NAS tree, sh build/t/run.sh. It passed. The review changed these things:

  • CronEdit: the template's bin/CronEdit is gone. Nothing ran it, and its name differs from bin/cronedit only in case: on Windows or macOS one file overwrites the other. Claude Code had noticed it, but deleting it needed an approval. The README's two lines about it now describe bin/cronedit.
  • HelloPublic: no code change.
  • The install. The answer says to install with qpkg_cli -m … --keep. For an unsigned package that installs nothing on QTS 6.1: qpkg_cli -s answers "notfound". Section 08 shows what installs it.

07Build the package

On the project's page, Build runs bvs qbuild in the project's build environment. In a terminal, in the project's folder, the command is the same:

bvs qbuild
ls build/
CronEdit_0.1.0_x86_64.qpkg  CronEdit_0.1.0_x86_64.qpkg.md5
The project's steps after Build: Build done with Build again and Rebuild; Test deploy off, Needs a code-signed package; under them: a test deploy needs a code-signed package, and this build has no signature

Without a code-signing certificate in the project the package is unsigned, and Test deploy stays off: "Needs a code-signed package". A signed build installs with Test deploy; the App Center guide shows how to sign.

08Install and check it

To try an unsigned build on your own NAS, copy the file into a shared folder and run it over SSH as admin. QTS installs it and starts it:

# over SSH as admin, in the shared folder that holds the file
cd /share/Public/packages
sh ./CronEdit_0.1.0_x86_64.qpkg
…
Link service start/stop script: CronEdit.sh
Set QPKG information in /etc/config/qpkg.conf
CronEdit: started
  • A package installed this way has no Status line in /etc/config/qpkg.conf. App Center's own installs write Status = complete.
  • Do not switch on App Center's setting for apps without a valid digital signature for these packages. Sign them instead.
  • Remove a package in App Center or with qpkg_cli -R CronEdit.

HelloPublic, after its start:

P=$(getcfg Public path -f /etc/config/smb.conf)
cat "$P/hello.txt"
Hello world

CronEdit, with two lines added while it runs:

cronedit add "*/15 * * * * /bin/true"
cronedit: added: */15 * * * * /bin/true
cronedit: /etc/config/crontab: 1 line(s) added, 0 removed
cronedit add "* * * * * /bin/date -u >> /share/Public/cronedit-demo.txt"
cronedit: added: * * * * * /bin/date -u >> /share/Public/cronedit-demo.txt
cronedit: /etc/config/crontab: 1 line(s) added, 0 removed
cronedit list
CronEdit is started; its lines (/share/CACHEDEV1_DATA/.qpkg/CronEdit/cronedit.tab):
1  */15 * * * * /bin/true
2  * * * * * /bin/date -u >> /share/Public/cronedit-demo.txt
grep -n 'managed-by:CronEdit' /etc/config/crontab
57:*/15 * * * * /bin/true # managed-by:CronEdit
58:* * * * * /bin/date -u >> /share/Public/cronedit-demo.txt # managed-by:CronEdit
/etc/init.d/CronEdit.sh status
CronEdit: Enable = TRUE
CronEdit: started
CronEdit: every line of /share/CACHEDEV1_DATA/.qpkg/CronEdit/cronedit.tab is in /etc/config/crontab, once: yes

09What the test showed

We saved /etc/config/crontab (58 lines) on a NAS with QTS 6.1 before the install, and compared the file with that copy after every step.

Step/etc/config/crontab afterwardsCron restarted
install, no lines yetthe saved copyno
two cronedit add while startedtwo tagged lines moreyes, after each
stopthe saved copy, byte for byteyes
startthe two lines backyes
start againunchanged, no line twiceno
a line taken out of cronedit.tab while the stop never ran, as after a power cut, then startthat line gone, the other one keptyes
cronedit add, then cronedit remove, while startedthe line in, then outyes, after each
qpkg_cli -R CronEditthe saved copy, byte for byte; crontab -l the sameyes
  • After every step the 58 other lines were the saved ones, in the same order.
  • The line * * * * * /bin/date -u >> /share/Public/cronedit-demo.txt wrote its first time stamp within a minute: cron runs the tagged lines.
  • QTS's crond.sh start moves its own vs_refresh and backup_conf.sh lines to the end of the file after crontab has loaded it. So while CronEdit's lines are in, crontab -l can list the same lines in another order than the file.
  • HelloPublic: after a start hello.txt held Hello world, after a second start still one line. Stop and uninstall left it in Public.

10Download the sources

ai-qpkg-examples.zip (170 KB) holds both projects as the review left them, the two prompts, and a README that names what Claude Code wrote and what the review changed. Copy a project into your projects folder and build it with bvs qbuild.