Vraag Claude Code om een QPKG voor ‘Hello world’ op Public en een tweede QPKG als crontab-editor
Claude Code draait op je NAS in een omgeving van Bucket & Code Server IDE. Je start een sessie vanuit het paneel, de terminal van de editor, claude.ai/code of de mobiele app. Je beschrijft het pakket in gewone taal. Deze handleiding toont twee prompts uit echte sessies. HelloPublic schrijft ‘Hello world’ naar een bestand in de gedeelde map Public. CronEdit voegt zijn eigen regels toe aan de crontab van de NAS volgens de regels van QNAP.
- Sessiein de projectmap
- Promptwat het pakket doet
- Controlelees en test de code
- Bouwenbvs qbuild
- Installerenen controleren
De schermafbeeldingen komen uit Bucket & Code Server IDE 1.0.0-102 en tonen het account ola. Claude Code is in de omgeving geïnstalleerd en er is niemand aangemeld. Daarom staat de sessie zelf als tekst op de pagina. De prompts en antwoorden komen uit echte sessies met Claude Code.
01Voordat je begint
- Een project dat je aanmaakt via Nieuw project met de sjabloon QPKG-pakket. Het bevat de skill
.claude/skills/qnap-devenAGENTS.md. Claude Code leest de skill en houdt bij het schrijven van de code rekening met BusyBoxsh,/etc/configen de systeemlogboeken van de NAS. - Installeer Claude Code in een omgeving via Toolchains → de omgeving → AI-tools → Claude Code → Installeren. Kies in hetzelfde venster Aanmelden bij Claude en gebruik je eigen account.
- Een account met de rol developer of admin. Alleen een beheerder van de NAS installeert pakketten op de NAS.
02Sessie starten
Met elk van de onderstaande manieren start je dezelfde installatie van Claude Code in de omgeving. Start Claude Code in de projectmap, zodat het de skill van het project leest.
- In het paneel. Kies op het tabblad Claude Code van AI-tools het project bij Map en klik op Een nieuwe sessie starten. De sessie draait in de sandbox van de omgeving en blijft draaien als je de pagina sluit. Je vindt de sessie terug via Terminal.

- In de terminal van de editor. De link Of start het programma in de terminal van de editor onder de knop opent de sessie daar. De sessie stopt als je het tabblad van de editor sluit.
- Vanuit claude.ai/code of de Claude-app. Zodra je bent aangemeld, toont hetzelfde tabblad Remote Control met de tekst ‘Sessies van deze omgeving kunnen worden gestart en bestuurd vanuit claude.ai/code en de Claude-app.’ Schakel de optie in en kies daar deze omgeving.
- Vanaf je telefoon. Koppel de mobiele app van Bucket & Code via Telefoon-app in het paneel. Open in de app het tabblad AI. Kies de omgeving, de map en de AI-tool. Tik daarna op Een nieuw gesprek starten.
03Vraag om HelloPublic
Voer in de map van een nieuw project met de naam HelloPublic deze prompt letterlijk in.
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 zet de startfunctie in shared/HelloPublic.sh. De functie haalt het pad van Public op uit QTS en overschrijft het bestand. Ook na een tweede start bevat het één regel.
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"
}
}
In dit ingekorte antwoord meldt Claude Code dat het in deze sessie bestanden kan bewerken en hun syntaxis kan controleren, maar ze niet kan uitvoeren.
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.
…
04Vraag om CronEdit
De prompt somt de regels van QNAP voor cron één voor één op, zodat je elke regel later in de code kunt terugvinden.
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.
Het ingekorte antwoord.
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`.
05De crontab-regels in de code
CronEdit bewaart zijn regels in cronedit.tab in de pakketmap. Het programma bin/cronedit schrijft ze naar /etc/config/crontab. Dat bestand blijft na een herstart behouden. Het programma zet de tag aan het einde van elke regel die het schrijft. Het wijzigt alleen regels met die tag aan het einde.
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
Met één doorgang maakt awk het nieuwe bestand. Het laat alle regels zonder de tag op hun plaats. Van elke regel met de tag die het pakket nodig heeft, behoudt awk het eerste exemplaar. Het verwijdert de rest, ook regels die niet meer in cronedit.tab staan. Het voegt ontbrekende regels die het pakket nodig heeft onderaan het bestand toe.
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")
Als er geen regels bijkomen of wegvallen, blijft het bestand ongewijzigd en start cron niet opnieuw.
set -- $changes
DROPPED=${1:-0}
ADDED=${2:-0}
if [ "$DROPPED" = 0 ] && [ "$ADDED" = 0 ]; then
rm -f "$new"
return 0
fi
Voor het schrijven controleert awk in een tweede doorgang of alle regels zonder de tag nog ongewijzigd en in dezelfde volgorde in het nieuwe bestand staan. Als de controle mislukt, laat het programma het oorspronkelijke bestand ongemoeid. Na het schrijven herlaadt het programma cron volgens de regels van QNAP.
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
}
Het servicescript roept het programma aan. Met start werkt het de crontab bij. Met stop en remove (bij het verwijderen van het pakket) verwijdert het alle regels met de tag. Als het pakket in App Center uitstaat, verwijdert het deze regels ook bij een startpoging. Bij stroomuitval kan de stopactie namelijk uitblijven.
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
Zolang het pakket draait, wijzigen cronedit add en cronedit remove het bestand cronedit.tab en werken ze /etc/config/crontab meteen bij. Draait het pakket niet? Dan verwerkt CronEdit de wijziging in de crontab bij de volgende start.
06Controleer wat Claude Code heeft geschreven
Lees de diff. Voer daarna uit wat Claude Code in de sessie niet kan uitvoeren. Voor CronEdit is dat de eigen test met een nagebootste NAS-mapstructuur. Voer daarvoor sh build/t/run.sh uit. De test slaagt. Bij de controle passen we het volgende aan.
- We verwijderen
bin/CronEdituit het CronEdit-project. Het bestand komt uit het sjabloon. Niets voert het uit. De naam verschilt alleen in het gebruik van hoofdletters en kleine letters vanbin/cronedit. Op Windows of macOS overschrijft het ene bestand het andere. Claude Code merkt dit op. Voor het verwijderen is toestemming nodig. De twee regels hierover in de README beschrijven nubin/cronedit. - De code van HelloPublic blijft ongewijzigd.
- Installatie. Het antwoord noemt
qpkg_cli -m … --keepals installatiecommando. Op QTS 6.1 installeert dat commando geen pakket zonder handtekening.qpkg_cli -sgeeft ‘notfound’ terug. Stap 08 toont hoe je het pakket installeert.
07Bouw het pakket
Op de projectpagina voert Bouwen het commando bvs qbuild uit in de buildomgeving van het project. In de terminal gebruik je hetzelfde commando in de projectmap.
bvs qbuild ls build/ CronEdit_0.1.0_x86_64.qpkg CronEdit_0.1.0_x86_64.qpkg.md5
Zonder certificaat voor codeondertekening in het project is het pakket ongetekend en blijft Testuitrol uit met de melding ‘Heeft een ondertekend pakket nodig’. Met Testuitrol installeer je een ondertekend pakket. De handleiding voor App Center laat zien hoe je het ondertekent.
08Installeer en controleer het pakket
Wil je een pakket zonder handtekening op je eigen NAS testen? Kopieer het pakketbestand naar een gedeelde map. Voer het via SSH uit als admin. QTS installeert en start het pakket.
# via SSH als admin, in de gedeelde map met het bestand
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
- Een pakket dat je op deze manier installeert, krijgt geen regel
Statusin/etc/config/qpkg.conf. Als App Center het pakket installeert, schrijft hetStatus = complete. - Laat in App Center de instelling voor apps zonder geldige digitale handtekening uit. Onderteken deze pakketten.
- Verwijder een pakket in App Center of met
qpkg_cli -R CronEdit.
HelloPublic na het starten.
P=$(getcfg Public path -f /etc/config/smb.conf) cat "$P/hello.txt" Hello world
CronEdit nadat er tijdens het draaien twee regels zijn toegevoegd.
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
09Testresultaten
Vóór de installatie maken we op een NAS met QTS 6.1 een kopie van /etc/config/crontab (58 regels). Na elke stap vergelijken we het bestand met die kopie.
| Stap | /etc/config/crontab na de stap | Herstart van cron |
|---|---|---|
| installeren, nog geen regels | de opgeslagen kopie | nee |
tweemaal cronedit add terwijl CronEdit draait | twee extra regels met de tag | ja, na elke opdracht |
| stoppen | byte voor byte gelijk aan de opgeslagen kopie | ja |
| starten | de twee regels staan er weer | ja |
| nogmaals starten | ongewijzigd, geen dubbele regels | nee |
een regel uit cronedit.tab halen zonder voorafgaande stopactie, zoals na stroomuitval, en daarna starten | die regel verdwijnt, de andere blijft staan | ja |
cronedit add en daarna cronedit remove terwijl CronEdit draait | de regel verschijnt en verdwijnt weer | ja, na elke opdracht |
qpkg_cli -R CronEdit | byte voor byte gelijk aan de opgeslagen kopie. Ook crontab -l toont dezelfde regels. | ja |
- Na elke stap staan de overige 58 regels ongewijzigd en in dezelfde volgorde als in de opgeslagen kopie.
- In de test schrijft de regel
* * * * * /bin/date -u >> /share/Public/cronedit-demo.txtbinnen een minuut zijn eerste tijdstempel. Daarmee toont de test aan dat cron de regels met de tag uitvoert. - Eerst laadt
crontabhet bestand. Daarna verplaatstcrond.sh startvan QTS de eigen regels voorvs_refreshenbackup_conf.shnaar het einde van het bestand. Zolang de regels van CronEdit in het bestand staan, kancrontab -ldezelfde regels in een andere volgorde tonen dan waarin ze in het bestand staan. - Bij het starten schrijft HelloPublic in
hello.txtéén regel metHello world. Ook na een tweede start bevat het bestand één regel. Als je HelloPublic stopt of verwijdert, blijft het bestand in de gedeelde map Public staan.
10Download de bronbestanden
ai-qpkg-examples.zip (170 KB) bevat beide projecten na de controle, de twee prompts en een README-bestand. Dat bestand vermeldt wat Claude Code heeft geschreven en wat bij de controle is aangepast. Kopieer een project naar je projectenmap en bouw het met bvs qbuild.