A Practical Guide to Terminal AI Coding Assistants: Modes, Sessions, and Costs
Terminal AI coding assistants can read files, execute commands, and modify code directly within a repository while maintaining session history. Using Claude Code as an example, this guide covers essential operations including interaction modes, session lifecycle management, cost optimization, and team collaboration best practices.
Terminal AI coding assistants can read files, run commands, and modify code within a code repository while remembering the current session history. This article uses Claude Code as an example to explain common operations. Note that slash commands and shortcuts may vary by product and version; always run /help locally to confirm before proceeding.
1. Interaction and Basic Operations
Terminal AI coding assistants are entirely keyboard-driven. They can perceive the current workspace’s file structure, code changes, and conversation history, so there is no need to paste large blocks of background context when asking questions. To get started, you need to understand two things. First, after submitting a prompt, the model may take tens of seconds to reason, during which it generates code, calls tools, or modifies files. Second, the current mode determines whether it can directly modify your files.
1.1 Submitting and Interrupting
Enter is used to submit a prompt. After the model starts generating, if you notice it is heading in the wrong direction (e.g., writing an API call that does not exist in the project), you should immediately press Esc to interrupt the generation. Interrupting promptly prevents unnecessary token consumption and waiting time.
In some versions, pressing Esc twice opens a backtrack menu, allowing you to return to a specific historical point or a state before a code change. Whether this shortcut exists depends on the product version; refer to /help.
1.2 Switching Modes
Shift+Tab cycles through three modes:
- Normal Mode: Requires confirmation before every file modification or command execution. Suitable for production environments and unfamiliar codebases.
- Auto-Accept Mode: No longer requires per-item confirmation for file modifications. Suitable for large, mechanical changes like style unification or template generation. Before using this, execute
git commitorgit stash, and only use it in version-controlled directories that do not contain production keys. When first entering an unfamiliar repository, validate the results with small-scope tasks. - Plan Mode: Only outputs the modification plan and steps without altering files. Suitable for architecture design and code review, reducing trial and error before taking action.
Boundaries to note: Taking Claude Code’s current version as an example, Auto-Accept typically only auto-accepts file edits; whether command execution still requires confirmation depends on the version and permission settings. Do not assume it will auto-approve all operations. Verify using /help or the product documentation.
To reduce the risk of incorrect modifications, it is recommended to create a temporary branch in Auto-Accept mode. After modifications are complete, test locally or wait for CI to pass before merging back into the main branch. Immediately switch back to Normal mode using Shift+Tab after the task is finished.
For daily development, use Normal mode by default. Before developing complex features, use Plan mode to generate a design draft, then switch back to Normal mode for execution once confirmed.
2. Session Lifecycle Management
2.1 Initializing a Project: /init
Upon entering a new project, the AI can only see the bare code. After executing /init, the tool scans the directory structure, dependency files (e.g., package.json, requirements.txt), and code style to generate a project memory file. Taking Claude Code’s common naming convention as an example, this file is named CLAUDE.md (other products may use different names). The file content typically includes:
- Tech stack and architectural specifications;
- Code style conventions, such as indentation and naming rules;
- Build, test, and deployment commands.
The generated file does not need to be finalized at once. As the project evolves, you can use /memory to add key decisions, keeping the memory file consistent with the actual project state.
2.2 Compacting Context: /compact
The model’s context window is limited. After working continuously for several hours, the conversation will accumulate a large number of code snippets, error logs, and modification records. At this point, responses may slow down, and early discussions may be forgotten.
Executing /compact along with an optional hint compresses the history into a summary. The hint specifies information that must be retained, for example:
/compact Keep the OrderService factory pattern refactoring requirements, confirmed interface signatures, and test commands
The hint should be written in one or two sentences, containing only the requirements, constraints, and key commands. If it is too long, the compression effect will be diminished, and it will occupy the already limited context.
After compression is complete, ask the model to reiterate the current goals and to-do items. Check them against the original requirements item by item to ensure nothing is missing. Then run the relevant tests to confirm the modifications still work. You can check using the following list:
- Whether the summary retains the content specified in the hint;
- Whether key file paths and run commands are still present;
- If the summary lost important decisions, whether you need to roll back to the pre-compaction state or provide additional clarification.
After compression, token usage usually drops significantly, and core requirements are generally retained. However, since the summary is generated by the model, details may still be missed, so the verification step cannot be skipped.
3. Cost Monitoring and Model Selection
The cost of a long session comes from two parts: the input context of each round, and the output generated by the model. Cost monitoring requires understanding where the money is being spent.
Check Spending: You can use /cost or /status to view the token usage and cost of the current session; refer to /help for the exact command. Checking after completing each milestone task can help detect abnormal growth in a timely manner.
Select Models by Task: /model allows you to switch models. The principle is to use lightweight models for simple tasks and stronger models for complex architectural design and cross-module troubleshooting. For example, batch rewriting comments or generating boilerplate code can use a lightweight model; designing a data migration plan or troubleshooting concurrency issues warrants a stronger model.
Split Long Tasks: Break a large requirement into several small tasks. After each task, execute /compact once or start a new session. This keeps the context short for each round, making both cost and response time more controllable.
Avoid Invalid Retries: When the model gives an incorrect direction, press Esc to interrupt first, then explain the error reason in a sentence or two. Do not simply resubmit the same prompt. Repeated retries will cause the same background context to be billed repeatedly without providing new information.
4. Team Collaboration: Permissions and Troubleshooting
When a team shares the same repository, permission configurations need to be managed uniformly.
Project-level Configuration: Taking Claude Code as an example, project permissions are usually written in the repository’s .claude/settings.json, while local personal overrides can be placed in .claude/settings.local.json, which is generally not committed to the version control system. Specific paths and fields are subject to the current version’s documentation.
Key and Directory Isolation: Production keys should only be placed in environment variables or key management services, never written into code or configuration files. For directories containing sensitive data, read or write access should be prohibited via permission rules. Directories involving production configurations can be set to read-only to prevent AI from making accidental changes.
Troubleshooting Denied Permissions: Follow these three steps:
- Use
/helpto confirm the permission-related commands and prompts supported by the current product version; - Check the allow and deny rules in project and personal settings files to confirm if a rule is overriding the current operation;
- Retry with minimal privileges: only open the single necessary item required to complete the current task, rather than opening the entire directory or all commands.
This approach solves the problem without expanding risk and facilitates post-auditing.
5. Common Mistakes Checklist
- Not compacting long sessions, resulting in slow responses and forgotten early requirements.
- Not switching back to Normal after Auto-Accept, leading to subsequent changes occurring without confirmation.
- Not updating the memory file with the project after executing
/init, causing the AI to continue working with outdated architecture and commands. - Writing production keys into the repository or memory file, leading to key leaks via the version control system.
- Not interrupting the model when it goes in the wrong direction, continuously consuming tokens.
Mastering these operations will make the terminal AI coding assistant a controllable tool. You decide when to delegate, know where the money goes, and understand how to recover when errors occur.
