This file gives concise, actionable guidance for AI coding agents that need to work on this repository.
- Big picture
- Primary purpose: a collection of command-line utilities and small web/docs for interacting with LLMs.
- Key runtime pieces:
bin/chatgpt— the main Node.js CLI that implements a very feature-rich front-end to OpenAI-compatible chat APIs.- many small helper scripts in
bin/that callchatgptor provide tooling (chatgptapplytemplate,chatgptpromptlib,chatgptdictate, ...). templates/holds prompt templates used bychatgptapplytemplateand others.docs/andpublic/contain web-facing pages and bookmarklets.docs/contains an index and several small web applications / bookmarklets (seedocs/index.html). Examples:docs/ChatGPTBookmarklet/(installable ChatGPT bookmarklet),docs/grabStyles/(Grab Styles bookmarklet),docs/dictation/(Dictation mini-app), anddocs/bookmarkletmaker/(bookmarklet generator).
- Important files and directories (quick reference)
bin/chatgpt— entry point for most functionality; Node.js script (~1.2k lines). Read it to understand options parsing, conversation handling, tools integration, and request formatting.bin/_makeusagetxt— used to regenerate_usages.txtby calling each script's--help.templates/— template files such as*.template.txtand*.jsonused by template appliers.test/chatgpt— integration tests using Bats. Seetest/chatgpt/README.mdand the it_test script.CLAUDE.mdandREADME.md— project-level developer guidance (build/test commands, style rules, conventions).docs/index.html— index page describing experiments and providing drag-install bookmarklet links; edit it when adding or changing bookmarklets or web mini-apps. Bookmarklets are typically added as an anchor with a generatedjavascript:URL (seegrabstylesanchor construction indocs/index.html).
- How the code is structured and why
- Scripts are the primary surface. Conventions: executable scripts live in
bin/. Files beginning with_are helpers or metadata (e.g._makeusagetxt,_usages.txt). - Conversation state is file-based and stored in
$HOME/.chatgpt.js/conversations. Profiles live in$HOME/.chatgpt.js/profiles. - Tools integration:
chatgptaccepts a tools config (-tf) or a tools script (-ts). Tools config is an array of tool descriptors (JSON) with keys likefunction,commandline,stdinand an optionalcfgfilelocation. - The repository intentionally keeps CLI scripts small, shell-first and readable; many scripts call each other via exec.
- Developer workflows and commands (concrete)
- Build (generate usages, docs, templates):
make all(seeCLAUDE.md/Makefile).
- Run integration tests (requires valid API credentials; tests use real API calls):
cd test/chatgpt && ./it_test.bats- To run a subset:
CHATGPT_TEST_ARGS="-op profile_name" ./it_test.bats
- Run an example CLI call:
bin/chatgpt -p 'Summarize:' -f README.md— reads README.md and submits it.
- Regenerate usages file for bin scripts:
bin/_makeusagetxtwill call each executable inbin/with--helpand collect output into_usages.txt.
- Project-specific conventions agents must follow
- Absolute paths: many scripts expect absolute paths or resolve
~and relative files to CWD withresolveFile()—preserve that behavior when editing. - IDs in HTML use the
hps-chatgpt-prefix. Search for that when modifying docs/layout. - Error handling: scripts print descriptive errors to stderr and use non-zero exit codes (common pattern: exit(1) or exit(2)). Keep consistent messages.
- Prompt library:
chatgptpromptlibis used for reusable prompt fragments. When you seepromptlib:keyin a prompt, the CLI will callchatgptpromptlib keyand replace the token with its output. - Tools scripts: if implementing a tool script referenced via
-ts, it must support--openaitoolsconfigand output a tools JSON config. The config must follow the format[{"function":{...}, "commandline":[...], "stdin":...}, ...].
- Environment and configuration variables
OPENAI_API_KEYor file at$HOME/.openai-api-key.txt— API key fallback.OPENAI_API_BASE— base URL for API;chatgptappends/chat/completionswhen not overridden.OPENAI_API_DEFAULTMODEL,OPENAI_API_HIGHMODEL,OPENAI_API_THINKINGMODEL— model defaults and special model aliases.- $HOME is used for profile and conversation storage:
$HOME/.chatgpt.js/profilesand$HOME/.chatgpt.js/conversations.
- Tests and CI notes
- Tests use Bats + bats-assert and assume access to a working LLM endpoint. Running tests may incur cost.
- Tests can be invoked manually; CI should provide API credentials or mock/stub the HTTP calls.
- Examples agents should use when making changes
- Add new tool: create
tools/yourtool.jsondescribing the tool, or writebin/yourtoolthat supports--openaitoolsconfigand returns the tool config. Then callchatgpt -tf tools/yourtool.jsonorchatgpt -ts bin/yourtool. - Add a prompt template: put
your.template.txtintemplates/and callbin/chatgptapplytemplate template_name file. - Add help text: ensure
--helpoutput exists and is collected by_makeusagetxt.
- Where to look first when investigating a change
bin/chatgptto understand CLI contract and how options are parsed and resolved.bin/_makeusagetxtand_usages.txtfor how command help text is maintained.templates/for prompt patterns and examples.test/chatgptandtest/chatgpt/README.mdfor integration expectations.CLAUDE.mdfor developer guidance and conventions.
- Safety and non-goals
- The repo intentionally calls the real LLM APIs in many places. Do not add tests that make uncontrolled API calls without flagging costs.
- Don't change global behaviors (path resolution, profile storage) without updating related docs and tests.
If anything in this file is unclear, read bin/chatgpt first — it contains the canonical behavior and examples.