Skip to main content

suken-sync

Đồng bộ hai chiều một thư mục từ máy Linux (qua SSH) về máy này (macOS hoặc Linux), để agent như Claude Code đọc và sửa code ngay trên máy này còn việc chạy (build, test, docker, server) vẫn ở máy Linux.

  • File nặng không đồng bộ. File từ ngưỡng (mặc định 10 MB) trở lên (weight model, .pdb, .so...) ở lại Linux; trên máy này chỉ có file bóng <tên file>.linux-only.txt ghi cỡ và vị trí thật, để agent biết file có tồn tại mà không tải về hay build lại.
  • Chạy nền, tự nối lại sau khi mở máy, mất mạng hay mất VPN.
  • Hook SessionStart của Claude Code dặn agent: máy này chỉ đọc và sửa, mọi lệnh chạy qua ssh sang Linux. Không đụng CLAUDE.md.

Dùng thế nào

pip install suken-sync
suken-sync setup     # bắt buộc chạy trước: cài Unison, hook; in hướng dẫn cho agent
suken-sync add --host linux-box --remote /home/dev/my_project --local /Users/me/Downloads_linux-box/my_project

Ngay sau pip install, mọi lệnh (trừ setup, usage) và cả --help chỉ nhắc chạy setup. setup chạy xong thì in hướng dẫn dùng add, và từ đó mỗi phiên Claude Code mở trong thư mục đã cài hook đều tự nhận hướng dẫn qua hook.

add bắt buộc đủ 3 tham số --host, --remote, --local (cũng viết --remote-Mac); thiếu hoặc sai một tham số thì lệnh bị chặn ngay, liệt kê từng lỗi kèm ví dụ đủ tham số. Đổi máy: tạo venv mới, pip install, setup, rồi chạy lại đúng lệnh add.

Các lệnh

Lệnh Làm gì
suken-sync setup [--dir DIR] [--remove] tải Unison 2.54.0 (ghim, kiểm sha256; macOS thêm unison-fsmonitor 0.3.9) vào cache; cài hook SessionStart vào DIR/.claude/settings.local.json (mặc định thư mục hiện tại, giữ nguyên hook khác); kiểm ssh, scp, dịch vụ nền; thiếu gì thì liệt kê và thoát mã lỗi, đủ thì in hướng dẫn. --remove gỡ hook
suken-sync add --host H --remote R --local L [--threshold 10MB] [--name N] [--ignore PATTERN] thêm một thư mục: nối ssh, cài Unison riêng lên Linux (~/.cache/suken-sync), quét file nặng, đồng bộ lần đầu, tạo file bóng, cài dịch vụ nền và hook vào L/.claude/settings.local.json, kiểm cuối (✅ Sync xong hoặc liệt kê chỗ thiếu và thoát mã lỗi). --ignore là mẫu Unison (vd "Name node_modules"), lặp lại được
suken-sync list liệt kê các phiên
suken-sync status [tên] dịch vụ còn chạy, nối được Linux, hook còn; thoát mã 1 nếu có vấn đề
suken-sync refresh [tên] quét file nặng ngay, nạp lại danh sách bỏ qua và file bóng, khởi động lại dịch vụ (thường không cần: dịch vụ tự quét mỗi 5 giây)
suken-sync remove <tên> tháo phiên: dịch vụ, hook, file bóng, trạng thái Unison ở cả hai máy; không xoá code ở cả hai máy
suken-sync usage in hướng dẫn cho agent

Cách hoạt động

  1. Mỗi phiên là một dịch vụ nền (macOS: launchd, KeepAlive; Linux: systemd user, Restart=always, chờ 15 giây giữa các lần dựng lại) chạy một bộ giám sát python -m suken_sync.watch.
  2. Bộ giám sát giữ một kết nối ssh chạy find mỗi 5 giây trên Linux để tìm file từ ngưỡng trở lên. Có file nặng mới thì nó tạo file bóng, ghi đường dẫn đó vào danh sách bỏ qua (ignore = Path ...) của Unison và khởi động lại Unison trong vài giây.
  3. Unison chạy -repeat watch (đồng bộ ngay khi có thay đổi) cùng maxsizethreshold: file nặng mới thêm vào thư mục có sẵn bị chặn ngay, không chờ bộ giám sát. Riêng file nặng nằm trong thư mục hoàn toàn mới thì Unison chép cả thư mục như một khối và bỏ qua ngưỡng (recon.ml), nên lớp quét ở bước 2 là lớp chặn chính cho trường hợp này.
  4. Độ trễ khi sửa file: khoảng 0,6 giây (Linux sang máy này) đến 1,2 giây (máy này sang Linux), đo trên mạng công ty qua VPN.

An toàn

  • Không bao giờ dùng prefer hay force của Unison; xung đột (cùng một file sửa cả hai bên) được bỏ qua và ghi vào log, không bên nào bị ghi đè.
  • Unison giữ nguyên lớp bảo vệ confirmbigdel: nếu một bên bỗng mất hàng loạt file (thư mục bị xoá, ổ chưa gắn) thì dừng thay vì xoá bên kia.
  • File bóng và .claude/settings.local.json không bao giờ đồng bộ. Gói chỉ xoá file bóng có dòng đầu bắt đầu bằng [BÓNG].
  • Mỗi phiên có trạng thái Unison riêng ở cả hai máy (remove xoá sạch), nên add lại vào thư mục trống không bị nhầm là "vừa xoá hết".
  • Log: <thư mục cấu hình>/logs/<tên>.log và .out (macOS: ~/Library/Application Support/suken-sync, Linux: ~/.config/suken-sync).

Yêu cầu

  • Máy này: macOS (Apple Silicon hoặc Intel) hoặc Linux x86_64, Python 3.9 trở lên, ssh và scp. Linux cần systemd user session; muốn chạy khi chưa đăng nhập thì bật loginctl enable-linger.
  • Máy Linux ở xa: x86_64, vào được bằng ssh <host> bằng key, không hỏi mật khẩu (bật VPN trước nếu cần).
  • Windows không hỗ trợ.

Biến môi trường (dùng khi tự cài hoặc thử)

Biến Tác dụng
SUKEN_SYNC_UNISON_DIR thư mục chứa file unison (và unison-fsmonitor) tự cài, bỏ qua bước tải
SUKEN_SYNC_REMOTE_UNISON_DIR thư mục chứa bản Unison Linux để chép lên máy ở xa
SUKEN_SYNC_HOME dời toàn bộ cấu hình, cache, file dịch vụ vào một thư mục (để thử, không đụng cấu hình thật)

Phần mềm bên thứ ba: xem THIRD_PARTY_NOTICES.md.

Metadata

Release files for suken-sync 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for suken-sync 0.1.0
File Size Uploaded Provenance Actions
suken_sync-0.1.0.tar.gz 33.2 kB Without provenance Details for suken_sync-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for suken-sync 0.1.0
File Interpreter ABI Platform Actions
suken_sync-0.1.0-py3-none-any.whl Python 3 none any Details for suken_sync-0.1.0-py3-none-any.whl

Total release size: 58.4 kB

Release files / suken_sync-0.1.0.tar.gz

Download URL suken_sync-0.1.0.tar.gz
Size 33.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e492fd0bf547d425ec2641ac070721872538313b82a80a52ea97763a5d1c5bd0
BLAKE2b-256 checksum
How to use checksums
b05c970245210fb76e96b0c45df98a9dc70f943282506688a9b4d0278f349f3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / suken_sync-0.1.0-py3-none-any.whl

Download URL suken_sync-0.1.0-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
012a57a18dadba1ec353f6ec38000aaf7a3c4b7e9204f7545c2d9dbbdfcc25ca
BLAKE2b-256 checksum
How to use checksums
013ead9eae81d955834160902bfaa014b605025f1b0a72572a6a9daf28fe540b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for suken-sync 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page