Hash the Prompt Before You Cross the Wire
Remote help is not free if the hop is slow. A prompt that never leaves disk cannot leak. The cheap path is a local cache with a measured fill. Most coding assistants resend the same context twice. The second trip pays latency already spent. Hash the prompt and the file set first. Store the draft beside the repo. Cross the wire only on a miss. This is not a model-quality argument. It is a path…
Remote assistance carries a cost when the connection is slow. A prompt that remains on disk cannot leak information. The quickest route is a local cache with measured additions. Many coding assistants repeat the same context unnecessarily. The second trip incurs latency already spent. Before sending data, hash the prompt and the file set.
Save the draft alongside the repository. Only attempt to cross the wire on a miss. This approach focuses on latency, secrets, and offline time rather than model quality. A free remote server only proves effective after these three factors are verified. Teams often evaluate models in public threads but overlook the actual path those models travel.
A delayed connection may waste more time than a subpar draft. Leaked tokens can cause more damage than a mere delay. This article was crafted for MonkeyCode's product promotion. MonkeyCode provides free model access and a free server option, but these factors matter only once a local check confirms the connection is secure. Consider the working tree as the source of truth and the network as a secondary option.
The secondary option opens upon a cache miss and remains closed if secrets are detected, the probe is slow, or the machine is offline. The artifact serves as a content-addressed preflight check, linking the hash of the prompt text and a sorted file list to git rev-parse HEAD. If a secret pattern is encountered, the cache refuses to fill.
It performs a single round trip before any payload is transmitted. Label the subsequent numbers as a method, not a result. This draft does not claim a measurable speedup. Execute the script on your repository, record your own timings, and avoid relying on someone else's hop cost. Create a directory dedicated solely to drafts, ensuring it remains uncommitted to the repository.
Keep these drafts nearby the work, not within the Git system. A cache functions as a notebook, not as the ultimate source of truth. Create a .prompt-cache directory using the command `mkdir -p .prompt-cache`, add a line to exclude it from the Git repository with `echo .prompt-cache/ >> .git/info/exclude`, and confirm the Git version with `git rev-parse HEAD`.
The exclude line prevents drafts from being included in remote storage, and the HEAD binding ensures drafts remain honest. A hash without HEAD would inadvertently replicate a draft onto the incorrect tree, resulting in a stale cache. Below is a concise hasher script that can be executed locally. It reads the prompt from standard input, accepts additional context through file paths, and outputs a ledger line that subsequent steps can interpret.
The script is not intended for shipping secrets. The `preflight_hash.py` Python script performs the following tasks:
1. Import necessary libraries: hashlib, json, os, sys, and time. Import the Path class from the pathlib module.
2. Define a constant `SECRET_MARKERS` containing patterns indicating sensitive information such as private keys, AWS access keys, API tokens, and GitHub personal access tokens.
3. Implement a `sha` function that computes the SHA-256 hash of the provided data.
4. Implement a `scan` function that searches for any occurrences of the secret markers within the given text.
5. Implement a `read_files` function that reads the contents of the provided file paths in sorted order and concatenates them along with a separator.
6. In the `main` function:
a. Read the prompt from standard input.
b. Retrieve the list of file paths provided as command-line arguments.
c. Obtain the current Git commit hash using `git rev-parse HEAD`.
d. Encode the prompt and file contents, then compute the hash using the `sha` function.
e. Scan the prompt and file contents for any secret markers.
f. Create a dictionary `record` containing the Git commit hash, computed hash, payload size, number of files, list of secret hits, and timestamp.
g. Write the `record` dictionary to a file named `ledger.jsonl` within the `.prompt-cache` directory.
h. Print the `record` dictionary in JSON format.
i. If any secret markers were found, exit with a status code of 2, indicating a forbidden hop. The ledger still records the attempt, providing an audit trail. Running the hasher script followed by a cache lookup allows for a decision on whether to proceed with the remote connection based on the presence of secrets, network speed, and local availability of the required resources.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.